@capgo/capacitor-updater 4.0.0-alpha.7 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,9 +9,10 @@ import Version
9
9
  @objc(CapacitorUpdaterPlugin)
10
10
  public class CapacitorUpdaterPlugin: CAPPlugin {
11
11
  private var implementation = CapacitorUpdater()
12
- static let updateUrlDefault = "https://xvwzpoazmxkqosrdewyv.functions.supabase.co/updates"
13
- static let statsUrlDefault = "https://xvwzpoazmxkqosrdewyv.functions.supabase.co/stats"
14
- static let DELAY_UPDATE = "delayUpdate"
12
+ static let updateUrlDefault = "https://api.capgo.app/updates"
13
+ static let statsUrlDefault = "https://api.capgo.app/stats"
14
+ let DELAY_UPDATE = "delayUpdate"
15
+ let DELAY_UPDATE_VAL = "delayUpdateVal"
15
16
  private var updateUrl = ""
16
17
  private var statsUrl = ""
17
18
  private var currentVersionNative: Version = "0.0.0"
@@ -23,17 +24,18 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
23
24
  private var autoDeletePrevious = false
24
25
 
25
26
  override public func load() {
27
+ print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
26
28
  do {
27
- currentVersionNative = try Version(Bundle.main.buildVersionNumber ?? "0.0.0")
29
+ currentVersionNative = try Version(Bundle.main.versionName ?? "0.0.0")
28
30
  } catch {
29
31
  print("\(self.implementation.TAG) Cannot get version native \(currentVersionNative)")
30
32
  }
31
- autoDeleteFailed = getConfigValue("autoDeleteFailed") as? Bool ?? false
32
- autoDeletePrevious = getConfigValue("autoDeletePrevious") as? Bool ?? false
33
- updateUrl = getConfigValue("updateUrl") as? String ?? CapacitorUpdaterPlugin.updateUrlDefault
34
- autoUpdate = getConfigValue("autoUpdate") as? Bool ?? false
35
- appReadyTimeout = getConfigValue("appReadyTimeout") as? Int ?? 10000
36
- resetWhenUpdate = getConfigValue("resetWhenUpdate") as? Bool ?? true
33
+ autoDeleteFailed = getConfig().getBoolean("autoDeleteFailed", true)
34
+ autoDeletePrevious = getConfig().getBoolean("autoDeletePrevious", true)
35
+ updateUrl = getConfig().getString("updateUrl") ?? CapacitorUpdaterPlugin.updateUrlDefault
36
+ autoUpdate = getConfig().getBoolean("autoUpdate", false)
37
+ appReadyTimeout = getConfig().getInt("appReadyTimeout", 10000)
38
+ resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", true)
37
39
 
38
40
  implementation.appId = Bundle.main.bundleIdentifier ?? ""
39
41
  implementation.notifyDownload = notifyDownload
@@ -41,14 +43,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
41
43
  if (config?["appId"] != nil) {
42
44
  implementation.appId = config?["appId"] as! String
43
45
  }
44
- implementation.statsUrl = getConfigValue("statsUrl") as? String ?? CapacitorUpdaterPlugin.statsUrlDefault
45
-
46
+ implementation.statsUrl = getConfig().getString("statsUrl") ?? CapacitorUpdaterPlugin.updateUrlDefault
46
47
  if (resetWhenUpdate) {
47
48
  self.cleanupObsoleteVersions()
48
49
  }
49
50
  let nc = NotificationCenter.default
50
51
  nc.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
51
52
  nc.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
53
+ self._checkCancelDelay(killed: true)
52
54
  self.appMovedToForeground()
53
55
  }
54
56
 
@@ -60,9 +62,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
60
62
  print("\(self.implementation.TAG) Cannot get version native \(currentVersionNative)")
61
63
  }
62
64
  if (LatestVersionNative != "0.0.0" && currentVersionNative.major > LatestVersionNative.major) {
63
- _ = self._reset(toAutoUpdate: false)
64
- UserDefaults.standard.set("", forKey: "LatestVersionAutoUpdate")
65
- UserDefaults.standard.set("", forKey: "LatestVersionNameAutoUpdate")
65
+ _ = self._reset(toLastSuccessful: false)
66
66
  let res = implementation.list()
67
67
  res.forEach { version in
68
68
  print("\(self.implementation.TAG) Deleting obsolete bundle: \(version)")
@@ -81,8 +81,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
81
81
  }
82
82
  }
