@capawesome/capacitor-live-update 7.2.2 → 7.4.0-dev.f18299f8.1767510052

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.
Files changed (38) hide show
  1. package/README.md +289 -28
  2. package/android/build.gradle +2 -0
  3. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +623 -220
  4. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java +23 -0
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java +42 -5
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +185 -15
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePreferences.java +42 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +2 -2
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/events/NextBundleSetEvent.java +26 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetConfigOptions.java +19 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SyncOptions.java +4 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetBlockedBundlesResult.java +27 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetConfigResult.java +40 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetDownloadedBundlesResult.java +27 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/IsSyncingResult.java +26 -0
  16. package/dist/docs.json +428 -1
  17. package/dist/esm/definitions.d.ts +230 -2
  18. package/dist/esm/definitions.js.map +1 -1
  19. package/dist/esm/web.d.ts +8 -1
  20. package/dist/esm/web.js +21 -0
  21. package/dist/esm/web.js.map +1 -1
  22. package/dist/plugin.cjs.js +21 -0
  23. package/dist/plugin.cjs.js.map +1 -1
  24. package/dist/plugin.js +21 -0
  25. package/dist/plugin.js.map +1 -1
  26. package/ios/Plugin/Classes/Events/NextBundleSetEvent.swift +16 -0
  27. package/ios/Plugin/Classes/Options/SetConfigOptions.swift +14 -0
  28. package/ios/Plugin/Classes/Options/SyncOptions.swift +4 -0
  29. package/ios/Plugin/Classes/Results/GetBlockedBundlesResult.swift +16 -0
  30. package/ios/Plugin/Classes/Results/GetConfigResult.swift +19 -0
  31. package/ios/Plugin/Classes/Results/GetDownloadedBundlesResult.swift +16 -0
  32. package/ios/Plugin/Classes/Results/IsSyncingResult.swift +16 -0
  33. package/ios/Plugin/LiveUpdate.swift +178 -4
  34. package/ios/Plugin/LiveUpdateConfig.swift +2 -0
  35. package/ios/Plugin/LiveUpdateHttpClient.swift +4 -2
  36. package/ios/Plugin/LiveUpdatePlugin.swift +106 -11
  37. package/ios/Plugin/LiveUpdatePreferences.swift +56 -0
  38. package/package.json +1 -1
@@ -8,41 +8,65 @@ import Capacitor
8
8
  @objc(LiveUpdatePlugin)
9
9
  public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
10
10
  public static let tag = "LiveUpdate"
11
- public static let version = "7.2.2"
11
+ public static let version = "7.4.0"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
14
  public let identifier = "LiveUpdatePlugin"
15
15
  public let jsName = "LiveUpdate"
16
16
  public let pluginMethods: [CAPPluginMethod] = [
17
+ CAPPluginMethod(name: "clearBlockedBundles", returnType: CAPPluginReturnPromise),
17
18
  CAPPluginMethod(name: "deleteBundle", returnType: CAPPluginReturnPromise),
18
19
  CAPPluginMethod(name: "downloadBundle", returnType: CAPPluginReturnPromise),
19
20
  CAPPluginMethod(name: "fetchLatestBundle", returnType: CAPPluginReturnPromise),
21
+ CAPPluginMethod(name: "getBlockedBundles", returnType: CAPPluginReturnPromise),
20
22
  CAPPluginMethod(name: "getBundles", returnType: CAPPluginReturnPromise),
21
23
  CAPPluginMethod(name: "getChannel", returnType: CAPPluginReturnPromise),
24
+ CAPPluginMethod(name: "getConfig", returnType: CAPPluginReturnPromise),
25
+ CAPPluginMethod(name: "getDownloadedBundles", returnType: CAPPluginReturnPromise),
22
26
  CAPPluginMethod(name: "getCurrentBundle", returnType: CAPPluginReturnPromise),
23
27
  CAPPluginMethod(name: "getCustomId", returnType: CAPPluginReturnPromise),
24
28
  CAPPluginMethod(name: "getDeviceId", returnType: CAPPluginReturnPromise),
25
29
  CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise),
26
30
  CAPPluginMethod(name: "getVersionCode", returnType: CAPPluginReturnPromise),
27
31
  CAPPluginMethod(name: "getVersionName", returnType: CAPPluginReturnPromise),
