@capawesome/capacitor-live-update 8.1.1 → 8.2.1-dev.70823ec8.1778138208
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.
- package/CapawesomeCapacitorLiveUpdate.podspec +15 -0
- package/Package.swift +21 -5
- package/README.md +147 -3
- package/android/build.gradle +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +104 -2
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java +12 -1
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +39 -1
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetChannelsResponseItem.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/FetchChannelsOptions.java +38 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/FetchLatestBundleOptions.java +15 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/ChannelResult.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchChannelsResult.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchLatestBundleResult.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/providers/ionic/LiveUpdateIonicManager.java +232 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/providers/ionic/LiveUpdateIonicProvider.java +41 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/providers/ionic/LiveUpdateIonicProviderRegistration.java +46 -0
- package/dist/docs.json +151 -3
- package/dist/esm/definitions.d.ts +85 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +2 -1
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +3 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Classes/Options/FetchChannelsOptions.swift +26 -0
- package/ios/Plugin/Classes/Options/FetchLatestBundleOptions.swift +12 -0
- package/ios/Plugin/Classes/Results/ChannelResult.swift +19 -0
- package/ios/Plugin/Classes/Results/FetchChannelsResult.swift +16 -0
- package/ios/Plugin/Classes/Results/FetchLatestBundleResult.swift +24 -0
- package/ios/Plugin/Enums/CustomError.swift +12 -0
- package/ios/Plugin/LiveUpdate.swift +55 -1
- package/ios/Plugin/LiveUpdateHttpClient.swift +11 -0
- package/ios/Plugin/LiveUpdatePlugin.swift +40 -1
- package/ios/Plugin/Protocols/Api/GetChannelsResponseItem.swift +4 -0
- package/ios/Plugin/Providers/Ionic/LiveUpdateIonicManager.swift +118 -0
- package/ios/Plugin/Providers/Ionic/LiveUpdateIonicProvider.swift +25 -0
- package/package.json +1 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class FetchChannelsResult: NSObject, Result {
|
|
5
|
+
private let channels: [ChannelResult]
|
|
6
|
+
|
|
7
|
+
init(channels: [ChannelResult]) {
|
|
8
|
+
self.channels = channels
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public func toJSObject() -> AnyObject {
|
|
12
|
+
var result = JSObject()
|
|
13
|
+
result["channels"] = channels.map { $0.toJSObject() }
|
|
14
|
+
return result as AnyObject
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -18,6 +18,30 @@ import Capacitor
|
|
|
18
18
|
self.signature = signature
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
public func getArtifactType() -> String? {
|
|
22
|
+
return artifactType?.rawValue
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public func getBundleId() -> String? {
|
|
26
|
+
return bundleId
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public func getChecksum() -> String? {
|
|
30
|
+
return checksum
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public func getCustomProperties() -> [String: Any]? {
|
|
34
|
+
return customProperties
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public func getDownloadUrl() -> String? {
|
|
38
|
+
return downloadUrl
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public func getSignature() -> String? {
|
|
42
|
+
return signature
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
public func toJSObject() -> AnyObject {
|
|
22
46
|
var result = JSObject()
|
|
23
47
|
if artifactType == .manifest {
|
|
@@ -3,15 +3,19 @@ import Foundation
|
|
|
3
3
|
public enum CustomError: Error {
|
|
4
4
|
case appIdMissing
|
|
5
5
|
case bundleAlreadyExists
|
|
6
|
+
case bundleDirectoryNotFound
|
|
6
7
|
case bundleIdMissing
|
|
7
8
|
case bundleIndexHtmlMissing
|
|
8
9
|
case bundleNotFound
|
|
10
|
+
case channelDiscoveryNotEnabled
|
|
9
11
|
case channelMissing
|
|
10
12
|
case checksumCalculationFailed
|
|
11
13
|
case checksumMismatch
|
|
12
14
|
case customIdMissing
|
|
13
15
|
case downloadFailed
|
|
16
|
+
case downloadUrlMissing
|
|
14
17
|
case httpTimeout
|
|
18
|
+
case managerKeyMissing
|
|
15
19
|
case signatureMissing
|
|
16
20
|
case signatureVerificationFailed
|
|
17
21
|
case syncInProgress
|
|
@@ -26,12 +30,16 @@ extension CustomError: LocalizedError {
|
|
|
26
30
|
return NSLocalizedString("appId must be configured.", comment: "appIdMissing")
|
|
27
31
|
case .bundleAlreadyExists:
|
|
28
32
|
return NSLocalizedString("bundle already exists.", comment: "bundleAlreadyExists")
|
|
33
|
+
case .bundleDirectoryNotFound:
|
|
34
|
+
return NSLocalizedString("Bundle directory could not be resolved.", comment: "bundleDirectoryNotFound")
|
|
29
35
|
case .bundleIdMissing:
|
|
30
36
|
return NSLocalizedString("bundleId must be provided.", comment: "bundleIdMissing")
|
|
31
37
|
case .bundleIndexHtmlMissing:
|
|
32
38
|
return NSLocalizedString("The bundle does not contain an index.html file.", comment: "bundleIndexHtmlMissing")
|
|
33
39
|
case .bundleNotFound:
|
|
34
40
|
return NSLocalizedString("bundle not found.", comment: "bundleNotFound")
|
|
41
|
+
case .channelDiscoveryNotEnabled:
|
|
42
|
+
return NSLocalizedString("Unauthorized. Channel Discovery may not be enabled for this app.", comment: "channelDiscoveryNotEnabled")
|
|
35
43
|
case .channelMissing:
|
|
36
44
|
return NSLocalizedString("channel must be provided.", comment: "channelMissing")
|
|
37
45
|
case .checksumCalculationFailed:
|
|
@@ -42,8 +50,12 @@ extension CustomError: LocalizedError {
|
|
|
42
50
|
return NSLocalizedString("customId must be provided.", comment: "customIdMissing")
|
|
43
51
|
case .downloadFailed:
|
|
44
52
|
return NSLocalizedString("Bundle could not be downloaded.", comment: "downloadFailed")
|
|
53
|
+
case .downloadUrlMissing:
|
|
54
|
+
return NSLocalizedString("Bundle does not have a valid download URL.", comment: "downloadUrlMissing")
|
|
45
55
|
case .httpTimeout:
|
|
46
56
|
return NSLocalizedString("Request timed out.", comment: "httpTimeout")
|
|
57
|
+
case .managerKeyMissing:
|
|
58
|
+
return NSLocalizedString("managerKey must be provided.", comment: "managerKeyMissing")
|
|
47
59
|
case .signatureMissing:
|
|
48
60
|
return NSLocalizedString("Bundle does not contain a signature.", comment: "signatureMissing")
|
|
49
61
|
case .signatureVerificationFailed:
|
|
@@ -34,6 +34,9 @@ import CommonCrypto
|
|
|
34
34
|
// Check version and reset config if version changed
|
|
35
35
|
checkAndResetConfigIfVersionChanged()
|
|
36
36
|
|
|
37
|
+
// Set the device ID on the HTTP client (after any potential config reset)
|
|
38
|
+
self.httpClient.setDeviceId(getDeviceId())
|
|
39
|
+
|
|
37
40
|
// Start the rollback timer to rollback to the default bundle
|
|
38
41
|
// if the app is not ready after a certain time
|
|
39
42
|
startRollbackTimer()
|
|
@@ -80,6 +83,39 @@ import CommonCrypto
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
@objc public func fetchChannels(_ options: FetchChannelsOptions) async throws -> FetchChannelsResult {
|
|
87
|
+
var parameters = [String: String]()
|
|
88
|
+
if let limit = options.getLimit() {
|
|
89
|
+
parameters["limit"] = String(limit)
|
|
90
|
+
}
|
|
91
|
+
if let offset = options.getOffset() {
|
|
92
|
+
parameters["offset"] = String(offset)
|
|
93
|
+
}
|
|
94
|
+
if let query = options.getQuery() {
|
|
95
|
+
parameters["query"] = query
|
|
96
|
+
}
|
|
97
|
+
var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(getAppId() ?? "")/channels")!
|
|
98
|
+
if !parameters.isEmpty {
|
|
99
|
+
urlComponents.queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) }
|
|
100
|
+
}
|
|
101
|
+
let url = try urlComponents.asURL()
|
|
102
|
+
let response = try await self.httpClient.request(url: url, type: [GetChannelsResponseItem].self)
|
|
103
|
+
if let error = response.error {
|
|
104
|
+
if response.response?.statusCode == 401 {
|
|
105
|
+
throw CustomError.channelDiscoveryNotEnabled
|
|
106
|
+
}
|
|
107
|
+
if let urlError = error.underlyingError as? URLError {
|
|
108
|
+
if urlError.code == .timedOut {
|
|
109
|
+
throw urlError
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
throw error
|
|
113
|
+
}
|
|
114
|
+
let items = response.value ?? []
|
|
115
|
+
let channels = items.map { ChannelResult(id: $0.id, name: $0.name) }
|
|
116
|
+
return FetchChannelsResult(channels: channels)
|
|
117
|
+
}
|
|
118
|
+
|
|
83
119
|
@objc public func fetchLatestBundle(_ options: FetchLatestBundleOptions) async throws -> FetchLatestBundleResult {
|
|
84
120
|
let response: GetLatestBundleResponse? = try await self.fetchLatestBundle(options)
|
|
85
121
|
return FetchLatestBundleResult(artifactType: response?.artifactType, bundleId: response?.bundleId, checksum: response?.checksum, customProperties: response?.customProperties, downloadUrl: response?.url, signature: response?.signature)
|
|
@@ -125,6 +161,14 @@ import CommonCrypto
|
|
|
125
161
|
completion(result, nil)
|
|
126
162
|
}
|
|
127
163
|
|
|
164
|
+
/// - Returns: The on-disk URL of a downloaded bundle, or `nil` if the bundle does not exist.
|
|
165
|
+
public func getBundleDirectory(bundleId: String) -> URL? {
|
|
166
|
+
guard hasBundleById(bundleId) else {
|
|
167
|
+
return nil
|
|
168
|
+
}
|
|
169
|
+
return buildBundleURLFor(bundleId: bundleId)
|
|
170
|
+
}
|
|
171
|
+
|
|
128
172
|
@objc public func getCustomId(completion: @escaping (Result?, Error?) -> Void) {
|
|
129
173
|
let customId = preferences.getCustomId()
|
|
130
174
|
|
|
@@ -544,6 +588,9 @@ import CommonCrypto
|
|
|
544
588
|
}
|
|
545
589
|
|
|
546
590
|
private func fetchLatestBundle(_ options: FetchLatestBundleOptions) async throws -> GetLatestBundleResponse? {
|
|
591
|
+
guard let appId = options.getAppId() ?? getAppId(), !appId.isEmpty else {
|
|
592
|
+
throw CustomError.appIdMissing
|
|
593
|
+
}
|
|
547
594
|
let channel = options.getChannel() ?? getChannel()
|
|
548
595
|
var parameters = [String: String]()
|
|
549
596
|
parameters["appVersionCode"] = getVersionCode()
|
|
@@ -555,7 +602,7 @@ import CommonCrypto
|
|
|
555
602
|
parameters["osVersion"] = await UIDevice.current.systemVersion
|
|
556
603
|
parameters["platform"] = "1"
|
|
557
604
|
parameters["pluginVersion"] = LiveUpdatePlugin.version
|
|
558
|
-
var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(
|
|
605
|
+
var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(appId)/bundles/latest")!
|
|
559
606
|
urlComponents.queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) }
|
|
560
607
|
let url = try urlComponents.asURL()
|
|
561
608
|
CAPLog.print("[", LiveUpdatePlugin.tag, "] Fetching latest bundle: ", url)
|
|
@@ -604,12 +651,19 @@ import CommonCrypto
|
|
|
604
651
|
if let _ = config.defaultChannel {
|
|
605
652
|
channel = config.defaultChannel
|
|
606
653
|
}
|
|
654
|
+
if let nativeChannel = getNativeChannel() {
|
|
655
|
+
channel = nativeChannel
|
|
656
|
+
}
|
|
607
657
|
if let _ = preferences.getChannel() {
|
|
608
658
|
channel = preferences.getChannel()
|
|
609
659
|
}
|
|
610
660
|
return channel
|
|
611
661
|
}
|
|
612
662
|
|
|
663
|
+
private func getNativeChannel() -> String? {
|
|
664
|
+
return Bundle.main.object(forInfoDictionaryKey: "CapawesomeLiveUpdateDefaultChannel") as? String
|
|
665
|
+
}
|
|
666
|
+
|
|
613
667
|
/// - Returns: The sha256 checksum of the file at the given URL.
|
|
614
668
|
private func getChecksumForFile(url: URL) throws -> String {
|
|
615
669
|
let handle = try FileHandle(forReadingFrom: url)
|
|
@@ -5,6 +5,7 @@ import Alamofire
|
|
|
5
5
|
public class LiveUpdateHttpClient: NSObject {
|
|
6
6
|
|
|
7
7
|
private let config: LiveUpdateConfig
|
|
8
|
+
private var deviceId: String?
|
|
8
9
|
|
|
9
10
|
public static func getChecksumFromResponse(response: HTTPURLResponse) -> String? {
|
|
10
11
|
guard let headers = response.allHeaderFields as? [String: String] else { return nil }
|
|
@@ -20,10 +21,17 @@ public class LiveUpdateHttpClient: NSObject {
|
|
|
20
21
|
self.config = config
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
public func setDeviceId(_ deviceId: String) {
|
|
25
|
+
self.deviceId = deviceId
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
public func download(url: URL, destination: @escaping DownloadRequest.Destination, callback: ((Progress) -> Void)?) async throws -> AFDownloadResponse<Data> {
|
|
24
29
|
var request = URLRequest(url: url)
|
|
25
30
|
request.httpMethod = HTTPMethod.get.rawValue
|
|
26
31
|
request.timeoutInterval = Double(config.httpTimeout) / 1000.0
|
|
32
|
+
if let deviceId = deviceId, !deviceId.isEmpty {
|
|
33
|
+
request.setValue(deviceId, forHTTPHeaderField: "X-Capawesome-Device-Id")
|
|
34
|
+
}
|
|
27
35
|
return try await withCheckedThrowingContinuation { continuation in
|
|
28
36
|
AF.download(request, to: destination).downloadProgress { progress in
|
|
29
37
|
if let callback = callback {
|
|
@@ -39,6 +47,9 @@ public class LiveUpdateHttpClient: NSObject {
|
|
|
39
47
|
var request = URLRequest(url: url)
|
|
40
48
|
request.httpMethod = HTTPMethod.get.rawValue
|
|
41
49
|
request.timeoutInterval = Double(config.httpTimeout) / 1000.0
|
|
50
|
+
if let deviceId = deviceId, !deviceId.isEmpty {
|
|
51
|
+
request.setValue(deviceId, forHTTPHeaderField: "X-Capawesome-Device-Id")
|
|
52
|
+
}
|
|
42
53
|
return try await withCheckedThrowingContinuation { continuation in
|
|
43
54
|
AF.request(request).validate().responseDecodable(of: type) { response in
|
|
44
55
|
continuation.resume(returning: response)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import Capacitor
|
|
3
|
+
#if CAPAWESOME_INCLUDE_IONIC_PROVIDER
|
|
4
|
+
import LiveUpdateProvider
|
|
5
|
+
#endif
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
@@ -8,7 +11,7 @@ import Capacitor
|
|
|
8
11
|
@objc(LiveUpdatePlugin)
|
|
9
12
|
public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
13
|
public static let tag = "LiveUpdate"
|
|
11
|
-
public static let version = "8.
|
|
14
|
+
public static let version = "8.2.0"
|
|
12
15
|
public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
|
|
13
16
|
|
|
14
17
|
public let identifier = "LiveUpdatePlugin"
|
|
@@ -17,6 +20,7 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
17
20
|
CAPPluginMethod(name: "clearBlockedBundles", returnType: CAPPluginReturnPromise),
|
|
18
21
|
CAPPluginMethod(name: "deleteBundle", returnType: CAPPluginReturnPromise),
|
|
19
22
|
CAPPluginMethod(name: "downloadBundle", returnType: CAPPluginReturnPromise),
|
|
23
|
+
CAPPluginMethod(name: "fetchChannels", returnType: CAPPluginReturnPromise),
|
|
20
24
|
CAPPluginMethod(name: "fetchLatestBundle", returnType: CAPPluginReturnPromise),
|
|
21
25
|
CAPPluginMethod(name: "getBlockedBundles", returnType: CAPPluginReturnPromise),
|
|
22
26
|
CAPPluginMethod(name: "getBundles", returnType: CAPPluginReturnPromise),
|
|
@@ -55,6 +59,22 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
55
59
|
// Notify implementation about load
|
|
56
60
|
implementation?.handleLoad()
|
|
57
61
|
|
|
62
|
+
// Register the Ionic Live Update Provider when the optional SDK is linked.
|
|
63
|
+
#if CAPAWESOME_INCLUDE_IONIC_PROVIDER
|
|
64
|
+
if let implementation = implementation {
|
|
65
|
+
do {
|
|
66
|
+
if LiveUpdateProviderRegistry.shared.resolve(LiveUpdateIonicProvider.id) == nil {
|
|
67
|
+
try LiveUpdateProviderRegistry.shared.register(
|
|
68
|
+
LiveUpdateIonicProvider(liveUpdate: implementation)
|
|
69
|
+
)
|
|
70
|
+
CAPLog.print("[", LiveUpdatePlugin.tag, "] Registered Ionic provider '\(LiveUpdateIonicProvider.id)'.")
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
CAPLog.print("[", LiveUpdatePlugin.tag, "] Failed to register Ionic provider: ", error.localizedDescription)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
#endif
|
|
77
|
+
|
|
58
78
|
// Register for app resume notifications
|
|
59
79
|
NotificationCenter.default.addObserver(
|
|
60
80
|
self,
|
|
@@ -111,6 +131,25 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
111
131
|
}
|
|
112
132
|
}
|
|
113
133
|
|
|
134
|
+
@objc func fetchChannels(_ call: CAPPluginCall) {
|
|
135
|
+
Task {
|
|
136
|
+
do {
|
|
137
|
+
guard let appId = config?.appId, !appId.isEmpty else {
|
|
138
|
+
call.reject(CustomError.appIdMissing.localizedDescription)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let options = FetchChannelsOptions(call)
|
|
143
|
+
let result = try await implementation?.fetchChannels(options)
|
|
144
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
145
|
+
self.resolveCall(call, result)
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
rejectCall(call, error)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
114
153
|
@objc func fetchLatestBundle(_ call: CAPPluginCall) {
|
|
115
154
|
Task {
|
|
116
155
|
do {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#if CAPAWESOME_INCLUDE_IONIC_PROVIDER
|
|
2
|
+
import Foundation
|
|
3
|
+
import LiveUpdateProvider
|
|
4
|
+
|
|
5
|
+
/// Ionic Live Update Provider manager backed by the Capawesome live update plugin.
|
|
6
|
+
///
|
|
7
|
+
/// Each manager instance is scoped by a `managerKey` so that multiple shells (Portals or
|
|
8
|
+
/// Federated Capacitor apps) can persist their own active bundle without colliding with
|
|
9
|
+
/// each other or with the standalone plugin's `currentBundleId` / `nextBundleId` state.
|
|
10
|
+
///
|
|
11
|
+
/// Provider config keys (V1):
|
|
12
|
+
/// - `managerKey` (required) — scopes per-manager persisted state
|
|
13
|
+
/// - `appId` (optional) — Capawesome Cloud app UUID; falls back to plugin config
|
|
14
|
+
/// - `channel` (optional) — channel to sync; falls back to plugin config
|
|
15
|
+
public final class LiveUpdateIonicManager: LiveUpdateManaging {
|
|
16
|
+
private static let userDefaultsPrefix = "CapawesomeLiveUpdateIonicProvider.lastSyncedBundleId."
|
|
17
|
+
|
|
18
|
+
private let appId: String?
|
|
19
|
+
private let channel: String?
|
|
20
|
+
private let liveUpdate: LiveUpdate
|
|
21
|
+
private let managerKey: String
|
|
22
|
+
|
|
23
|
+
public private(set) var latestAppDirectory: URL?
|
|
24
|
+
|
|
25
|
+
public init(config: [String: Any], liveUpdate: LiveUpdate) throws {
|
|
26
|
+
guard let managerKey = config["managerKey"] as? String, !managerKey.isEmpty else {
|
|
27
|
+
throw LiveUpdateProviderError.invalidConfiguration(
|
|
28
|
+
CustomError.managerKeyMissing.localizedDescription,
|
|
29
|
+
underlyingError: nil
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
self.managerKey = managerKey
|
|
33
|
+
self.appId = config["appId"] as? String
|
|
34
|
+
self.channel = config["channel"] as? String
|
|
35
|
+
self.liveUpdate = liveUpdate
|
|
36
|
+
|
|
37
|
+
// Restore the last synced bundle directory, if any.
|
|
38
|
+
if let persistedBundleId = UserDefaults.standard.string(forKey: lastSyncedBundleIdKey()) {
|
|
39
|
+
self.latestAppDirectory = liveUpdate.getBundleDirectory(bundleId: persistedBundleId)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public func sync() async throws -> any LiveUpdateProvider.SyncResult {
|
|
44
|
+
do {
|
|
45
|
+
let fetchOptions = FetchLatestBundleOptions(appId: appId, channel: channel)
|
|
46
|
+
let result = try await liveUpdate.fetchLatestBundle(fetchOptions)
|
|
47
|
+
|
|
48
|
+
guard let bundleId = result.getBundleId() else {
|
|
49
|
+
// No update available; report success without changing state.
|
|
50
|
+
return DefaultFederatedCapacitorSyncResult(metadata: buildMetadata(bundleId: nil, customProperties: nil))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Bundle already on disk — just point latestAppDirectory at it and persist.
|
|
54
|
+
if let existingDirectory = liveUpdate.getBundleDirectory(bundleId: bundleId) {
|
|
55
|
+
applySyncedBundle(bundleId: bundleId, directory: existingDirectory)
|
|
56
|
+
return DefaultFederatedCapacitorSyncResult(
|
|
57
|
+
metadata: buildMetadata(bundleId: bundleId, customProperties: result.getCustomProperties())
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Otherwise, download and then apply.
|
|
62
|
+
guard let downloadUrl = result.getDownloadUrl(), !downloadUrl.isEmpty else {
|
|
63
|
+
throw LiveUpdateProviderError.syncFailed(
|
|
64
|
+
CustomError.downloadUrlMissing.localizedDescription,
|
|
65
|
+
underlyingError: nil
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
let artifactType = result.getArtifactType() ?? "zip"
|
|
69
|
+
let downloadOptions = DownloadBundleOptions(
|
|
70
|
+
artifactType: artifactType,
|
|
71
|
+
bundleId: bundleId,
|
|
72
|
+
checksum: result.getChecksum(),
|
|
73
|
+
signature: result.getSignature(),
|
|
74
|
+
url: downloadUrl
|
|
75
|
+
)
|
|
76
|
+
try await liveUpdate.downloadBundle(downloadOptions)
|
|
77
|
+
|
|
78
|
+
guard let downloadedDirectory = liveUpdate.getBundleDirectory(bundleId: bundleId) else {
|
|
79
|
+
throw LiveUpdateProviderError.syncFailed(
|
|
80
|
+
CustomError.bundleDirectoryNotFound.localizedDescription,
|
|
81
|
+
underlyingError: nil
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
applySyncedBundle(bundleId: bundleId, directory: downloadedDirectory)
|
|
85
|
+
return DefaultFederatedCapacitorSyncResult(
|
|
86
|
+
metadata: buildMetadata(bundleId: bundleId, customProperties: result.getCustomProperties())
|
|
87
|
+
)
|
|
88
|
+
} catch let error as LiveUpdateProviderError {
|
|
89
|
+
throw error
|
|
90
|
+
} catch {
|
|
91
|
+
throw LiveUpdateProviderError.syncFailed(error.localizedDescription, underlyingError: error)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private func applySyncedBundle(bundleId: String, directory: URL) {
|
|
96
|
+
latestAppDirectory = directory
|
|
97
|
+
UserDefaults.standard.set(bundleId, forKey: lastSyncedBundleIdKey())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private func buildMetadata(bundleId: String?, customProperties: [String: Any]?) -> [String: Any]? {
|
|
101
|
+
var metadata: [String: Any] = [:]
|
|
102
|
+
if let bundleId = bundleId {
|
|
103
|
+
metadata["bundleId"] = bundleId
|
|
104
|
+
}
|
|
105
|
+
if let channel = channel {
|
|
106
|
+
metadata["channel"] = channel
|
|
107
|
+
}
|
|
108
|
+
if let customProperties = customProperties, !customProperties.isEmpty {
|
|
109
|
+
metadata["customProperties"] = customProperties
|
|
110
|
+
}
|
|
111
|
+
return metadata.isEmpty ? nil : metadata
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private func lastSyncedBundleIdKey() -> String {
|
|
115
|
+
return Self.userDefaultsPrefix + managerKey
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
#endif
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#if CAPAWESOME_INCLUDE_IONIC_PROVIDER
|
|
2
|
+
import Foundation
|
|
3
|
+
import LiveUpdateProvider
|
|
4
|
+
|
|
5
|
+
/// Ionic Live Update Provider implementation backed by the Capawesome live update plugin.
|
|
6
|
+
///
|
|
7
|
+
/// Registered with `LiveUpdateProviderRegistry.shared` when the Capacitor plugin loads, so
|
|
8
|
+
/// Federated Capacitor can resolve provider id `"capawesome"` and create managers from the
|
|
9
|
+
/// per-shell configuration.
|
|
10
|
+
public struct LiveUpdateIonicProvider: LiveUpdateProviding {
|
|
11
|
+
public static let id = "capawesome"
|
|
12
|
+
|
|
13
|
+
public let id: String = LiveUpdateIonicProvider.id
|
|
14
|
+
|
|
15
|
+
private let liveUpdate: LiveUpdate
|
|
16
|
+
|
|
17
|
+
public init(liveUpdate: LiveUpdate) {
|
|
18
|
+
self.liveUpdate = liveUpdate
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public func createManager(config: [String: Any]) throws -> any LiveUpdateManaging {
|
|
22
|
+
return try LiveUpdateIonicManager(config: config, liveUpdate: liveUpdate)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
#endif
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-live-update",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.2.1-dev.70823ec8.1778138208",
|
|
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",
|
|
@@ -71,7 +71,6 @@
|
|
|
71
71
|
"@capacitor/docgen": "0.3.1",
|
|
72
72
|
"@capacitor/ios": "8.0.0",
|
|
73
73
|
"@ionic/eslint-config": "0.4.0",
|
|
74
|
-
"@ionic/swiftlint-config": "2.0.0",
|
|
75
74
|
"eslint": "8.57.0",
|
|
76
75
|
"prettier": "3.4.2",
|
|
77
76
|
"prettier-plugin-java": "2.6.7",
|
|
@@ -83,7 +82,6 @@
|
|
|
83
82
|
"peerDependencies": {
|
|
84
83
|
"@capacitor/core": ">=8.0.0"
|
|
85
84
|
},
|
|
86
|
-
"swiftlint": "@ionic/swiftlint-config",
|
|
87
85
|
"eslintConfig": {
|
|
88
86
|
"extends": "@ionic/eslint-config/recommended"
|
|
89
87
|
},
|