83
83
 
84
- @objc func getId(_ call: CAPPluginCall) {
85
- call.resolve(["id": implementation.deviceID])
84
+ @objc func getDeviceId(_ call: CAPPluginCall) {
85
+ call.resolve(["deviceId": implementation.deviceID])
86
86
  }
87
87
 
88
88
  @objc func getPluginVersion(_ call: CAPPluginCall) {
@@ -106,6 +106,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
106
106
  let res = try implementation.download(url: url!, version: version)
107
107
  call.resolve(res.toJSON())
108
108
  } catch {
109
+ print("\(self.implementation.TAG) download failed \(error.localizedDescription)")
110
+ self.notifyListeners("downloadFailed", data: ["version": version])
109
111
  call.reject("download failed", error.localizedDescription)
110
112
  }
111
113
  }
@@ -127,8 +129,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
127
129
  if (self._reload()) {
128
130
  call.resolve()
129
131
  } else {
130
- call.reject("Reload failed")
131
132
  print("\(self.implementation.TAG) Reload failed")
133
+ call.reject("Reload failed")
132
134
  }
133
135
  }
134
136
 
@@ -138,9 +140,9 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
138
140
  call.reject("Next called without id")
139
141
  return
140
142
  }
141
-
142
143
  print("\(self.implementation.TAG) Setting next active id \(id)")
143
- if (!self.implementation.setNextVersion(next: id)) {
144
+ if (!self.implementation.setNextBundle(next: id)) {
145
+ print("\(self.implementation.TAG) Set next version failed. id \(id) does not exist.")
144
146
  call.reject("Set next version failed. id \(id) does not exist.")
145
147
  } else {
146
148
  call.resolve(self.implementation.getBundleInfo(id: id).toJSON())
@@ -173,6 +175,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
173
175
  if (res) {
174
176
  call.resolve()
175
177
  } else {
178
+ print("\(self.implementation.TAG) Delete failed, id \(id) doesn't exist")
176
179
  call.reject("Delete failed, id \(id) doesn't exist")
177
180
  }
178
181
  }
@@ -189,18 +192,18 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
189
192
  }
190
193
 
191
194
  @objc func getLatest(_ call: CAPPluginCall) {
192
- let res = self.implementation.getLatest(url: url)
193
- call.resolve(res)
195
+ let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!)
196
+ call.resolve(res.toDict())
194
197
  }
195
198
 
196
199
  @objc func _reset(toLastSuccessful: Bool) -> Bool {
197
200
  guard let bridge = self.bridge else { return false }
198
201
 
199
202
  if let vc = bridge.viewController as? CAPBridgeViewController {
200
- let fallback: BundleInfo = self.implementation.getFallbackVersion()
203
+ let fallback: BundleInfo = self.implementation.getFallbackBundle()
201
204
  if (toLastSuccessful && !fallback.isBuiltin()) {
202
205
  print("\(self.implementation.TAG) Resetting to: \(fallback.toString())")
203
- return self.implementation.set(fallback) && self._reload()
206
+ return self.implementation.set(bundle: fallback) && self._reload()
204
207
  }
205
208
  self.implementation.reset()
206
209
  vc.setServerBasePath(path: "")
@@ -215,10 +218,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
215
218
  }
216
219
 
217
220
  @objc func reset(_ call: CAPPluginCall) {
218
- let toAutoUpdate = call.getBool("toLastSuccessful") ?? false
221
+ let toLastSuccessful = call.getBool("toLastSuccessful") ?? false
219
222
  if (self._reset(toLastSuccessful: toLastSuccessful)) {
220
223
  return call.resolve()
221
224
  }
225
+ print("\(self.implementation.TAG) Reset failed")
222
226
  call.reject("\(self.implementation.TAG) Reset failed")
223
227
  }
224
228
 
@@ -226,27 +230,79 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
226
230
  let bundle: BundleInfo = self.implementation.getCurrentBundle()
227
231
  call.resolve([
228
232
  "bundle": bundle.toJSON(),
229
- "native": self.currentVersionNative
233
+ "native": self.currentVersionNative.description
230
234
  ])
231
235
  }