32
+ CAPPluginMethod(name: "isSyncing", returnType: CAPPluginReturnPromise),
28
33
  CAPPluginMethod(name: "ready", returnType: CAPPluginReturnPromise),
29
34
  CAPPluginMethod(name: "reload", returnType: CAPPluginReturnPromise),
30
35
  CAPPluginMethod(name: "reset", returnType: CAPPluginReturnPromise),
36
+ CAPPluginMethod(name: "resetConfig", returnType: CAPPluginReturnPromise),
31
37
  CAPPluginMethod(name: "setChannel", returnType: CAPPluginReturnPromise),
38
+ CAPPluginMethod(name: "setConfig", returnType: CAPPluginReturnPromise),
32
39
  CAPPluginMethod(name: "setCustomId", returnType: CAPPluginReturnPromise),
33
40
  CAPPluginMethod(name: "setNextBundle", returnType: CAPPluginReturnPromise),
34
41
  CAPPluginMethod(name: "sync", returnType: CAPPluginReturnPromise)
35
42
  ]
36
43
 
37
44
  private let eventDownloadBundleProgess = "downloadBundleProgress"
45
+ private let eventNextBundleSet = "nextBundleSet"
46
+ private let eventReloaded = "reloaded"
38
47
 
39
48
  private var config: LiveUpdateConfig?
40
49
  private var implementation: LiveUpdate?
41
- private var syncInProgress = false
42
50
 
43
51
  override public func load() {
44
52
  self.config = liveUpdateConfig()
45
53
  self.implementation = LiveUpdate(config: config!, plugin: self)
54
+
55
+ // Notify implementation about load
56
+ implementation?.handleLoad()
57
+
58
+ // Register for app resume notifications
59
+ NotificationCenter.default.addObserver(
60
+ self,
61
+ selector: #selector(handleAppWillEnterForeground),
62
+ name: UIApplication.willEnterForegroundNotification,
63
+ object: nil
64
+ )
65
+ }
66
+
67
+ @objc func clearBlockedBundles(_ call: CAPPluginCall) {
68
+ implementation?.clearBlockedBundles()
69
+ resolveCall(call)
46
70
  }
47
71
 
