@capgo/capacitor-updater 4.17.37 → 4.17.39
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/LICENCE +367 -159
- package/README.md +13 -13
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +7 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +6 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +6 -0
- package/dist/docs.json +18 -18
- package/dist/esm/definitions.d.ts +13 -13
- package/dist/esm/definitions.js +5 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +4 -4
- package/dist/esm/web.js +11 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +16 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +16 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BundleInfo.swift +16 -10
- package/ios/Plugin/BundleStatus.swift +7 -1
- package/ios/Plugin/CapacitorUpdater.swift +94 -90
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +93 -83
- package/ios/Plugin/CryptoCipher.swift +5 -26
- package/ios/Plugin/DelayCondition.swift +6 -0
- package/ios/Plugin/DelayUntilNext.swift +6 -0
- package/ios/Plugin/UserDefaultsExtension.swift +6 -0
- package/package.json +1 -1
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import Foundation
|
|
2
8
|
|
|
3
9
|
@objc public class BundleInfo: NSObject, Decodable, Encodable {
|
|
4
|
-
public static let
|
|
5
|
-
public static let
|
|
6
|
-
public static let
|
|
10
|
+
public static let ID_BUILTIN: String = "builtin"
|
|
11
|
+
public static let VERSION_UNKNOWN: String = "unknown"
|
|
12
|
+
public static let DOWNLOADED_BUILTIN: String = "1970-01-01T00:00:00.000Z"
|
|
7
13
|
|
|
8
14
|
private let downloaded: String
|
|
9
15
|
private let id: String
|
|
@@ -15,7 +21,7 @@ import Foundation
|
|
|
15
21
|
self.init(id: id, version: version, status: status, downloaded: downloaded.iso8601withFractionalSeconds, checksum: checksum)
|
|
16
22
|
}
|
|
17
23
|
|
|
18
|
-
init(id: String, version: String, status: BundleStatus, downloaded: String = BundleInfo.
|
|
24
|
+
init(id: String, version: String, status: BundleStatus, downloaded: String = BundleInfo.DOWNLOADED_BUILTIN, checksum: String) {
|
|
19
25
|
self.downloaded = downloaded.trim()
|
|
20
26
|
self.id = id
|
|
21
27
|
self.version = version
|
|
@@ -28,11 +34,11 @@ import Foundation
|
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
public func isBuiltin() -> Bool {
|
|
31
|
-
return BundleInfo.
|
|
37
|
+
return BundleInfo.ID_BUILTIN == self.id
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
public func isUnknown() -> Bool {
|
|
35
|
-
return BundleInfo.
|
|
41
|
+
return BundleInfo.VERSION_UNKNOWN == self.id
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
public func isErrorStatus() -> Bool {
|
|
@@ -44,11 +50,11 @@ import Foundation
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
public func isDownloaded() -> Bool {
|
|
47
|
-
return !self.isBuiltin() && self.downloaded != "" && self.downloaded != BundleInfo.
|
|
53
|
+
return !self.isBuiltin() && self.downloaded != "" && self.downloaded != BundleInfo.DOWNLOADED_BUILTIN && !self.isDeleted()
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
public func getDownloaded() -> String {
|
|
51
|
-
return self.isBuiltin() ? BundleInfo.
|
|
57
|
+
return self.isBuiltin() ? BundleInfo.DOWNLOADED_BUILTIN : self.downloaded
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
public func getChecksum() -> String {
|
|
@@ -64,7 +70,7 @@ import Foundation
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
public func getId() -> String {
|
|
67
|
-
return self.isBuiltin() ? BundleInfo.
|
|
73
|
+
return self.isBuiltin() ? BundleInfo.ID_BUILTIN : self.id
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
public func setId(id: String) -> BundleInfo {
|
|
@@ -72,7 +78,7 @@ import Foundation
|
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
public func getVersionName() -> String {
|
|
75
|
-
return (self.version ?? "").isEmpty ? BundleInfo.
|
|
81
|
+
return (self.version ?? "").isEmpty ? BundleInfo.ID_BUILTIN : self.version
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
public func setVersionName(version: String) -> BundleInfo {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import Foundation
|
|
2
8
|
|
|
3
9
|
struct LocalizedString: ExpressibleByStringLiteral, Equatable {
|
|
@@ -21,7 +27,7 @@ struct LocalizedString: ExpressibleByStringLiteral, Equatable {
|
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
func ==
|
|
30
|
+
func ==(lhs: LocalizedString, rhs: LocalizedString) -> Bool {
|
|
25
31
|
return lhs.v == rhs.v
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
import Foundation
|
|
2
8
|
import SSZipArchive
|
|
3
9
|
import Alamofire
|
|
@@ -66,16 +72,16 @@ extension GetChannel {
|
|
|
66
72
|
}
|
|
67
73
|
struct InfoObject: Codable {
|
|
68
74
|
let platform: String?
|
|
69
|
-
let
|
|
70
|
-
let
|
|
71
|
-
let
|
|
72
|
-
let
|
|
73
|
-
let
|
|
74
|
-
let
|
|
75
|
-
let
|
|
76
|
-
let
|
|
77
|
-
let
|
|
78
|
-
let
|
|
75
|
+
let device_id: String?
|
|
76
|
+
let app_id: String?
|
|
77
|
+
let custom_id: String?
|
|
78
|
+
let version_build: String?
|
|
79
|
+
let version_code: String?
|
|
80
|
+
let version_os: String?
|
|
81
|
+
let version_name: String?
|
|
82
|
+
let plugin_version: String?
|
|
83
|
+
let is_emulator: Bool?
|
|
84
|
+
let is_prod: Bool?
|
|
79
85
|
var action: String?
|
|
80
86
|
var channel: String?
|
|
81
87
|
}
|
|
@@ -85,7 +91,7 @@ struct AppVersionDec: Decodable {
|
|
|
85
91
|
let url: String?
|
|
86
92
|
let message: String?
|
|
87
93
|
let error: String?
|
|
88
|
-
let
|
|
94
|
+
let session_key: String?
|
|
89
95
|
let major: Bool?
|
|
90
96
|
}
|
|
91
97
|
public class AppVersion: NSObject {
|
|
@@ -171,7 +177,6 @@ enum CustomError: Error {
|
|
|
171
177
|
|
|
172
178
|
extension CustomError: LocalizedError {
|
|
173
179
|
public var errorDescription: String? {
|
|
174
|
-
let invalidFolder: String = "Invalid folder"
|
|
175
180
|
switch self {
|
|
176
181
|
case .cannotUnzip:
|
|
177
182
|
return NSLocalizedString(
|
|
@@ -181,17 +186,17 @@ extension CustomError: LocalizedError {
|
|
|
181
186
|
case .cannotCreateDirectory:
|
|
182
187
|
return NSLocalizedString(
|
|
183
188
|
"The folder cannot be created",
|
|
184
|
-
comment:
|
|
189
|
+
comment: "Invalid folder"
|
|
185
190
|
)
|
|
186
191
|
case .cannotDeleteDirectory:
|
|
187
192
|
return NSLocalizedString(
|
|
188
193
|
"The folder cannot be deleted",
|
|
189
|
-
comment:
|
|
194
|
+
comment: "Invalid folder"
|
|
190
195
|
)
|
|
191
196
|
case .cannotUnflat:
|
|
192
197
|
return NSLocalizedString(
|
|
193
198
|
"The file cannot be unflat",
|
|
194
|
-
comment:
|
|
199
|
+
comment: "Invalid folder"
|
|
195
200
|
)
|
|
196
201
|
case .unexpected:
|
|
197
202
|
return NSLocalizedString(
|
|
@@ -220,23 +225,22 @@ extension CustomError: LocalizedError {
|
|
|
220
225
|
private let documentsDir: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
|
221
226
|
private let libraryDir: URL = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
|
|
222
227
|
private let bundleDirectoryHot: String = "versions"
|
|
223
|
-
private let
|
|
228
|
+
private let DEFAULT_FOLDER: String = ""
|
|
224
229
|
private let bundleDirectory: String = "NoCloud/ionic_built_snapshots"
|
|
225
|
-
private let
|
|
226
|
-
private let
|
|
227
|
-
private let
|
|
230
|
+
private let INFO_SUFFIX: String = "_info"
|
|
231
|
+
private let FALLBACK_VERSION: String = "pastVersion"
|
|
232
|
+
private let NEXT_VERSION: String = "nextVersion"
|
|
228
233
|
|
|
229
|
-
public let
|
|
230
|
-
public let
|
|
234
|
+
public let TAG: String = "✨ Capacitor-updater:"
|
|
235
|
+
public let CAP_SERVER_PATH: String = "serverBasePath"
|
|
231
236
|
public var customId: String = ""
|
|
232
|
-
public var
|
|
237
|
+
public var PLUGIN_VERSION: String = ""
|
|
233
238
|
public let timeout: Double = 20
|
|
234
239
|
public var statsUrl: String = ""
|
|
235
240
|
public var channelUrl: String = ""
|
|
236
241
|
public var appId: String = ""
|
|
237
242
|
public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
|
238
243
|
public var privateKey: String = ""
|
|
239
|
-
private let indexHTML: String = "index.html"
|
|
240
244
|
|
|
241
245
|
public var notifyDownload: (String, Int) -> Void = { _, _ in }
|
|
242
246
|
|
|
@@ -292,7 +296,7 @@ extension CustomError: LocalizedError {
|
|
|
292
296
|
do {
|
|
293
297
|
try FileManager.default.createDirectory(atPath: source.path, withIntermediateDirectories: true, attributes: nil)
|
|
294
298
|
} catch {
|
|
295
|
-
print("\(self.
|
|
299
|
+
print("\(self.TAG) Cannot createDirectory \(source.path)")
|
|
296
300
|
throw CustomError.cannotCreateDirectory
|
|
297
301
|
}
|
|
298
302
|
}
|
|
@@ -302,13 +306,13 @@ extension CustomError: LocalizedError {
|
|
|
302
306
|
do {
|
|
303
307
|
try FileManager.default.removeItem(atPath: source.path)
|
|
304
308
|
} catch {
|
|
305
|
-
print("\(self.
|
|
309
|
+
print("\(self.TAG) File not removed. \(source.path)")
|
|
306
310
|
throw CustomError.cannotDeleteDirectory
|
|
307
311
|
}
|
|
308
312
|
}
|
|
309
313
|
|
|
310
314
|
private func unflatFolder(source: URL, dest: URL) throws -> Bool {
|
|
311
|
-
let index: URL = source.appendingPathComponent(
|
|
315
|
+
let index: URL = source.appendingPathComponent("index.html")
|
|
312
316
|
do {
|
|
313
317
|
let files: [String] = try FileManager.default.contentsOfDirectory(atPath: source.path)
|
|
314
318
|
if files.count == 1 && source.appendingPathComponent(files[0]).isDirectory && !FileManager.default.fileExists(atPath: index.path) {
|
|
@@ -319,7 +323,7 @@ extension CustomError: LocalizedError {
|
|
|
319
323
|
return false
|
|
320
324
|
}
|
|
321
325
|
} catch {
|
|
322
|
-
print("\(self.
|
|
326
|
+
print("\(self.TAG) File not moved. source: \(source.path) dest: \(dest.path)")
|
|
323
327
|
throw CustomError.cannotUnflat
|
|
324
328
|
}
|
|
325
329
|
}
|
|
@@ -330,14 +334,14 @@ extension CustomError: LocalizedError {
|
|
|
330
334
|
let checksum: uLong = fileData.withUnsafeBytes { crc32(0, $0.bindMemory(to: Bytef.self).baseAddress, uInt(fileData.count)) }
|
|
331
335
|
return String(format: "%08X", checksum).lowercased()
|
|
332
336
|
} catch {
|
|
333
|
-
print("\(self.
|
|
337
|
+
print("\(self.TAG) Cannot get checksum: \(filePath.path)", error)
|
|
334
338
|
return ""
|
|
335
339
|
}
|
|
336
340
|
}
|
|
337
341
|
|
|
338
342
|
private func decryptFile(filePath: URL, sessionKey: String) throws {
|
|
339
343
|
if (self.privateKey ?? "").isEmpty || (sessionKey ?? "").isEmpty {
|
|
340
|
-
print("\(self.
|
|
344
|
+
print("\(self.TAG) Cannot found privateKey or sessionKey")
|
|
341
345
|
return
|
|
342
346
|
}
|
|
343
347
|
do {
|
|
@@ -359,7 +363,7 @@ extension CustomError: LocalizedError {
|
|
|
359
363
|
|
|
360
364
|
try decryptedData.write(to: filePath)
|
|
361
365
|
} catch {
|
|
362
|
-
print("\(self.
|
|
366
|
+
print("\(self.TAG) Cannot decode: \(filePath.path)", error)
|
|
363
367
|
throw CustomError.cannotDecode
|
|
364
368
|
}
|
|
365
369
|
}
|
|
@@ -379,16 +383,16 @@ extension CustomError: LocalizedError {
|
|
|
379
383
|
private func createInfoObject() -> InfoObject {
|
|
380
384
|
return InfoObject(
|
|
381
385
|
platform: "ios",
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
386
|
+
device_id: self.deviceID,
|
|
387
|
+
app_id: self.appId,
|
|
388
|
+
custom_id: self.customId,
|
|
389
|
+
version_build: self.versionName,
|
|
390
|
+
version_code: self.versionCode,
|
|
391
|
+
version_os: self.versionOs,
|
|
392
|
+
version_name: self.getCurrentBundle().getVersionName(),
|
|
393
|
+
plugin_version: self.PLUGIN_VERSION,
|
|
394
|
+
is_emulator: self.isEmulator(),
|
|
395
|
+
is_prod: self.isProd(),
|
|
392
396
|
action: nil,
|
|
393
397
|
channel: nil
|
|
394
398
|
)
|
|
@@ -398,7 +402,7 @@ extension CustomError: LocalizedError {
|
|
|
398
402
|
let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
|
|
399
403
|
let latest: AppVersion = AppVersion()
|
|
400
404
|
let parameters: InfoObject = self.createInfoObject()
|
|
401
|
-
print("\(self.
|
|
405
|
+
print("\(self.TAG) Auto-update parameters: \(parameters)")
|
|
402
406
|
let request = AF.request(url, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default, requestModifier: { $0.timeoutInterval = self.timeout })
|
|
403
407
|
|
|
404
408
|
request.validate().responseDecodable(of: AppVersionDec.self) { response in
|
|
@@ -422,11 +426,11 @@ extension CustomError: LocalizedError {
|
|
|
422
426
|
if let message = response.value?.message {
|
|
423
427
|
latest.message = message
|
|
424
428
|
}
|
|
425
|
-
if let sessionKey = response.value?.
|
|
429
|
+
if let sessionKey = response.value?.session_key {
|
|
426
430
|
latest.sessionKey = sessionKey
|
|
427
431
|
}
|
|
428
432
|
case let .failure(error):
|
|
429
|
-
print("\(self.
|
|
433
|
+
print("\(self.TAG) Error getting Latest", response.value ?? "", error )
|
|
430
434
|
latest.message = "Error getting Latest \(String(describing: response.value))"
|
|
431
435
|
latest.error = "response_error"
|
|
432
436
|
}
|
|
@@ -437,9 +441,9 @@ extension CustomError: LocalizedError {
|
|
|
437
441
|
}
|
|
438
442
|
|
|
439
443
|
private func setCurrentBundle(bundle: String) {
|
|
440
|
-
UserDefaults.standard.set(bundle, forKey: self.
|
|
444
|
+
UserDefaults.standard.set(bundle, forKey: self.CAP_SERVER_PATH)
|
|
441
445
|
UserDefaults.standard.synchronize()
|
|
442
|
-
print("\(self.
|
|
446
|
+
print("\(self.TAG) Current bundle set to: \((bundle ?? "").isEmpty ? BundleInfo.ID_BUILTIN : bundle)")
|
|
443
447
|
}
|
|
444
448
|
|
|
445
449
|
public func download(url: URL, version: String, sessionKey: String) throws -> BundleInfo {
|
|
@@ -474,11 +478,11 @@ extension CustomError: LocalizedError {
|
|
|
474
478
|
self.notifyDownload(id, 100)
|
|
475
479
|
try self.deleteFolder(source: fileURL)
|
|
476
480
|
} catch {
|
|
477
|
-
print("\(self.
|
|
481
|
+
print("\(self.TAG) download unzip error", error)
|
|
478
482
|
mainError = error as NSError
|
|
479
483
|
}
|
|
480
484
|
case let .failure(error):
|
|
481
|
-
print("\(self.
|
|
485
|
+
print("\(self.TAG) download error", response.value!, error)
|
|
482
486
|
mainError = error as NSError
|
|
483
487
|
}
|
|
484
488
|
}
|
|
@@ -500,7 +504,7 @@ extension CustomError: LocalizedError {
|
|
|
500
504
|
do {
|
|
501
505
|
let files: [String] = try FileManager.default.contentsOfDirectory(atPath: dest.path)
|
|
502
506
|
var res: [BundleInfo] = []
|
|
503
|
-
print("\(self.
|
|
507
|
+
print("\(self.TAG) list File : \(dest.path)")
|
|
504
508
|
if dest.exist {
|
|
505
509
|
for id: String in files {
|
|
506
510
|
res.append(self.getBundleInfo(id: id))
|
|
@@ -508,7 +512,7 @@ extension CustomError: LocalizedError {
|
|
|
508
512
|
}
|
|
509
513
|
return res
|
|
510
514
|
} catch {
|
|
511
|
-
print("\(self.
|
|
515
|
+
print("\(self.TAG) No version available \(dest.path)")
|
|
512
516
|
return []
|
|
513
517
|
}
|
|
514
518
|
}
|
|
@@ -516,7 +520,7 @@ extension CustomError: LocalizedError {
|
|
|
516
520
|
public func delete(id: String, removeInfo: Bool) -> Bool {
|
|
517
521
|
let deleted: BundleInfo = self.getBundleInfo(id: id)
|
|
518
522
|
if deleted.isBuiltin() || self.getCurrentBundleId() == id {
|
|
519
|
-
print("\(self.
|
|
523
|
+
print("\(self.TAG) Cannot delete \(id)")
|
|
520
524
|
return false
|
|
521
525
|
}
|
|
522
526
|
let destHot: URL = documentsDir.appendingPathComponent(bundleDirectoryHot).appendingPathComponent(id)
|
|
@@ -524,12 +528,12 @@ extension CustomError: LocalizedError {
|
|
|
524
528
|
do {
|
|
525
529
|
try FileManager.default.removeItem(atPath: destHot.path)
|
|
526
530
|
} catch {
|
|
527
|
-
print("\(self.
|
|
531
|
+
print("\(self.TAG) Hot Folder \(destHot.path), not removed.")
|
|
528
532
|
}
|
|
529
533
|
do {
|
|
530
534
|
try FileManager.default.removeItem(atPath: destPersist.path)
|
|
531
535
|
} catch {
|
|
532
|
-
print("\(self.
|
|
536
|
+
print("\(self.TAG) Folder \(destPersist.path), not removed.")
|
|
533
537
|
return false
|
|
534
538
|
}
|
|
535
539
|
if removeInfo {
|
|
@@ -537,7 +541,7 @@ extension CustomError: LocalizedError {
|
|
|
537
541
|
} else {
|
|
538
542
|
self.saveBundleInfo(id: id, bundle: deleted.setStatus(status: BundleStatus.DELETED.localizedString))
|
|
539
543
|
}
|
|
540
|
-
print("\(self.
|
|
544
|
+
print("\(self.TAG) bundle delete \(deleted.getVersionName())")
|
|
541
545
|
self.sendStats(action: "delete", versionName: deleted.getVersionName())
|
|
542
546
|
return true
|
|
543
547
|
}
|
|
@@ -557,8 +561,8 @@ extension CustomError: LocalizedError {
|
|
|
557
561
|
private func bundleExists(id: String) -> Bool {
|
|
558
562
|
let destHot: URL = self.getPathHot(id: id)
|
|
559
563
|
let destHotPersist: URL = self.getPathPersist(id: id)
|
|
560
|
-
let indexHot: URL = destHot.appendingPathComponent(
|
|
561
|
-
let indexPersist: URL = destHotPersist.appendingPathComponent(
|
|
564
|
+
let indexHot: URL = destHot.appendingPathComponent("index.html")
|
|
565
|
+
let indexPersist: URL = destHotPersist.appendingPathComponent("index.html")
|
|
562
566
|
let url: URL = self.getBundleDirectory(id: id)
|
|
563
567
|
let bundleIndo: BundleInfo = self.getBundleInfo(id: id)
|
|
564
568
|
if url.isDirectory && destHotPersist.isDirectory && indexHot.exist && indexPersist.exist && !bundleIndo.isDeleted() {
|
|
@@ -596,7 +600,7 @@ extension CustomError: LocalizedError {
|
|
|
596
600
|
}
|
|
597
601
|
|
|
598
602
|
public func reset(isInternal: Bool) {
|
|
599
|
-
print("\(self.
|
|
603
|
+
print("\(self.TAG) reset: \(isInternal)")
|
|
600
604
|
self.setCurrentBundle(bundle: "")
|
|
601
605
|
self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
|
|
602
606
|
_ = self.setNextBundle(next: Optional<String>.none)
|
|
@@ -608,14 +612,14 @@ extension CustomError: LocalizedError {
|
|
|
608
612
|
public func setSuccess(bundle: BundleInfo, autoDeletePrevious: Bool) {
|
|
609
613
|
self.setBundleStatus(id: bundle.getId(), status: BundleStatus.SUCCESS)
|
|
610
614
|
let fallback: BundleInfo = self.getFallbackBundle()
|
|
611
|
-
print("\(self.
|
|
612
|
-
print("\(self.
|
|
615
|
+
print("\(self.TAG) Fallback bundle is: \(fallback.toString())")
|
|
616
|
+
print("\(self.TAG) Version successfully loaded: \(bundle.toString())")
|
|
613
617
|
if autoDeletePrevious && !fallback.isBuiltin() {
|
|
614
618
|
let res = self.delete(id: fallback.getId())
|
|
615
619
|
if res {
|
|
616
|
-
print("\(self.
|
|
620
|
+
print("\(self.TAG) Deleted previous bundle: \(fallback.toString())")
|
|
617
621
|
} else {
|
|
618
|
-
print("\(self.
|
|
622
|
+
print("\(self.TAG) Failed to delete previous bundle: \(fallback.toString())")
|
|
619
623
|
}
|
|
620
624
|
}
|
|
621
625
|
self.setFallbackBundle(fallback: bundle)
|
|
@@ -628,7 +632,7 @@ extension CustomError: LocalizedError {
|
|
|
628
632
|
func setChannel(channel: String) -> SetChannel {
|
|
629
633
|
let setChannel: SetChannel = SetChannel()
|
|
630
634
|
if (self.channelUrl ?? "").isEmpty {
|
|
631
|
-
print("\(self.
|
|
635
|
+
print("\(self.TAG) Channel URL is not set")
|
|
632
636
|
setChannel.message = "Channel URL is not set"
|
|
633
637
|
setChannel.error = "missing_config"
|
|
634
638
|
return setChannel
|
|
@@ -652,7 +656,7 @@ extension CustomError: LocalizedError {
|
|
|
652
656
|
setChannel.message = message
|
|
653
657
|
}
|
|
654
658
|
case let .failure(error):
|
|
655
|
-
print("\(self.
|
|
659
|
+
print("\(self.TAG) Error set Channel", response.value, error)
|
|
656
660
|
setChannel.message = "Error set Channel \(String(describing: response.value))"
|
|
657
661
|
setChannel.error = "response_error"
|
|
658
662
|
}
|
|
@@ -665,7 +669,7 @@ extension CustomError: LocalizedError {
|
|
|
665
669
|
func getChannel() -> GetChannel {
|
|
666
670
|
let getChannel: GetChannel = GetChannel()
|
|
667
671
|
if (self.channelUrl ?? "").isEmpty {
|
|
668
|
-
print("\(self.
|
|
672
|
+
print("\(self.TAG) Channel URL is not set")
|
|
669
673
|
getChannel.message = "Channel URL is not set"
|
|
670
674
|
getChannel.error = "missing_config"
|
|
671
675
|
return getChannel
|
|
@@ -693,7 +697,7 @@ extension CustomError: LocalizedError {
|
|
|
693
697
|
getChannel.allowSet = allowSet
|
|
694
698
|
}
|
|
695
699
|
case let .failure(error):
|
|
696
|
-
print("\(self.
|
|
700
|
+
print("\(self.TAG) Error get Channel", response.value ?? "", error)
|
|
697
701
|
getChannel.message = "Error get Channel \(String(describing: response.value)))"
|
|
698
702
|
getChannel.error = "response_error"
|
|
699
703
|
}
|
|
@@ -714,34 +718,34 @@ extension CustomError: LocalizedError {
|
|
|
714
718
|
request.responseData { response in
|
|
715
719
|
switch response.result {
|
|
716
720
|
case .success:
|
|
717
|
-
print("\(self.
|
|
721
|
+
print("\(self.TAG) Stats send for \(action), version \(versionName)")
|
|
718
722
|
case let .failure(error):
|
|
719
|
-
print("\(self.
|
|
723
|
+
print("\(self.TAG) Error sending stats: ", response.value, error)
|
|
720
724
|
}
|
|
721
725
|
}
|
|
722
726
|
}
|
|
723
727
|
}
|
|
724
728
|
|
|
725
729
|
public func getBundleInfo(id: String?) -> BundleInfo {
|
|
726
|
-
var trueId = BundleInfo.
|
|
730
|
+
var trueId = BundleInfo.VERSION_UNKNOWN
|
|
727
731
|
if id != nil {
|
|
728
732
|
trueId = id!
|
|
729
733
|
}
|
|
730
|
-
print("\(self.
|
|
734
|
+
print("\(self.TAG) Getting info for bundle [\(trueId)]")
|
|
731
735
|
let result: BundleInfo
|
|
732
|
-
if BundleInfo.
|
|
736
|
+
if BundleInfo.ID_BUILTIN == trueId {
|
|
733
737
|
result = BundleInfo(id: trueId, version: "", status: BundleStatus.SUCCESS, checksum: "")
|
|
734
|
-
} else if BundleInfo.
|
|
738
|
+
} else if BundleInfo.VERSION_UNKNOWN == trueId {
|
|
735
739
|
result = BundleInfo(id: trueId, version: "", status: BundleStatus.ERROR, checksum: "")
|
|
736
740
|
} else {
|
|
737
741
|
do {
|
|
738
|
-
result = try UserDefaults.standard.getObj(forKey: "\(trueId)\(self.
|
|
742
|
+
result = try UserDefaults.standard.getObj(forKey: "\(trueId)\(self.INFO_SUFFIX)", castTo: BundleInfo.self)
|
|
739
743
|
} catch {
|
|
740
|
-
print("\(self.
|
|
744
|
+
print("\(self.TAG) Failed to parse info for bundle [\(trueId)]", error.localizedDescription)
|
|
741
745
|
result = BundleInfo(id: trueId, version: "", status: BundleStatus.PENDING, checksum: "")
|
|
742
746
|
}
|
|
743
747
|
}
|
|
744
|
-
print("\(self.
|
|
748
|
+
print("\(self.TAG) Returning info bundle [\(result.toString())]")
|
|
745
749
|
return result
|
|
746
750
|
}
|
|
747
751
|
|
|
@@ -761,32 +765,32 @@ extension CustomError: LocalizedError {
|
|
|
761
765
|
|
|
762
766
|
private func saveBundleInfo(id: String, bundle: BundleInfo?) {
|
|
763
767
|
if bundle != nil && (bundle!.isBuiltin() || bundle!.isUnknown()) {
|
|
764
|
-
print("\(self.
|
|
768
|
+
print("\(self.TAG) Not saving info for bundle [\(id)]", bundle!.toString())
|
|
765
769
|
return
|
|
766
770
|
}
|
|
767
771
|
if bundle == nil {
|
|
768
|
-
print("\(self.
|
|
769
|
-
UserDefaults.standard.removeObject(forKey: "\(id)\(self.
|
|
772
|
+
print("\(self.TAG) Removing info for bundle [\(id)]")
|
|
773
|
+
UserDefaults.standard.removeObject(forKey: "\(id)\(self.INFO_SUFFIX)")
|
|
770
774
|
} else {
|
|
771
775
|
let update = bundle!.setId(id: id)
|
|
772
|
-
print("\(self.
|
|
776
|
+
print("\(self.TAG) Storing info for bundle [\(id)]", update.toString())
|
|
773
777
|
do {
|
|
774
|
-
try UserDefaults.standard.setObj(update, forKey: "\(id)\(self.
|
|
778
|
+
try UserDefaults.standard.setObj(update, forKey: "\(id)\(self.INFO_SUFFIX)")
|
|
775
779
|
} catch {
|
|
776
|
-
print("\(self.
|
|
780
|
+
print("\(self.TAG) Failed to save info for bundle [\(id)]", error.localizedDescription)
|
|
777
781
|
}
|
|
778
782
|
}
|
|
779
783
|
UserDefaults.standard.synchronize()
|
|
780
784
|
}
|
|
781
785
|
|
|
782
786
|
public func setVersionName(id: String, version: String) {
|
|
783
|
-
print("\(self.
|
|
787
|
+
print("\(self.TAG) Setting version for folder [\(id)] to \(version)")
|
|
784
788
|
let info = self.getBundleInfo(id: id)
|
|
785
789
|
self.saveBundleInfo(id: id, bundle: info.setVersionName(version: version))
|
|
786
790
|
}
|
|
787
791
|
|
|
788
792
|
private func setBundleStatus(id: String, status: BundleStatus) {
|
|
789
|
-
print("\(self.
|
|
793
|
+
print("\(self.TAG) Setting status for bundle [\(id)] to \(status)")
|
|
790
794
|
let info = self.getBundleInfo(id: id)
|
|
791
795
|
self.saveBundleInfo(id: id, bundle: info.setStatus(status: status.localizedString))
|
|
792
796
|
}
|
|
@@ -796,38 +800,38 @@ extension CustomError: LocalizedError {
|
|
|
796
800
|
}
|
|
797
801
|
|
|
798
802
|
public func getCurrentBundleId() -> String {
|
|
799
|
-
guard let bundlePath: String = UserDefaults.standard.string(forKey: self.
|
|
800
|
-
return BundleInfo.
|
|
803
|
+
guard let bundlePath: String = UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) else {
|
|
804
|
+
return BundleInfo.ID_BUILTIN
|
|
801
805
|
}
|
|
802
806
|
if (bundlePath ?? "").isEmpty {
|
|
803
|
-
return BundleInfo.
|
|
807
|
+
return BundleInfo.ID_BUILTIN
|
|
804
808
|
}
|
|
805
809
|
let bundleID: String = bundlePath.components(separatedBy: "/").last ?? bundlePath
|
|
806
810
|
return bundleID
|
|
807
811
|
}
|
|
808
812
|
|
|
809
813
|
public func isUsingBuiltin() -> Bool {
|
|
810
|
-
return (UserDefaults.standard.string(forKey: self.
|
|
814
|
+
return (UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) ?? "") == self.DEFAULT_FOLDER
|
|
811
815
|
}
|
|
812
816
|
|
|
813
817
|
public func getFallbackBundle() -> BundleInfo {
|
|
814
|
-
let id: String = UserDefaults.standard.string(forKey: self.
|
|
818
|
+
let id: String = UserDefaults.standard.string(forKey: self.FALLBACK_VERSION) ?? BundleInfo.ID_BUILTIN
|
|
815
819
|
return self.getBundleInfo(id: id)
|
|
816
820
|
}
|
|
817
821
|
|
|
818
822
|
private func setFallbackBundle(fallback: BundleInfo?) {
|
|
819
|
-
UserDefaults.standard.set(fallback == nil ? BundleInfo.
|
|
823
|
+
UserDefaults.standard.set(fallback == nil ? BundleInfo.ID_BUILTIN : fallback!.getId(), forKey: self.FALLBACK_VERSION)
|
|
820
824
|
UserDefaults.standard.synchronize()
|
|
821
825
|
}
|
|
822
826
|
|
|
823
827
|
public func getNextBundle() -> BundleInfo? {
|
|
824
|
-
let id: String? = UserDefaults.standard.string(forKey: self.
|
|
828
|
+
let id: String? = UserDefaults.standard.string(forKey: self.NEXT_VERSION)
|
|
825
829
|
return self.getBundleInfo(id: id)
|
|
826
830
|
}
|
|
827
831
|
|
|
828
832
|
public func setNextBundle(next: String?) -> Bool {
|
|
829
833
|
guard let nextId: String = next else {
|
|
830
|
-
UserDefaults.standard.removeObject(forKey: self.
|
|
834
|
+
UserDefaults.standard.removeObject(forKey: self.NEXT_VERSION)
|
|
831
835
|
UserDefaults.standard.synchronize()
|
|
832
836
|
return false
|
|
833
837
|
}
|
|
@@ -836,7 +840,7 @@ extension CustomError: LocalizedError {
|
|
|
836
840
|
if !newBundle.isBuiltin() && !bundle.exist {
|
|
837
841
|
return false
|
|
838
842
|
}
|
|
839
|
-
UserDefaults.standard.set(nextId, forKey: self.
|
|
843
|
+
UserDefaults.standard.set(nextId, forKey: self.NEXT_VERSION)
|
|
840
844
|
UserDefaults.standard.synchronize()
|
|
841
845
|
self.setBundleStatus(id: nextId, status: BundleStatus.PENDING)
|
|
842
846
|
return true
|