232
236
 
233
237
  @objc func notifyAppReady(_ call: CAPPluginCall) {
234
- print("\(self.implementation.TAG) Current bundle loaded successfully. ['notifyAppReady()' was called]")
235
238
  let version = self.implementation.getCurrentBundle()
236
- self.implementation.commit(bundle: version)
239
+ self.implementation.setSuccess(bundle: version, autoDeletePrevious: self.autoDeletePrevious)
240
+ print("\(self.implementation.TAG) Current bundle loaded successfully. ['notifyAppReady()' was called] \(version.toString())")
237
241
  call.resolve()
238
242
  }
239
243
 
240
244
  @objc func setDelay(_ call: CAPPluginCall) {
241
- guard let delay = call.getBool("delay") else {
242
- print("\(self.implementation.TAG) setDelay called without delay")
243
- call.reject("setDelay called without delay")
245
+ guard let kind = call.getString("kind") else {
246
+ print("\(self.implementation.TAG) setDelay called without kind")
247
+ call.reject("setDelay called without kind")
244
248
  return
245
249
  }
246
- UserDefaults.standard.set(delay, forKey: "delayUpdate")
250
+ let val = call.getString("value") ?? ""
251
+ UserDefaults.standard.set(kind, forKey: DELAY_UPDATE)
252
+ UserDefaults.standard.set(val, forKey: DELAY_UPDATE_VAL)
253
+ UserDefaults.standard.synchronize()
254
+ print("\(self.implementation.TAG) Delay update saved.", kind, val)
247
255
  call.resolve()
248
256
  }
249
-
257
+
258
+ private func _cancelDelay(source: String) -> Void {
259
+ print("\(self.implementation.TAG) delay Canceled from \(source)")
260
+ UserDefaults.standard.removeObject(forKey: DELAY_UPDATE)
261
+ UserDefaults.standard.removeObject(forKey: DELAY_UPDATE_VAL)
262
+ UserDefaults.standard.synchronize()
263
+ }
264
+
265
+ @objc func cancelDelay(_ call: CAPPluginCall) {
266
+ self._cancelDelay(source: "JS")
267
+ call.resolve()
268
+ }
269
+
270
+ private func _checkCancelDelay(killed: Bool) -> Void {
271
+ let delayUpdate = UserDefaults.standard.string(forKey: DELAY_UPDATE)
272
+ if (delayUpdate != nil) {
273
+ if (delayUpdate == "background" && !killed) {
274
+ self._cancelDelay(source: "background check")
275
+ } else if (delayUpdate == "kill" && killed) {
276
+ self._cancelDelay(source: "kill check")
277
+ }
278
+ guard let delayVal = UserDefaults.standard.string(forKey: DELAY_UPDATE_VAL) else {
279
+ self._cancelDelay(source: "delayVal absent")
280
+ return
281
+ }
282
+ if (delayUpdate == "date") {
283
+ let dateFormatter = ISO8601DateFormatter()
284
+ guard let ExpireDate = dateFormatter.date(from: delayVal) else {
285
+ self._cancelDelay(source: "date parsing issue")
286
+ return
287
+ }
288
+ if (ExpireDate < Date()) {
289
+ self._cancelDelay(source: "date expired")
290
+ }
291
+ } else if (delayUpdate == "nativeVersion") {
292
+ do {
293
+ let versionLimit = try Version(delayVal)
294
+ if (self.currentVersionNative >= versionLimit) {
295
+ self._cancelDelay(source: "nativeVersion above limit")
296
+ }
297
+ } catch {
298
+ self._cancelDelay(source: "nativeVersion parsing issue")
299
+ }
300
+ }
301
+ }
302
+
303
+ self.checkAppReady()
304
+ }
305
+
250
306
  private func _isAutoUpdateEnabled() -> Bool {
251
307
  return self.autoUpdate && self.updateUrl != ""
252
308
  }
@@ -266,7 +322,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
266
322
  DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(self.appReadyTimeout), execute: self.appReadyCheck!)
267
323
  }
268
324
 