48
72
  @objc func deleteBundle(_ call: CAPPluginCall) {
@@ -90,6 +114,11 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
90
114
  @objc func fetchLatestBundle(_ call: CAPPluginCall) {
91
115
  Task {
92
116
  do {
117
+ guard let appId = config?.appId, !appId.isEmpty else {
118
+ call.reject(CustomError.appIdMissing.localizedDescription)
119
+ return
120
+ }
121
+
93
122
  let options = FetchLatestBundleOptions(call)
94
123
  let result = try await implementation?.fetchLatestBundle(options)
95
124
  if let result = result?.toJSObject() as? JSObject {
@@ -101,6 +130,18 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
101
130
  }
102
131
  }
103
132
 
133
+ @objc func getBlockedBundles(_ call: CAPPluginCall) {
134
+ implementation?.getBlockedBundles(completion: { result, error in
135
+ if let error = error {
136
+ self.rejectCall(call, error)
137
+ return
138
+ }
139
+ if let result = result?.toJSObject() as? JSObject {
140
+ self.resolveCall(call, result)
141
+ }
142
+ })
143
+ }
144
+
104
145
  @objc func getBundles(_ call: CAPPluginCall) {
105
146
  implementation?.getBundles(completion: { result, error in
106
147
  if let error = error {
@@ -113,6 +154,18 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
113
154
  })
114
155
  }
115
156
 
157
+ @objc func getDownloadedBundles(_ call: CAPPluginCall) {
158
+ implementation?.getDownloadedBundles(completion: { result, error in
159
+ if let error = error {
160
+ self.rejectCall(call, error)
161
+ return
162
+ }
163
+ if let result = result?.toJSObject() as? JSObject {
164
+ self.resolveCall(call, result)
165
+ }
166
+ })
167
+ }
168
+
116
169
  @objc func getChannel(_ call: CAPPluginCall) {
117
170
  implementation?.getChannel(completion: { result, error in
118
171
  if let error = error {
@@ -125,6 +178,18 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
125
178
  })
126
179
  }
127
180
 
181
+ @objc func getConfig(_ call: CAPPluginCall) {
182
+ implementation?.getConfig(completion: { result, error in
183
+ if let error = error {
184
+ self.rejectCall(call, error)
185
+ return
186
+ }
187
+ if let result = result?.toJSObject() as? JSObject {
188
+ self.resolveCall(call, result)
189
+ }
190
+ })
191
+ }
192
+
128
193
  @objc func getCurrentBundle(_ call: CAPPluginCall) {
129
194
  implementation?.getCurrentBundle(completion: { result, error in
130
195
  if let error = error {
@@ -197,6 +262,18 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
197
262
  })
198
263
  }
199
264
 
265
+ @objc func isSyncing(_ call: CAPPluginCall) {
266
+ implementation?.isSyncing(completion: { result, error in
267
+ if let error = error {
268
+ self.rejectCall(call, error)
269
+ return
270
+ }
271
+ if let result = result?.toJSObject() as? JSObject {
272
+ self.resolveCall(call, result)
273
+ }
274
+ })
275
+ }
276
+
200
277
  @objc func ready(_ call: CAPPluginCall) {
201
278
  implementation?.ready(completion: { result, error in
202
279
  if let error = error {
@@ -219,6 +296,11 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
219
296
  resolveCall(call)
220
297
  }
221
298
 
299
+ @objc func resetConfig(_ call: CAPPluginCall) {
300
+ implementation?.resetConfig()
301
+ resolveCall(call)
302
+ }
303
+
222
304
  @objc func setChannel(_ call: CAPPluginCall) {
223
305
  let channel = call.getString("channel")
224
306
 
@@ -233,6 +315,12 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
233
315
  })
234
316
  }
235
317
 
318
+ @objc func setConfig(_ call: CAPPluginCall) {
319
+ let options = SetConfigOptions(call)
320
+ implementation?.setConfig(options)
321
+ resolveCall(call)
322
+ }
323
+
236
324
  @objc func setCustomId(_ call: CAPPluginCall) {
237
325
  guard let customId = call.getString("customId") else {
238
326
  call.reject(CustomError.customIdMissing.localizedDescription)
@@ -265,25 +353,17 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
265
353
  @objc func sync(_ call: CAPPluginCall) {
266
354
  Task {
267
355
  do {
268
- guard let _ = config?.appId else {
356
+ guard let appId = config?.appId, !appId.isEmpty else {
269
357
  call.reject(CustomError.appIdMissing.localizedDescription)
270
358
  return
271
359
  }
272
360
 
273
- guard !syncInProgress else {
274
- call.reject(CustomError.syncInProgress.localizedDescription)
275
- return
276
- }
277
- syncInProgress = true
278
-
279
361
  let options = SyncOptions(call)
280
362
  let result = try await implementation?.sync(options)
281
- self.syncInProgress = false
282
363
  if let result = result?.toJSObject() as? JSObject {
283
364
  resolveCall(call, result)
284
365
  }
285
366
  } catch {
286
- self.syncInProgress = false
287
367
  rejectCall(call, error)
288
368
  }
289
369
  }
@@ -295,11 +375,26 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
295
375
  }
296
376
  }
297
377
 
378
+ func notifyNextBundleSetListeners(_ event: NextBundleSetEvent) {
379
+ notifyListeners(eventNextBundleSet, data: event.toJSObject(), retainUntilConsumed: false)
380
+ }
381
+
382
+ func notifyReloadedListeners() {
383
+ let event = JSObject()
384
+ notifyListeners(eventReloaded, data: event, retainUntilConsumed: true)
385
+ }
386
+
387
+ @objc private func handleAppWillEnterForeground() {
388
+ implementation?.handleAppWillEnterForeground()
389
+ }
390
+
298
391
  private func liveUpdateConfig() -> LiveUpdateConfig {
299
392
  var config = LiveUpdateConfig()
300
393
 
301
394
  config.appId = getConfig().getString("appId", config.appId)
395
+ config.autoBlockRolledBackBundles = getConfig().getBoolean("autoBlockRolledBackBundles", config.autoBlockRolledBackBundles)
302
396
  config.autoDeleteBundles = getConfig().getBoolean("autoDeleteBundles", config.autoDeleteBundles)
397
+ config.autoUpdateStrategy = getConfig().getString("autoUpdateStrategy", config.autoUpdateStrategy) ?? config.autoUpdateStrategy
303
398
  config.defaultChannel = getConfig().getString("defaultChannel", config.defaultChannel)
304
399
  config.httpTimeout = getConfig().getInt("httpTimeout", config.httpTimeout)
305
400
  config.publicKey = getConfig().getString("publicKey", config.publicKey)
@@ -1,10 +1,22 @@
1
1
  import Foundation
2
2
 
3
3
  public class LiveUpdatePreferences: NSObject {
4
+ private let appIdKey = "appId" // DO NOT CHANGE
5
+ private let blockedBundleIdsKey = "blockedBundleIds" // DO NOT CHANGE
4
6
  private let channelKey = "channel" // DO NOT CHANGE
5
7
  private let customIdKey = "customId" // DO NOT CHANGE
8
+ private let lastVersionCodeKey = "lastVersionCode" // DO NOT CHANGE
9
+ private let lastVersionNameKey = "lastVersionName" // DO NOT CHANGE
6
10
  private let previousBundleIdKey = "previousBundleIdKey" // DO NOT CHANGE
7
11
 
12
+ public func getAppId() -> String? {
13
+ return UserDefaults.standard.string(forKey: applyPrefix(to: appIdKey))
14
+ }
15
+
16
+ public func getBlockedBundleIds() -> String? {
17
+ return UserDefaults.standard.string(forKey: applyPrefix(to: blockedBundleIdsKey))
18
+ }
19
+
8
20
  public func getChannel() -> String? {
9
21
  return UserDefaults.standard.string(forKey: applyPrefix(to: channelKey))
10
22
  }
@@ -13,10 +25,36 @@ public class LiveUpdatePreferences: NSObject {
13
25
  return UserDefaults.standard.string(forKey: applyPrefix(to: customIdKey))
14
26
  }
15
27
 
28
+ public func getLastVersionCode() -> String? {
29
+ return UserDefaults.standard.string(forKey: applyPrefix(to: lastVersionCodeKey))
30
+ }
31
+
32
+ public func getLastVersionName() -> String? {
33
+ return UserDefaults.standard.string(forKey: applyPrefix(to: lastVersionNameKey))
34
+ }
35
+
16
36
  public func getPreviousBundleId() -> String? {
17
37
  return UserDefaults.standard.string(forKey: applyPrefix(to: previousBundleIdKey))
18
38
  }
19
39
 
40
+ public func setAppId(_ value: String?) {
41
+ if let value = value {
42
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: appIdKey))
43
+ } else {
44
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: appIdKey))
45
+ }
46
+ UserDefaults.standard.synchronize()
47
+ }
48
+
49
+ public func setBlockedBundleIds(_ value: String?) {
50
+ if let value = value {
51
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: blockedBundleIdsKey))
52
+ } else {
53
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: blockedBundleIdsKey))
54
+ }
55
+ UserDefaults.standard.synchronize()
56
+ }
57
+
20
58
  public func setChannel(_ value: String?) {
21
59
  if let value = value {
22
60
  UserDefaults.standard.set(value, forKey: applyPrefix(to: channelKey))
@@ -31,6 +69,24 @@ public class LiveUpdatePreferences: NSObject {
31
69
  UserDefaults.standard.synchronize()
32
70
  }
33
71
 
72
+ public func setLastVersionCode(_ value: String?) {
73
+ if let value = value {
74
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: lastVersionCodeKey))
75
+ } else {
76
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastVersionCodeKey))
77
+ }
78
+ UserDefaults.standard.synchronize()
79
+ }
80
+
81
+ public func setLastVersionName(_ value: String?) {
82
+ if let value = value {
83
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: lastVersionNameKey))
84
+ } else {
85
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastVersionNameKey))
86
+ }
87
+ UserDefaults.standard.synchronize()
88
+ }
89
+
34
90
  public func setPreviousBundleId(_ value: String?) {
35
91
  if let value = value {
36
92
  UserDefaults.standard.set(value, forKey: applyPrefix(to: previousBundleIdKey))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "7.2.2",
3
+ "version": "7.4.0-dev.f18299f8.1767510052",
4
4
  "description": "Capacitor plugin to update your app remotely in real-time.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",