@otakit/capacitor-updater 2.1.0 → 2.1.1

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.
@@ -5,7 +5,8 @@ final class BundleStore {
5
5
  static let currentBundleId = "otakit_current_bundle_id"
6
6
  static let fallbackBundleId = "otakit_fallback_bundle_id"
7
7
  static let stagedBundleId = "otakit_staged_bundle_id"
8
- static let failedBundleInfo = "otakit_failed_bundle_info"
8
+ static let lastFailedBundleInfo = "otakit_last_failed_bundle_info"
9
+ static let lastResolvedRuntimeKey = "otakit_last_resolved_runtime_key"
9
10
  }
10
11
 
11
12
  private let defaults = UserDefaults.standard
@@ -142,6 +143,10 @@ final class BundleStore {
142
143
  return bundle
143
144
  }
144
145
 
146
+ func getCurrentBundleId() -> String? {
147
+ defaults.string(forKey: Keys.currentBundleId)
148
+ }
149
+
145
150
  func setCurrentBundleId(_ id: String?) {
146
151
  if let id {
147
152
  defaults.set(id, forKey: Keys.currentBundleId)
@@ -160,6 +165,10 @@ final class BundleStore {
160
165
  return bundle
161
166
  }
162
167
 
168
+ func getFallbackBundleId() -> String? {
169
+ defaults.string(forKey: Keys.fallbackBundleId)
170
+ }
171
+
163
172
  func setFallbackBundleId(_ id: String?) {
164
173
  if let id {
165
174
  defaults.set(id, forKey: Keys.fallbackBundleId)
@@ -180,23 +189,36 @@ final class BundleStore {
180
189
  }
181
190
  }
182
191
 
183
- func setFailedBundle(_ bundle: BundleInfo?) {
192
+ func setLastFailedBundle(_ bundle: BundleInfo?) {
184
193
  if let bundle {
185
194
  if let data = try? encoder.encode(bundle) {
186
- defaults.set(data, forKey: Keys.failedBundleInfo)
195
+ defaults.set(data, forKey: Keys.lastFailedBundleInfo)
187
196
  }
188
197
  } else {
189
- defaults.removeObject(forKey: Keys.failedBundleInfo)
198
+ defaults.removeObject(forKey: Keys.lastFailedBundleInfo)
190
199
  }
191
200
  }
192
201
 
193
- func getFailedBundle() -> BundleInfo? {
194
- guard let data = defaults.data(forKey: Keys.failedBundleInfo) else {
202
+ func getLastFailedBundle() -> BundleInfo? {
203
+ guard let data = defaults.data(forKey: Keys.lastFailedBundleInfo) else {
195
204
  return nil
196
205
  }
197
206
  return try? decoder.decode(BundleInfo.self, from: data)
198
207
  }
199
208
 
209
+ func getLastResolvedRuntimeKey() -> String? {
210
+ defaults.string(forKey: Keys.lastResolvedRuntimeKey)
211
+ }
212
+
213
+ func setLastResolvedRuntimeKey(_ runtimeKey: String?) {
214
+ if let runtimeKey {
215
+ defaults.set(runtimeKey, forKey: Keys.lastResolvedRuntimeKey)
216
+ } else {
217
+ // nil clears the key so the next cold start is treated as unresolved again
218
+ defaults.removeObject(forKey: Keys.lastResolvedRuntimeKey)
219
+ }
220
+ }
221
+
200
222
  func markStatus(bundleId: String, status: BundleStatus) {
201
223
  guard var bundle = getBundle(id: bundleId) else {
202
224
  return
@@ -59,11 +59,15 @@ enum ManifestClient {
59
59
  let runtimeKey = runtimeVersion?.trimmingCharacters(in: .whitespacesAndNewlines).nilIfEmpty
60
60
  ?? defaultRuntimeKey
61
61
 
62
- guard let url = URL(
63
- string: "\(sanitizedBase)/manifests/\(appId)/\(channelKey)/\(runtimeKey)/manifest.json"
64
- ) else {
62
+ guard let baseURL = URL(string: sanitizedBase) else {
65
63
  throw ManifestClientError.invalidURL
66
64
  }
65
+ let url = baseURL
66
+ .appendingPathComponent("manifests", isDirectory: true)
67
+ .appendingPathComponent(appId, isDirectory: true)
68
+ .appendingPathComponent(channelKey, isDirectory: true)
69
+ .appendingPathComponent(runtimeKey, isDirectory: true)
70
+ .appendingPathComponent("manifest.json", isDirectory: false)
67
71
 
68
72
  try requireHTTPS(url: url, allowInsecure: allowInsecureUrls)
69
73