@capawesome/capacitor-live-update 6.7.2 → 7.1.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.
Files changed (43) hide show
  1. package/CapawesomeCapacitorLiveUpdate.podspec +2 -2
  2. package/Package.swift +32 -0
  3. package/README.md +102 -88
  4. package/android/build.gradle +9 -9
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +192 -133
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java +6 -27
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java +7 -2
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +51 -77
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePreferences.java +12 -5
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +27 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/events/DownloadBundleProgressEvent.java +32 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/DownloadBundleOptions.java +16 -1
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchLatestBundleResult.java +29 -1
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/ReadyResult.java +32 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/interfaces/DownloadProgressCallback.java +5 -0
  16. package/dist/docs.json +228 -147
  17. package/dist/esm/definitions.d.ts +140 -49
  18. package/dist/esm/definitions.js.map +1 -1
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/web.d.ts +2 -2
  22. package/dist/esm/web.js.map +1 -1
  23. package/dist/plugin.cjs.js +1 -3
  24. package/dist/plugin.cjs.js.map +1 -1
  25. package/dist/plugin.js +1 -3
  26. package/dist/plugin.js.map +1 -1
  27. package/ios/Plugin/Classes/Events/DownloadBundleProgressEvent.swift +25 -0
  28. package/ios/Plugin/Classes/Options/DownloadBundleOptions.swift +7 -1
  29. package/ios/Plugin/Classes/Results/{FetchLatestBundle.swift → FetchLatestBundleResult.swift} +16 -1
  30. package/ios/Plugin/Classes/Results/ReadyResult.swift +22 -0
  31. package/ios/Plugin/LiveUpdate.swift +171 -154
  32. package/ios/Plugin/LiveUpdateConfig.swift +2 -4
  33. package/ios/Plugin/LiveUpdateHttpClient.swift +6 -2
  34. package/ios/Plugin/LiveUpdatePlugin.swift +45 -37
  35. package/ios/Plugin/LiveUpdatePreferences.swift +6 -20
  36. package/ios/Plugin/Protocols/Api/GetLatestBundleResponse.swift +3 -0
  37. package/package.json +17 -18
  38. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetBundleOptions.java +0 -18
  39. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetBundleResult.java +0 -24
  40. package/ios/Plugin/Classes/Options/SetBundleOptions.swift +0 -14
  41. package/ios/Plugin/Classes/Results/GetBundleResult.swift +0 -16
  42. package/ios/Plugin/LiveUpdatePlugin.h +0 -10
  43. package/ios/Plugin/LiveUpdatePlugin.m +0 -27
@@ -18,12 +18,16 @@ public class LiveUpdateHttpClient: NSObject {
18
18
  self.config = config
19
19
  }
20
20
 
