@capgo/capacitor-updater 6.0.3 → 6.0.5
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.
|
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
55
55
|
private static final String channelUrlDefault =
|
|
56
56
|
"https://api.capgo.app/channel_self";
|
|
57
57
|
|
|
58
|
-
private final String PLUGIN_VERSION = "6.0.
|
|
58
|
+
private final String PLUGIN_VERSION = "6.0.5";
|
|
59
59
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
60
|
|
|
61
61
|
private SharedPreferences.Editor editor;
|
|
@@ -220,9 +220,7 @@ extension CustomError: LocalizedError {
|
|
|
220
220
|
|
|
221
221
|
private let versionCode: String = Bundle.main.versionCode ?? ""
|
|
222
222
|
private let versionOs = UIDevice.current.systemVersion
|
|
223
|
-
private let documentsDir: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
|
224
223
|
private let libraryDir: URL = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
|
|
225
|
-
private let bundleDirectoryHot: String = "versions"
|
|
226
224
|
private let DEFAULT_FOLDER: String = ""
|
|
227
225
|
private let bundleDirectory: String = "NoCloud/ionic_built_snapshots"
|
|
228
226
|
private let INFO_SUFFIX: String = "_info"
|
|
@@ -446,8 +444,8 @@ extension CustomError: LocalizedError {
|
|
|
446
444
|
|
|
447
445
|
private func saveDownloaded(sourceZip: URL, id: String, base: URL, notify: Bool) throws {
|
|
448
446
|
try prepareFolder(source: base)
|
|
449
|
-
let
|
|
450
|
-
let destUnZip: URL =
|
|
447
|
+
let destPersist: URL = base.appendingPathComponent(id)
|
|
448
|
+
let destUnZip: URL = libraryDir.appendingPathComponent(randomString(length: 10))
|
|
451
449
|
|
|
452
450
|
self.unzipPercent = 0
|
|
453
451
|
self.notifyDownload(id, 75)
|
|
@@ -483,7 +481,7 @@ extension CustomError: LocalizedError {
|
|
|
483
481
|
throw unzipError ?? CustomError.cannotUnzip
|
|
484
482
|
}
|
|
485
483
|
|
|
486
|
-
if try unflatFolder(source: destUnZip, dest:
|
|
484
|
+
if try unflatFolder(source: destUnZip, dest: destPersist) {
|
|
487
485
|
try deleteFolder(source: destUnZip)
|
|
488
486
|
}
|
|
489
487
|
}
|
|
@@ -584,8 +582,7 @@ extension CustomError: LocalizedError {
|
|
|
584
582
|
do {
|
|
585
583
|
try self.decryptFile(filePath: fileURL, sessionKey: sessionKey, version: version)
|
|
586
584
|
checksum = self.getChecksum(filePath: fileURL)
|
|
587
|
-
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.
|
|
588
|
-
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: false)
|
|
585
|
+
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: true)
|
|
589
586
|
try self.deleteFolder(source: fileURL)
|
|
590
587
|
self.notifyDownload(id, 100)
|
|
591
588
|
} catch {
|
|
@@ -629,7 +626,7 @@ extension CustomError: LocalizedError {
|
|
|
629
626
|
}
|
|
630
627
|
|
|
631
628
|
public func list() -> [BundleInfo] {
|
|
632
|
-
let dest: URL =
|
|
629
|
+
let dest: URL = libraryDir.appendingPathComponent(bundleDirectory)
|
|
633
630
|
do {
|
|
634
631
|
let files: [String] = try FileManager.default.contentsOfDirectory(atPath: dest.path)
|
|
635
632
|
var res: [BundleInfo] = []
|
|
@@ -652,13 +649,7 @@ extension CustomError: LocalizedError {
|
|
|
652
649
|
print("\(self.TAG) Cannot delete \(id)")
|
|
653
650
|
return false
|
|
654
651
|
}
|
|
655
|
-
let destHot: URL = documentsDir.appendingPathComponent(bundleDirectoryHot).appendingPathComponent(id)
|
|
656
652
|
let destPersist: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
|
|
657
|
-
do {
|
|
658
|
-
try FileManager.default.removeItem(atPath: destHot.path)
|
|
659
|
-
} catch {
|
|
660
|
-
print("\(self.TAG) Hot Folder \(destHot.path), not removed.")
|
|
661
|
-
}
|
|
662
653
|
do {
|
|
663
654
|
try FileManager.default.removeItem(atPath: destPersist.path)
|
|
664
655
|
} catch {
|
|
@@ -679,10 +670,6 @@ extension CustomError: LocalizedError {
|
|
|
679
670
|
return self.delete(id: id, removeInfo: true)
|
|
680
671
|
}
|
|
681
672
|
|
|
682
|
-
public func getPathHot(id: String) -> URL {
|
|
683
|
-
return documentsDir.appendingPathComponent(self.bundleDirectoryHot).appendingPathComponent(id)
|
|
684
|
-
}
|
|
685
|
-
|
|
686
673
|
public func getBundleDirectory(id: String) -> URL {
|
|
687
674
|
return libraryDir.appendingPathComponent(self.bundleDirectory).appendingPathComponent(id)
|
|
688
675
|
}
|
|
@@ -692,17 +679,13 @@ extension CustomError: LocalizedError {
|
|
|
692
679
|
}
|
|
693
680
|
|
|
694
681
|
private func bundleExists(id: String) -> Bool {
|
|
695
|
-
let
|
|
696
|
-
let
|
|
697
|
-
let indexHot: URL = destHot.appendingPathComponent("index.html")
|
|
698
|
-
let indexPersist: URL = destHotPersist.appendingPathComponent("index.html")
|
|
682
|
+
let destPersist: URL = self.getBundleDirectory(id: id)
|
|
683
|
+
let indexPersist: URL = destPersist.appendingPathComponent("index.html")
|
|
699
684
|
let bundleIndo: BundleInfo = self.getBundleInfo(id: id)
|
|
700
685
|
if
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
destHotPersist.isDirectory &&
|
|
705
|
-
indexHot.exist &&
|
|
686
|
+
destPersist.exist &&
|
|
687
|
+
destPersist.isDirectory &&
|
|
688
|
+
!indexPersist.isDirectory &&
|
|
706
689
|
indexPersist.exist &&
|
|
707
690
|
!bundleIndo.isDeleted() {
|
|
708
691
|
return true
|
|
@@ -756,7 +739,7 @@ extension CustomError: LocalizedError {
|
|
|
756
739
|
let fallback: BundleInfo = self.getFallbackBundle()
|
|
757
740
|
print("\(self.TAG) Fallback bundle is: \(fallback.toString())")
|
|
758
741
|
print("\(self.TAG) Version successfully loaded: \(bundle.toString())")
|
|
759
|
-
if autoDeletePrevious && !fallback.isBuiltin() {
|
|
742
|
+
if autoDeletePrevious && !fallback.isBuiltin() && fallback.getId() != bundle.getId() {
|
|
760
743
|
let res = self.delete(id: fallback.getId())
|
|
761
744
|
if res {
|
|
762
745
|
print("\(self.TAG) Deleted previous bundle: \(fallback.toString())")
|
|
@@ -988,7 +971,7 @@ extension CustomError: LocalizedError {
|
|
|
988
971
|
guard let bundlePath: String = UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) else {
|
|
989
972
|
return BundleInfo.ID_BUILTIN
|
|
990
973
|
}
|
|
991
|
-
if (bundlePath
|
|
974
|
+
if (bundlePath).isEmpty {
|
|
992
975
|
return BundleInfo.ID_BUILTIN
|
|
993
976
|
}
|
|
994
977
|
let bundleID: String = bundlePath.components(separatedBy: "/").last ?? bundlePath
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
public var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "6.0.
|
|
18
|
+
private let PLUGIN_VERSION: String = "6.0.5"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|
|
@@ -82,6 +82,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
82
82
|
implementation.channelUrl = getConfig().getString("channelUrl", CapacitorUpdaterPlugin.channelUrlDefault)!
|
|
83
83
|
implementation.defaultChannel = getConfig().getString("defaultChannel", "")!
|
|
84
84
|
self.implementation.autoReset()
|
|
85
|
+
|
|
86
|
+
// Load the server
|
|
87
|
+
// This is very much swift specific, android does not do that
|
|
88
|
+
// In android we depend on the serverBasePath capacitor property
|
|
89
|
+
// In IOS we do not. Instead during the plugin initialization we try to call setServerBasePath
|
|
90
|
+
// The idea is to prevent having to store the bundle in 2 locations for hot reload and persisten storage
|
|
91
|
+
// According to martin it is not possible to use serverBasePath on ios in a way that allows us to store the bundle once
|
|
92
|
+
|
|
93
|
+
if !self.initialLoad() {
|
|
94
|
+
print("\(self.implementation.TAG) unable to force reload, the plugin might fallback to the builtin version")
|
|
95
|
+
}
|
|
85
96
|
if resetWhenUpdate {
|
|
86
97
|
self.cleanupObsoleteVersions()
|
|
87
98
|
}
|
|
@@ -93,6 +104,23 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
93
104
|
self.checkForUpdateAfterDelay()
|
|
94
105
|
}
|
|
95
106
|
|
|
107
|
+
private func initialLoad() -> Bool {
|
|
108
|
+
guard let bridge = self.bridge else { return false }
|
|
109
|
+
|
|
110
|
+
let id = self.implementation.getCurrentBundleId()
|
|
111
|
+
let dest: URL
|
|
112
|
+
if BundleInfo.ID_BUILTIN == id {
|
|
113
|
+
dest = Bundle.main.resourceURL!.appendingPathComponent("public")
|
|
114
|
+
} else {
|
|
115
|
+
dest = self.implementation.getBundleDirectory(id: id)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
print("\(self.implementation.TAG) Initial load \(id)")
|
|
119
|
+
// We don't use the viewcontroller here as it does not work during the initial load state
|
|
120
|
+
bridge.setServerBasePath(dest.path)
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
96
124
|
private func semaphoreWait(waitTime: Int) {
|
|
97
125
|
print("\(self.implementation.TAG) semaphoreWait \(waitTime)")
|
|
98
126
|
_ = semaphoreReady.wait(timeout: .now() + .milliseconds(waitTime))
|
|
@@ -247,7 +275,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
247
275
|
if BundleInfo.ID_BUILTIN == id {
|
|
248
276
|
dest = Bundle.main.resourceURL!.appendingPathComponent("public")
|
|
249
277
|
} else {
|
|
250
|
-
dest = self.implementation.
|
|
278
|
+
dest = self.implementation.getBundleDirectory(id: id)
|
|
251
279
|
}
|
|
252
280
|
print("\(self.implementation.TAG) Reloading \(id)")
|
|
253
281
|
if let vc = bridge.viewController as? CAPBridgeViewController {
|