269
- func DeferredNotifyAppReadyCheck() {
325
+ func checkRevert() {
270
326
  // Automatically roll back to fallback version if notifyAppReady has not been called yet
271
327
  let current: BundleInfo = self.implementation.getCurrentBundle()
272
328
  if(current.isBuiltin()) {
@@ -274,16 +330,33 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
274
330
  return
275
331
  }
276
332
 
333
+ print("\(self.implementation.TAG) Current bundle is: \(current.toString())")
334
+
277
335
  if(BundleStatus.SUCCESS.localizedString != current.getStatus()) {
278
336
  print("\(self.implementation.TAG) notifyAppReady was not called, roll back current bundle: \(current.toString())")
279
- self.implementation.rollback(bundle: current)
280
- let res = self._reset(toAutoUpdate: true)
281
- if (!res) {
282
- return
337
+ print("\(self.implementation.TAG) Did you forget to call 'notifyAppReady()' in your Capacitor App code?")
338
+ self.notifyListeners("updateFailed", data: [
339
+ "bundle": current.toJSON()
340
+ ])
341
+ self.implementation.sendStats(action: "update_fail", versionName: current.getVersionName())
342
+ self.implementation.setError(bundle: current)
343
+ _ = self._reset(toLastSuccessful: true)
344
+ if (self.autoDeleteFailed && !current.isBuiltin()) {
345
+ print("\(self.implementation.TAG) Deleting failing bundle: \(current.toString())")
346
+ let res = self.implementation.delete(id: current.getId(), removeInfo: false)
347
+ if (!res) {
348
+ print("\(self.implementation.TAG) Delete version deleted: \(current.toString())")
349
+ } else {
350
+ print("\(self.implementation.TAG) Failed to delete failed bundle: \(current.toString())")
351
+ }
283
352
  }
284
353
  } else {
285
354
  print("\(self.implementation.TAG) notifyAppReady was called. This is fine: \(current.toString())")
286
355
  }
356
+ }
357
+
358
+ func DeferredNotifyAppReadyCheck() {
359
+ self.checkRevert()
287
360
  self.appReadyCheck = nil
288
361
  }
289
362
 
@@ -293,44 +366,51 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
293
366
  print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
294
367
  let url = URL(string: self.updateUrl)!
295
368
  let res = self.implementation.getLatest(url: url)
296
- if (res == nil) {
297
- print("\(self.implementation.TAG) No result found in \(self.updateUrl)")
298
- return
299
- }
300
- if (res?.message) {
301
- print("\(self.implementation.TAG) message \(res.message)")
302
- if (res?.major == true) {
303
- self.notifyListeners("majorAvailable", data: ["version": res?.version ?? "0.0.0"])
369
+ let current = self.implementation.getCurrentBundle()
370
+
371
+ if ((res.message) != nil) {
372
+ print("\(self.implementation.TAG) message \(res.message ?? "")")
373
+ if (res.major == true) {
374
+ self.notifyListeners("majorAvailable", data: ["version": res.version])
304
375
  }
376
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
305
377
  return
306
378
  }
307
- guard let downloadUrl = URL(string: res?.url ?? "") else {
379
+ guard let downloadUrl = URL(string: res.url) else {
308
380
  print("\(self.implementation.TAG) Error no url or wrong format")
381
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
382
+ return
309
383
  }
310
- let current = self.implementation.getCurrentBundle()
311
- let latestVersionName = res?.version
312
- if (latestVersionName != nil && latestVersionName != "" && current.getVersionName() != latestVersionName) {
313
- let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName!)
384
+ let latestVersionName = res.version
385
+ if (latestVersionName != "" && current.getVersionName() != latestVersionName) {
386
+ let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
314
387
  if (latest != nil) {
315
388
  if(latest!.isErrorStatus()) {
316
389
  print("\(self.implementation.TAG) Latest version already exists, and is in error state. Aborting update.")
390
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
317
391
  return
318
392
  }
319
393
  if(latest!.isDownloaded()){
320
394
  print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
321
- let _ = self.implementation.setNextVersion(next: latest!.getId())
395
+ self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
396
+ let _ = self.implementation.setNextBundle(next: latest!.getId())
322
397
  return
323
398
  }
324
399
  }
325
400
 
326
401
  do {
327
- print("\(self.implementation.TAG) New bundle: \(latestVersionName!) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
328
- let next = try self.implementation.download(url: downloadUrl, version: latestVersionName!)
329
-
330
- let _ = self.implementation.setNextVersion(next: next.getId())
402
+ print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
403
+ let next = try self.implementation.download(url: downloadUrl, version: latestVersionName)
404
+ self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
405
+ let _ = self.implementation.setNextBundle(next: next.getId())
331
406
  } catch {
332
407
  print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
408
+ self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
409
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
333
410
  }
411
+ } else {
412
+ print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
413
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
334
414
  }
335
415
  }
336
416
  }
@@ -339,85 +419,24 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
339
419
  }
340
420
 
341
421
  @objc func appMovedToBackground() {
342
- print("\(self.implementation.TAG) Check for waiting update")
343
- let delayUpdate = UserDefaults.standard.bool(forKey: "delayUpdate")
344
- UserDefaults.standard.set(false, forKey: "delayUpdate")
345
- if (delayUpdate) {
422
+ print("\(self.implementation.TAG) Check for pending update")
423
+ let delayUpdate = UserDefaults.standard.string(forKey: DELAY_UPDATE)
424
+ self._checkCancelDelay(killed: false)
425
+ if (delayUpdate != nil) {
346
426
  print("\(self.implementation.TAG) Update delayed to next backgrounding")
347
427
  return
348
428
  }
349
429
 
350
- let fallback: BundleInfo = self.implementation.getFallbackVersion()
351
430
  let current: BundleInfo = self.implementation.getCurrentBundle()
352
- let next: BundleInfo? = self.implementation.getNextVersion()
353
-
354
- let success: Bool = current.getStatus() == BundleStatus.SUCCESS.localizedString
431
+ let next: BundleInfo? = self.implementation.getNextBundle()
355
432
 
356
- print("\(self.implementation.TAG) Fallback bundle is: \(fallback.toString())")
357
- print("\(self.implementation.TAG) Current bundle is: \(current.toString())")
358
-
359
- if (next != nil && !next!.isErrorStatus() && (next!.getVersionName() != current.getVersionName())) {
433
+ if (next != nil && !next!.isErrorStatus() && next!.getVersionName() != current.getVersionName()) {
360
434
  print("\(self.implementation.TAG) Next bundle is: \(next!.toString())")
361
435
  if (self.implementation.set(bundle: next!) && self._reload()) {
362
- print("\(self.implementation.TAG) Updated to bundle: \(next!)")
363
- let _ = self.implementation.setNextVersion(next: Optional<String>.none)
364
- } else {
365
- print("\(self.implementation.TAG) Updated to bundle: \(next!) Failed!")
366
- }
367
- } else if (!success) {
368
- // There is a no next version, and the current version has failed
369
-
370
- if(!current.isBuiltin()) {
371
- // Don't try to roll back the builtin version. Nothing we can do.
372
-
373
- self.implementation.rollback(bundle: current)
374
-
375
- print("\(self.implementation.TAG) Update failed: 'notifyAppReady()' was never called.")
376
- print("\(self.implementation.TAG) Version: \(current.toString()), is in error state.")
377
- print("\(self.implementation.TAG) Will fallback to: \(fallback.toString()) on application restart.")
378
- print("\(self.implementation.TAG) Did you forget to call 'notifyAppReady()' in your Capacitor App code?")
379
-
380
- self.notifyListeners("updateFailed", data: [
381
- "bundle": current.toJSON()
382
- ])
383
- self.implementation.sendStats(action: "revert", bundle: current)
384
- if (!fallback.isBuiltin() && !(fallback == current)) {
385
- let res = self.implementation.set(bundle: fallback)
386
- if (res && self._reload()) {
387
- print("\(self.implementation.TAG) Revert to bundle: \(fallback.toString())")
388
- } else {
389
- print("\(self.implementation.TAG) Revert to bundle: \(fallback.toString()) Failed!")
390
- }
391
- } else {
392
- if (self._reset(toAutoUpdate: false)) {
393
- print("\(self.implementation.TAG) Reverted to 'builtin' bundle.")
394
- }
395
- }
396
-
397
- if (self.autoDeleteFailed) {
398
- print("\(self.implementation.TAG) Deleting failing bundle: \(current.toString())")
399
- let res = self.implementation.delete(id: current.getId())
400
- if (!res) {
401
- print("\(self.implementation.TAG) Delete version deleted: \(current.toString())")
402
- } else {
403
- print("\(self.implementation.TAG) Failed to delete failed bundle: \(current.toString())")
404
- }
405
- }
436
+ print("\(self.implementation.TAG) Updated to bundle: \(next!.toString())")
437
+ let _ = self.implementation.setNextBundle(next: Optional<String>.none)
406
438
  } else {
407
- // Nothing we can/should do by default if the 'builtin' bundle fails to call 'notifyAppReady()'.
408
- }
409
- } else if (!fallback.isBuiltin()) {
410
- // There is a no next version, and the current version has succeeded
411
- self.implementation.commit(bundle: current)
412
-
413
- if(self.autoDeletePrevious) {
414
- print("\(self.implementation.TAG) Version successfully loaded: \(current.toString())")
415
- let res = self.implementation.delete(id: fallback.getId())
416
- if (res) {
417
- print("\(self.implementation.TAG) Deleted previous bundle: \(fallback.toString())")
418
- } else {
419
- print("\(self.implementation.TAG) Failed to delete previous bundle: \(fallback.toString())")
420
- }
439
+ print("\(self.implementation.TAG) Update to bundle: \(next!.toString()) Failed!")
421
440
  }
422
441
  }
423
442
  }
@@ -38,60 +38,4 @@ extension UserDefaults: ObjectSavable {
38
38
  throw ObjectSavableError.unableToDecode
39
39
  }
40
40
  }
41
- }
42
-
43
- //
44
- //// MARK: - Methods
45
- //public extension UserDefaults {
46
- // /// SwifterSwift: get object from UserDefaults by using subscript.
47
- // ///
48
- // /// - Parameter key: key in the current user's defaults database.
49
- // subscript(key: String) -> Any? {
50
- // get {
51
- // return object(forKey: key)
52
- // }
53
- // set {
54
- // set(newValue, forKey: key)
55
- // }
56
- // }
57
- //
58
- // /// SwifterSwift: Float from UserDefaults.
59
- // ///
60
- // /// - Parameter key: key to find float for.
61
- // /// - Returns: Float object for key (if exists).
62
- // func float(forKey key: String) -> Float? {
63
- // return object(forKey: key) as? Float
64
- // }
65
- //
66
- // /// SwifterSwift: Date from UserDefaults.
67
- // ///
68
- // /// - Parameter key: key to find date for.
69
- // /// - Returns: Date object for key (if exists).
70
- // func date(forKey key: String) -> Date? {
71
- // return object(forKey: key) as? Date
72
- // }
73
- //
74
- // /// SwifterSwift: Retrieves a Codable object from UserDefaults.
75
- // ///
76
- // /// - Parameters:
77
- // /// - type: Class that conforms to the Codable protocol.
78
- // /// - key: Identifier of the object.
79
- // /// - decoder: Custom JSONDecoder instance. Defaults to `JSONDecoder()`.
80
- // /// - Returns: Codable object for key (if exists).
81
- // func object<T: Codable>(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? {
82
- // guard let data = value(forKey: key) as? Data else { return nil }
83
- // return try? decoder.decode(type.self, from: data)
84
- // }
85
- //
86
- // /// SwifterSwift: Allows storing of Codable objects to UserDefaults.
87
- // ///
88
- // /// - Parameters:
89
- // /// - object: Codable object to store.
90
- // /// - key: Identifier of the object.
91
- // /// - encoder: Custom JSONEncoder instance. Defaults to `JSONEncoder()`.
92
- // func set<T: Codable>(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) {
93
- // let data = try? encoder.encode(object)
94
- // set(data, forKey: key)
95
- // }
96
- //}
97
- //
41
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.0.0-alpha.7",
4
- "license": "AGPL-3.0-only",
3
+ "version": "4.0.0",
4
+ "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",
7
7
  "module": "dist/esm/index.js",
@@ -68,7 +68,7 @@
68
68
  "typescript": "^4.6.2"
69
69
  },
70
70
  "peerDependencies": {
71
- "@capacitor/core": "^3.0.0"
71
+ "@capacitor/core": "^3.0.0 || ^4.0.0 || ^4.0.0"
72
72
  },
73
73
  "prettier": "@ionic/prettier-config",
74
74
  "swiftlint": "@ionic/swiftlint-config",