@capgo/capacitor-updater 6.0.2 → 6.0.4

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.2";
58
+ private final String PLUGIN_VERSION = "6.0.4";
59
59
  private static final String DELAY_CONDITION_PREFERENCES = "";
60
60
 
61
61
  private SharedPreferences.Editor editor;
@@ -220,7 +220,6 @@ 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
224
  private let DEFAULT_FOLDER: String = ""
226
225
  private let bundleDirectory: String = "NoCloud/ionic_built_snapshots"
@@ -295,7 +294,8 @@ extension CustomError: LocalizedError {
295
294
  return false
296
295
  #endif
297
296
  }
298
- // Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
297
+ // Persistent path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
298
+ // Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Documents/FOLDER
299
299
  // Normal /private/var/containers/Bundle/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/App.app/public
300
300
 
301
301
  private func prepareFolder(source: URL) throws {
@@ -444,8 +444,8 @@ extension CustomError: LocalizedError {
444
444
 
445
445
  private func saveDownloaded(sourceZip: URL, id: String, base: URL, notify: Bool) throws {
446
446
  try prepareFolder(source: base)
447
- let destHot: URL = base.appendingPathComponent(id)
448
- let destUnZip: URL = documentsDir.appendingPathComponent(randomString(length: 10))
447
+ let destPersist: URL = base.appendingPathComponent(id)
448
+ let destUnZip: URL = libraryDir.appendingPathComponent(randomString(length: 10))
449
449
 
450
450
  self.unzipPercent = 0
451
451
  self.notifyDownload(id, 75)
@@ -481,7 +481,7 @@ extension CustomError: LocalizedError {
481
481
  throw unzipError ?? CustomError.cannotUnzip
482
482
  }
483
483
 
484
- if try unflatFolder(source: destUnZip, dest: destHot) {
484
+ if try unflatFolder(source: destUnZip, dest: destPersist) {
485
485
  try deleteFolder(source: destUnZip)
486
486
  }
487
487
  }
@@ -626,7 +626,7 @@ extension CustomError: LocalizedError {
626
626
  }
627
627
 
628
628
  public func list() -> [BundleInfo] {
629
- let dest: URL = documentsDir.appendingPathComponent(bundleDirectory)
629
+ let dest: URL = libraryDir.appendingPathComponent(bundleDirectory)
630
630
  do {
631
631
  let files: [String] = try FileManager.default.contentsOfDirectory(atPath: dest.path)
632
632
  var res: [BundleInfo] = []
@@ -649,11 +649,11 @@ extension CustomError: LocalizedError {
649
649
  print("\(self.TAG) Cannot delete \(id)")
650
650
  return false
651
651
  }
652
- let destHot: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
652
+ let destPersist: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
653
653
  do {
654
- try FileManager.default.removeItem(atPath: destHot.path)
654
+ try FileManager.default.removeItem(atPath: destPersist.path)
655
655
  } catch {
656
- print("\(self.TAG) Folder \(destHot.path), not removed.")
656
+ print("\(self.TAG) Folder \(destPersist.path), not removed.")
657
657
  return false
658
658
  }
659
659
  if removeInfo {
@@ -679,14 +679,14 @@ extension CustomError: LocalizedError {
679
679
  }
680
680
 
681
681
  private func bundleExists(id: String) -> Bool {
682
- let destHot: URL = self.getBundleDirectory(id: id)
683
- let indexHot: URL = destHot.appendingPathComponent("index.html")
682
+ let destPersist: URL = self.getBundleDirectory(id: id)
683
+ let indexPersist: URL = destPersist.appendingPathComponent("index.html")
684
684
  let bundleIndo: BundleInfo = self.getBundleInfo(id: id)
685
685
  if
686
- destHot.exist &&
687
- destHot.isDirectory &&
688
- !indexHot.isDirectory &&
689
- indexHot.exist &&
686
+ destPersist.exist &&
687
+ destPersist.isDirectory &&
688
+ !indexPersist.isDirectory &&
689
+ indexPersist.exist &&
690
690
  !bundleIndo.isDeleted() {
691
691
  return true
692
692
  }
@@ -739,7 +739,7 @@ extension CustomError: LocalizedError {
739
739
  let fallback: BundleInfo = self.getFallbackBundle()
740
740
  print("\(self.TAG) Fallback bundle is: \(fallback.toString())")
741
741
  print("\(self.TAG) Version successfully loaded: \(bundle.toString())")
742
- if autoDeletePrevious && !fallback.isBuiltin() {
742
+ if autoDeletePrevious && !fallback.isBuiltin() && fallback.getId() != bundle.getId() {
743
743
  let res = self.delete(id: fallback.getId())
744
744
  if res {
745
745
  print("\(self.TAG) Deleted previous bundle: \(fallback.toString())")
@@ -971,7 +971,7 @@ extension CustomError: LocalizedError {
971
971
  guard let bundlePath: String = UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) else {
972
972
  return BundleInfo.ID_BUILTIN
973
973
  }
974
- if (bundlePath ).isEmpty {
974
+ if (bundlePath).isEmpty {
975
975
  return BundleInfo.ID_BUILTIN
976
976
  }
977
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.2"
18
+ private let PLUGIN_VERSION: String = "6.0.4"
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))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "6.0.2",
3
+ "version": "6.0.4",
4
4
  "packageManager": "pnpm@8.15.7",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",