21
- public func download(url: URL, destination: @escaping DownloadRequest.Destination) async throws -> AFDownloadResponse<Data> {
21
+ public func download(url: URL, destination: @escaping DownloadRequest.Destination, callback: ((Progress) -> Void)?) async throws -> AFDownloadResponse<Data> {
22
22
  var request = URLRequest(url: url)
23
23
  request.httpMethod = HTTPMethod.get.rawValue
24
24
  request.timeoutInterval = Double(config.httpTimeout) / 1000.0
25
25
  return try await withCheckedThrowingContinuation { continuation in
26
- AF.download(request, to: destination).responseData { response in
26
+ AF.download(request, to: destination).downloadProgress { progress in
27
+ if let callback = callback {
28
+ callback(progress)
29
+ }
30
+ }.responseData { response in
27
31
  continuation.resume(returning: response)
28
32
  }
29
33
  }
@@ -6,11 +6,36 @@ import Capacitor
6
6
  * here: https://capacitorjs.com/docs/plugins/ios
7
7
  */
8
8
  @objc(LiveUpdatePlugin)
9
- public class LiveUpdatePlugin: CAPPlugin {
9
+ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
10
10
  public static let tag = "LiveUpdate"
11
- public static let version = "6.7.2"
11
+ public static let version = "7.1.0"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
+ public let identifier = "LiveUpdatePlugin"
15
+ public let jsName = "LiveUpdate"
16
+ public let pluginMethods: [CAPPluginMethod] = [
17
+ CAPPluginMethod(name: "deleteBundle", returnType: CAPPluginReturnPromise),
18
+ CAPPluginMethod(name: "downloadBundle", returnType: CAPPluginReturnPromise),
19
+ CAPPluginMethod(name: "fetchLatestBundle", returnType: CAPPluginReturnPromise),
20
+ CAPPluginMethod(name: "getBundles", returnType: CAPPluginReturnPromise),
21
+ CAPPluginMethod(name: "getChannel", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "getCurrentBundle", returnType: CAPPluginReturnPromise),
23
+ CAPPluginMethod(name: "getCustomId", returnType: CAPPluginReturnPromise),
24
+ CAPPluginMethod(name: "getDeviceId", returnType: CAPPluginReturnPromise),
25
+ CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise),
26
+ CAPPluginMethod(name: "getVersionCode", returnType: CAPPluginReturnPromise),
27
+ CAPPluginMethod(name: "getVersionName", returnType: CAPPluginReturnPromise),
28
+ CAPPluginMethod(name: "ready", returnType: CAPPluginReturnPromise),
29
+ CAPPluginMethod(name: "reload", returnType: CAPPluginReturnPromise),
30
+ CAPPluginMethod(name: "reset", returnType: CAPPluginReturnPromise),
31
+ CAPPluginMethod(name: "setChannel", returnType: CAPPluginReturnPromise),
32
+ CAPPluginMethod(name: "setCustomId", returnType: CAPPluginReturnPromise),
33
+ CAPPluginMethod(name: "setNextBundle", returnType: CAPPluginReturnPromise),
34
+ CAPPluginMethod(name: "sync", returnType: CAPPluginReturnPromise)
35
+ ]
36
+
37
+ private let eventDownloadBundleProgess = "downloadBundleProgress"
38
+
14
39
  private var config: LiveUpdateConfig?
15
40
  private var implementation: LiveUpdate?
16
41
  private var syncInProgress = false
@@ -46,12 +71,13 @@ public class LiveUpdatePlugin: CAPPlugin {
46
71
  return
47
72
  }
48
73
  let checksum = call.getString("checksum")
74
+ let signature = call.getString("signature")
49
75
  guard let url = call.getString("url") else {
50
76
  call.reject(CustomError.urlMissing.localizedDescription)
51
77
  return
52
78
  }
53
79
 
54
- let options = DownloadBundleOptions(artifactType: artifactType, bundleId: bundleId, checksum: checksum, url: url)
80
+ let options = DownloadBundleOptions(artifactType: artifactType, bundleId: bundleId, checksum: checksum, signature: signature, url: url)
55
81
 
56
82
  try await implementation?.downloadBundle(options)
57
83
  self.resolveCall(call)
@@ -75,18 +101,6 @@ public class LiveUpdatePlugin: CAPPlugin {
75
101
  }
76
102
  }
77
103
 
78
- @objc func getBundle(_ call: CAPPluginCall) {
79
- implementation?.getBundle(completion: { result, error in
80
- if let error = error {
81
- self.rejectCall(call, error)
82
- return
83
- }
84
- if let result = result?.toJSObject() as? JSObject {
85
- self.resolveCall(call, result)
86
- }
87
- })
88
- }
89
-
90
104
  @objc func getBundles(_ call: CAPPluginCall) {
91
105
  implementation?.getBundles(completion: { result, error in
92
106
  if let error = error {
@@ -184,8 +198,15 @@ public class LiveUpdatePlugin: CAPPlugin {
184
198
  }
185
199
 
186
200
  @objc func ready(_ call: CAPPluginCall) {
187
- implementation?.ready()
188
- resolveCall(call)
201
+ implementation?.ready(completion: { result, error in
202
+ if let error = error {
203
+ self.rejectCall(call, error)
204
+ return
205
+ }
206
+ if let result = result?.toJSObject() as? JSObject {
207
+ self.resolveCall(call, result)
208
+ }
209
+ })
189
210
  }
190
211
 
191
212
  @objc func reload(_ call: CAPPluginCall) {
@@ -198,23 +219,6 @@ public class LiveUpdatePlugin: CAPPlugin {
198
219
  resolveCall(call)
199
220
  }
200
221
 
201
- @objc func setBundle(_ call: CAPPluginCall) {
202
- guard let bundleId = call.getString("bundleId") else {
203
- call.reject(CustomError.bundleIdMissing.localizedDescription)
204
- return
205
- }
206
-
207
- let options = SetBundleOptions(bundleId: bundleId)
208
-
209
- implementation?.setBundle(options, completion: { error in
210
- if let error = error {
211
- self.rejectCall(call, error)
212
- return
213
- }
214
- self.resolveCall(call)
215
- })
216
- }
217
-
218
222
  @objc func setChannel(_ call: CAPPluginCall) {
219
223
  let channel = call.getString("channel")
220
224
 
@@ -285,18 +289,22 @@ public class LiveUpdatePlugin: CAPPlugin {
285
289
  }
286
290
  }
287
291
 
292
+ func notifyDownloadBundleProgressListeners(_ event: DownloadBundleProgressEvent) {
293
+ if let event = event.toJSObject() as? JSObject {
294
+ notifyListeners(eventDownloadBundleProgess, data: event, retainUntilConsumed: false)
295
+ }
296
+ }
297
+
288
298
  private func liveUpdateConfig() -> LiveUpdateConfig {
289
299
  var config = LiveUpdateConfig()
290
300
 
291
301
  config.appId = getConfig().getString("appId", config.appId)
292
302
  config.autoDeleteBundles = getConfig().getBoolean("autoDeleteBundles", config.autoDeleteBundles)
293
303
  config.defaultChannel = getConfig().getString("defaultChannel", config.defaultChannel)
294
- config.enabled = getConfig().getBoolean("enabled", config.enabled)
295
304
  config.httpTimeout = getConfig().getInt("httpTimeout", config.httpTimeout)
296
- config.location = getConfig().getString("location", config.location)
297
305
  config.publicKey = getConfig().getString("publicKey", config.publicKey)
298
306
  config.readyTimeout = getConfig().getInt("readyTimeout", config.readyTimeout)
299
- config.resetOnUpdate = getConfig().getBoolean("resetOnUpdate", config.resetOnUpdate)
307
+ config.serverDomain = getConfig().getString("serverDomain", config.serverDomain) ?? config.serverDomain
300
308
 
301
309
  return config
302
310
  }
@@ -3,8 +3,7 @@ import Foundation
3
3
  public class LiveUpdatePreferences: NSObject {
4
4
  private let channelKey = "channel" // DO NOT CHANGE
5
5
  private let customIdKey = "customId" // DO NOT CHANGE
6
- private let lastBundleShortVersionStringKey = "lastBundleShortVersionString" // DO NOT CHANGE
7
- private let lastBundleVersionKey = "lastBundleVersion" // DO NOT CHANGE
6
+ private let previousBundleIdKey = "previousBundleIdKey" // DO NOT CHANGE
8
7
 
9
8
  public func getChannel() -> String? {
10
9
  return UserDefaults.standard.string(forKey: applyPrefix(to: channelKey))
@@ -13,13 +12,9 @@ public class LiveUpdatePreferences: NSObject {
13
12
  public func getCustomId() -> String? {
14
13
  return UserDefaults.standard.string(forKey: applyPrefix(to: customIdKey))
15
14
  }
16
-
17
- public func getLastBundleShortVersionString() -> String? {
18
- return UserDefaults.standard.string(forKey: applyPrefix(to: lastBundleShortVersionStringKey))
19
- }
20
15
 
21
- public func getLastBundleVersion() -> String? {
22
- return UserDefaults.standard.string(forKey: applyPrefix(to: lastBundleVersionKey))
16
+ public func getPreviousBundleId() -> String? {
17
+ return UserDefaults.standard.string(forKey: applyPrefix(to: previousBundleIdKey))
23
18
  }
24
19
 
25
20
  public func setChannel(_ value: String?) {
@@ -35,21 +30,12 @@ public class LiveUpdatePreferences: NSObject {
35
30
  UserDefaults.standard.set(value, forKey: applyPrefix(to: customIdKey))
36
31
  UserDefaults.standard.synchronize()
37
32
  }
38
-
39
- public func setLastBundleShortVersionString(_ value: String?) {
40
- if let value = value {
41
- UserDefaults.standard.set(value, forKey: applyPrefix(to: lastBundleShortVersionStringKey))
42
- } else {
43
- UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastBundleShortVersionStringKey))
44
- }
45
- UserDefaults.standard.synchronize()
46
- }
47
33
 
48
- public func setLastBundleVersion(_ value: String?) {
34
+ public func setPreviousBundleId(_ value: String?) {
49
35
  if let value = value {
50
- UserDefaults.standard.set(value, forKey: applyPrefix(to: lastBundleVersionKey))
36
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: previousBundleIdKey))
51
37
  } else {
52
- UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastBundleVersionKey))
38
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: previousBundleIdKey))
53
39
  }
54
40
  UserDefaults.standard.synchronize()
55
41
  }
@@ -1,5 +1,8 @@
1
1
  public struct GetLatestBundleResponse: Codable {
2
2
  var artifactType: ArtifactType
3
3
  var bundleId: String
4
+ var checksum: String?
5
+ var customProperties: [String: String]?
6
+ var signature: String?
4
7
  var url: String
5
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "6.7.2",
3
+ "version": "7.1.0",
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",
@@ -11,7 +11,8 @@
11
11
  "android/build.gradle",
12
12
  "dist/",
13
13
  "ios/Plugin/",
14
- "CapawesomeCapacitorLiveUpdate.podspec"
14
+ "CapawesomeCapacitorLiveUpdate.podspec",
15
+ "Package.swift"
15
16
  ],
16
17
  "author": "Robin Genz <mail@robingenz.dev>",
17
18
  "license": "MIT",
@@ -56,7 +57,7 @@
56
57
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
57
58
  "swiftlint": "node-swiftlint",
58
59
  "docgen": "docgen --api LiveUpdatePlugin --output-readme README.md --output-json dist/docs.json",
59
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
60
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
60
61
  "clean": "rimraf ./dist",
61
62
  "watch": "tsc --watch",
62
63
  "version": "node scripts/sync-plugin-version.mjs",
@@ -64,26 +65,24 @@
64
65
  "prepublishOnly": "npm run build"
65
66
  },
66
67
  "devDependencies": {
67
- "@capacitor/android": "6.0.0",
68
- "@capacitor/cli": "6.0.0",
69
- "@capacitor/core": "6.0.0",
68
+ "@capacitor/android": "7.0.0",
69
+ "@capacitor/cli": "7.0.0",
70
+ "@capacitor/core": "7.0.0",
70
71
  "@capacitor/docgen": "0.3.0",
71
- "@capacitor/ios": "6.0.0",
72
- "@ionic/eslint-config": "0.3.0",
73
- "@ionic/prettier-config": "2.0.0",
74
- "@ionic/swiftlint-config": "1.1.2",
75
- "eslint": "7.32.0",
76
- "prettier": "2.6.2",
77
- "prettier-plugin-java": "1.6.1",
78
- "rimraf": "3.0.2",
79
- "rollup": "2.77.2",
80
- "swiftlint": "1.0.1",
72
+ "@capacitor/ios": "7.0.0",
73
+ "@ionic/eslint-config": "0.4.0",
74
+ "@ionic/swiftlint-config": "2.0.0",
75
+ "eslint": "8.57.0",
76
+ "prettier": "3.4.2",
77
+ "prettier-plugin-java": "2.6.7",
78
+ "rimraf": "6.0.1",
79
+ "rollup": "4.30.1",
80
+ "swiftlint": "2.0.0",
81
81
  "typescript": "4.1.5"
82
82
  },
83
83
  "peerDependencies": {
84
- "@capacitor/core": "^6.0.0"
84
+ "@capacitor/core": ">=7.0.0"
85
85
  },
86
- "prettier": "@ionic/prettier-config",
87
86
  "swiftlint": "@ionic/swiftlint-config",
88
87
  "eslintConfig": {
89
88
  "extends": "@ionic/eslint-config/recommended"
@@ -1,18 +0,0 @@
1
- package io.capawesome.capacitorjs.plugins.liveupdate.classes.options;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- public class SetBundleOptions {
6
-
7
- @NonNull
8
- private String bundleId;
9
-
10
- public SetBundleOptions(@NonNull String bundleId) {
11
- this.bundleId = bundleId;
12
- }
13
-
14
- @NonNull
15
- public String getBundleId() {
16
- return bundleId;
17
- }
18
- }
@@ -1,24 +0,0 @@
1
- package io.capawesome.capacitorjs.plugins.liveupdate.classes.results;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
- import com.getcapacitor.JSArray;
6
- import com.getcapacitor.JSObject;
7
- import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
8
- import org.json.JSONObject;
9
-
10
- public class GetBundleResult implements Result {
11
-
12
- @Nullable
13
- private String bundleId;
14
-
15
- public GetBundleResult(@Nullable String bundleId) {
16
- this.bundleId = bundleId;
17
- }
18
-
19
- public JSObject toJSObject() {
20
- JSObject result = new JSObject();
21
- result.put("bundleId", bundleId == null ? JSONObject.NULL : bundleId);
22
- return result;
23
- }
24
- }
@@ -1,14 +0,0 @@
1
- import Foundation
2
- import Capacitor
3
-
4
- @objc public class SetBundleOptions: NSObject {
5
- private var bundleId: String
6
-
7
- init(bundleId: String) {
8
- self.bundleId = bundleId
9
- }
10
-
11
- func getBundleId() -> String {
12
- return bundleId
13
- }
14
- }
@@ -1,16 +0,0 @@
1
- import Foundation
2
- import Capacitor
3
-
4
- @objc public class GetBundleResult: NSObject, Result {
5
- let bundleId: String?
6
-
7
- init(bundleId: String?) {
8
- self.bundleId = bundleId
9
- }
10
-
11
- public func toJSObject() -> AnyObject {
12
- var result = JSObject()
13
- result["bundleId"] = bundleId == nil ? NSNull() : bundleId
14
- return result as AnyObject
15
- }
16
- }
@@ -1,10 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
-
3
- //! Project version number for Plugin.
4
- FOUNDATION_EXPORT double PluginVersionNumber;
5
-
6
- //! Project version string for Plugin.
7
- FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
-
9
- // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
-
@@ -1,27 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
- #import <Capacitor/Capacitor.h>
3
-
4
- // Define the plugin using the CAP_PLUGIN Macro, and
5
- // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
- CAP_PLUGIN(LiveUpdatePlugin, "LiveUpdate",
7
- CAP_PLUGIN_METHOD(deleteBundle, CAPPluginReturnPromise);
8
- CAP_PLUGIN_METHOD(downloadBundle, CAPPluginReturnPromise);
9
- CAP_PLUGIN_METHOD(fetchLatestBundle, CAPPluginReturnPromise);
10
- CAP_PLUGIN_METHOD(getBundle, CAPPluginReturnPromise);
11
- CAP_PLUGIN_METHOD(getBundles, CAPPluginReturnPromise);
12
- CAP_PLUGIN_METHOD(getChannel, CAPPluginReturnPromise);
13
- CAP_PLUGIN_METHOD(getCurrentBundle, CAPPluginReturnPromise);
14
- CAP_PLUGIN_METHOD(getCustomId, CAPPluginReturnPromise);
15
- CAP_PLUGIN_METHOD(getDeviceId, CAPPluginReturnPromise);
16
- CAP_PLUGIN_METHOD(getNextBundle, CAPPluginReturnPromise);
17
- CAP_PLUGIN_METHOD(getVersionCode, CAPPluginReturnPromise);
18
- CAP_PLUGIN_METHOD(getVersionName, CAPPluginReturnPromise);
19
- CAP_PLUGIN_METHOD(ready, CAPPluginReturnPromise);
20
- CAP_PLUGIN_METHOD(reload, CAPPluginReturnPromise);
21
- CAP_PLUGIN_METHOD(reset, CAPPluginReturnPromise);
22
- CAP_PLUGIN_METHOD(setBundle, CAPPluginReturnPromise);
23
- CAP_PLUGIN_METHOD(setChannel, CAPPluginReturnPromise);
24
- CAP_PLUGIN_METHOD(setCustomId, CAPPluginReturnPromise);
25
- CAP_PLUGIN_METHOD(setNextBundle, CAPPluginReturnPromise);
26
- CAP_PLUGIN_METHOD(sync, CAPPluginReturnPromise);
27
- )