@capawesome/capacitor-live-update 6.7.1 → 6.7.2

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.
@@ -104,6 +104,7 @@ public class LiveUpdate {
104
104
 
105
105
  if (config.getEnabled()) {
106
106
  if (wasUpdated() && config.getResetOnUpdate()) {
107
+ Logger.debug(LiveUpdatePlugin.TAG, "App was updated. Resetting to default bundle.");
107
108
  reset();
108
109
  } else {
109
110
  startRollbackTimer();
@@ -24,7 +24,7 @@ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
24
24
  public class LiveUpdatePlugin extends Plugin {
25
25
 
26
26
  public static final String TAG = "LiveUpdate";
27
- public static final String VERSION = "6.7.1";
27
+ public static final String VERSION = "6.7.2";
28
28
  public static final String SHARED_PREFERENCES_NAME = "CapawesomeLiveUpdate"; // DO NOT CHANGE
29
29
  public static final String ERROR_APP_ID_MISSING = "appId must be configured.";
30
30
  public static final String ERROR_BUNDLE_EXISTS = "bundle already exists.";
@@ -35,11 +35,12 @@ import CommonCrypto
35
35
 
36
36
  if config.enabled {
37
37
  if wasUpdated() && config.resetOnUpdate {
38
+ CAPLog.print("[", LiveUpdatePlugin.tag, "] ", "App was updated. Resetting to default bundle.")
38
39
  reset()
39
40
  } else {
40
41
  startRollbackTimer()
41
42
  }
42
- saveCurrentBundleVersion()
43
+ saveCurrentBundleShortVersionStringAndBundleVersion()
43
44
  }
44
45
  }
45
46
 
@@ -611,10 +612,10 @@ import CommonCrypto
611
612
  setCurrentCapacitorServerPathToDefaultWebAssetDir()
612
613
  }
613
614
 
614
- private func saveCurrentBundleVersion() {
615
- guard let currentBundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String else {
616
- return
617
- }
615
+ private func saveCurrentBundleShortVersionStringAndBundleVersion() {
616
+ let currentBundleShortVersionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
617
+ preferences.setLastBundleShortVersionString(currentBundleShortVersionString)
618
+ let currentBundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String
618
619
  preferences.setLastBundleVersion(currentBundleVersion)
619
620
  }
620
621
 
@@ -786,19 +787,24 @@ import CommonCrypto
786
787
  }
787
788
 
788
789
  private func wasUpdated() -> Bool {
790
+ guard let lastBundleShortVersionString = preferences.getLastBundleShortVersionString() else {
791
+ // If the last bundle short version is not set, the app may have been updated
792
+ return true
793
+ }
789
794
  guard let lastBundleVersionString = preferences.getLastBundleVersion() else {
790
- return false
795
+ // If the last bundle version is not set, the app may have been updated
796
+ return true
791
797
  }
792
- guard let lastBundleVersion = Int(lastBundleVersionString) else {
793
- return false
798
+ guard let currentBundleShortVersionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
799
+ // If the current bundle short version is not set, return true for safety reasons
800
+ return true
794
801
  }
795
802
  guard let currentBundleVersionString = Bundle.main.infoDictionary?["CFBundleVersion"] as? String else {
796
- return false
797
- }
798
- guard let currentBundleVersion = Int(currentBundleVersionString) else {
799
- return false
803
+ // If the current bundle version is not set, return true for safety reasons
804
+ return true
800
805
  }
801
- return currentBundleVersion > lastBundleVersion
806
+ // `CFBundleVersion` is not unique across different versions of the app
807
+ return lastBundleShortVersionString + "_" + lastBundleVersionString != currentBundleShortVersionString + "_" + currentBundleVersionString
802
808
  }
803
809
  }
804
810
 
@@ -8,7 +8,7 @@ import Capacitor
8
8
  @objc(LiveUpdatePlugin)
9
9
  public class LiveUpdatePlugin: CAPPlugin {
10
10
  public static let tag = "LiveUpdate"
11
- public static let version = "6.7.1"
11
+ public static let version = "6.7.2"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
14
  private var config: LiveUpdateConfig?
@@ -3,6 +3,7 @@ import Foundation
3
3
  public class LiveUpdatePreferences: NSObject {
4
4
  private let channelKey = "channel" // DO NOT CHANGE
5
5
  private let customIdKey = "customId" // DO NOT CHANGE
6
+ private let lastBundleShortVersionStringKey = "lastBundleShortVersionString" // DO NOT CHANGE
6
7
  private let lastBundleVersionKey = "lastBundleVersion" // DO NOT CHANGE
7
8
 
8
9
  public func getChannel() -> String? {
@@ -12,6 +13,10 @@ public class LiveUpdatePreferences: NSObject {
12
13
  public func getCustomId() -> String? {
13
14
  return UserDefaults.standard.string(forKey: applyPrefix(to: customIdKey))
14
15
  }
16
+
17
+ public func getLastBundleShortVersionString() -> String? {
18
+ return UserDefaults.standard.string(forKey: applyPrefix(to: lastBundleShortVersionStringKey))
19
+ }
15
20
 
16
21
  public func getLastBundleVersion() -> String? {
17
22
  return UserDefaults.standard.string(forKey: applyPrefix(to: lastBundleVersionKey))
@@ -30,9 +35,22 @@ public class LiveUpdatePreferences: NSObject {
30
35
  UserDefaults.standard.set(value, forKey: applyPrefix(to: customIdKey))
31
36
  UserDefaults.standard.synchronize()
32
37
  }
38
+
39
+ public func setLastBundleShortVersionString(_ value: String?) {
40
+ if let value = value {
41
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: lastBundleShortVersionStringKey))
42
+ } else {
43
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastBundleShortVersionStringKey))
44
+ }
45
+ UserDefaults.standard.synchronize()
46
+ }
33
47
 
34
- public func setLastBundleVersion(_ value: String) {
35
- UserDefaults.standard.set(value, forKey: applyPrefix(to: lastBundleVersionKey))
48
+ public func setLastBundleVersion(_ value: String?) {
49
+ if let value = value {
50
+ UserDefaults.standard.set(value, forKey: applyPrefix(to: lastBundleVersionKey))
51
+ } else {
52
+ UserDefaults.standard.removeObject(forKey: applyPrefix(to: lastBundleVersionKey))
53
+ }
36
54
  UserDefaults.standard.synchronize()
37
55
  }
38
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "6.7.1",
3
+ "version": "6.7.2",
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",