@capgo/capacitor-updater 7.9.0 → 7.9.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.
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +3 -3
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +17 -8
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +10 -3
- package/package.json +1 -1
|
@@ -59,7 +59,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
59
59
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
60
60
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
61
61
|
|
|
62
|
-
private final String PLUGIN_VERSION = "7.9.
|
|
62
|
+
private final String PLUGIN_VERSION = "7.9.1";
|
|
63
63
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
64
64
|
|
|
65
65
|
private SharedPreferences.Editor editor;
|
|
@@ -233,7 +233,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
233
233
|
this.implementation.versionOs = Build.VERSION.RELEASE;
|
|
234
234
|
this.implementation.deviceID = this.prefs.getString("appUUID", UUID.randomUUID().toString()).toLowerCase();
|
|
235
235
|
this.editor.putString("appUUID", this.implementation.deviceID);
|
|
236
|
-
this.editor.
|
|
236
|
+
this.editor.apply();
|
|
237
237
|
logger.info("init for device " + this.implementation.deviceID);
|
|
238
238
|
logger.info("version native " + this.currentVersionNative.getOriginalString());
|
|
239
239
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
@@ -455,7 +455,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
455
455
|
logger.error("Error calculating previous native version " + e.getMessage());
|
|
456
456
|
}
|
|
457
457
|
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
458
|
-
this.editor.
|
|
458
|
+
this.editor.apply();
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
public void notifyDownload(final String id, final int percent) {
|
|
@@ -486,14 +486,14 @@ public class DownloadService extends Worker {
|
|
|
486
486
|
|
|
487
487
|
private String calculateFileHash(File file) throws Exception {
|
|
488
488
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
|
489
|
-
FileInputStream fis = new FileInputStream(file);
|
|
490
489
|
byte[] byteArray = new byte[1024];
|
|
491
490
|
int bytesCount = 0;
|
|
492
491
|
|
|
493
|
-
|
|
494
|
-
|
|
492
|
+
try (FileInputStream fis = new FileInputStream(file)) {
|
|
493
|
+
while ((bytesCount = fis.read(byteArray)) != -1) {
|
|
494
|
+
digest.update(byteArray, 0, bytesCount);
|
|
495
|
+
}
|
|
495
496
|
}
|
|
496
|
-
fis.close();
|
|
497
497
|
|
|
498
498
|
byte[] bytes = digest.digest();
|
|
499
499
|
StringBuilder sb = new StringBuilder();
|
|
@@ -23,6 +23,7 @@ public class DownloadWorkerManager {
|
|
|
23
23
|
|
|
24
24
|
private static volatile boolean isInitialized = false;
|
|
25
25
|
private static final Set<String> activeVersions = new HashSet<>();
|
|
26
|
+
private static final Object activeVersionsLock = new Object();
|
|
26
27
|
|
|
27
28
|
private static synchronized void initializeIfNeeded(Context context) {
|
|
28
29
|
if (!isInitialized) {
|
|
@@ -36,8 +37,10 @@ public class DownloadWorkerManager {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
public static
|
|
40
|
-
|
|
40
|
+
public static boolean isVersionDownloading(String version) {
|
|
41
|
+
synchronized (activeVersionsLock) {
|
|
42
|
+
return activeVersions.contains(version);
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
public static void enqueueDownload(
|
|
@@ -58,11 +61,13 @@ public class DownloadWorkerManager {
|
|
|
58
61
|
initializeIfNeeded(context.getApplicationContext());
|
|
59
62
|
|
|
60
63
|
// If version is already downloading, don't start another one
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
synchronized (activeVersionsLock) {
|
|
65
|
+
if (activeVersions.contains(version)) {
|
|
66
|
+
logger.info("Version " + version + " is already downloading");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
activeVersions.add(version);
|
|
64
70
|
}
|
|
65
|
-
activeVersions.add(version);
|
|
66
71
|
|
|
67
72
|
// Create input data
|
|
68
73
|
Data inputData = new Data.Builder()
|
|
@@ -114,12 +119,16 @@ public class DownloadWorkerManager {
|
|
|
114
119
|
public static void cancelVersionDownload(Context context, String version) {
|
|
115
120
|
initializeIfNeeded(context.getApplicationContext());
|
|
116
121
|
WorkManager.getInstance(context).cancelAllWorkByTag(version);
|
|
117
|
-
|
|
122
|
+
synchronized (activeVersionsLock) {
|
|
123
|
+
activeVersions.remove(version);
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
public static void cancelAllDownloads(Context context) {
|
|
121
128
|
initializeIfNeeded(context.getApplicationContext());
|
|
122
129
|
WorkManager.getInstance(context).cancelAllWorkByTag("capacitor_updater_download");
|
|
123
|
-
|
|
130
|
+
synchronized (activeVersionsLock) {
|
|
131
|
+
activeVersions.clear();
|
|
132
|
+
}
|
|
124
133
|
}
|
|
125
134
|
}
|
|
@@ -86,7 +86,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
86
86
|
CAPPluginMethod(name: "isShakeMenuEnabled", returnType: CAPPluginReturnPromise)
|
|
87
87
|
]
|
|
88
88
|
public var implementation = CapgoUpdater()
|
|
89
|
-
private let PLUGIN_VERSION: String = "7.9.
|
|
89
|
+
private let PLUGIN_VERSION: String = "7.9.1"
|
|
90
90
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
91
91
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
92
92
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|
|
@@ -1150,6 +1150,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1150
1150
|
self.checkAppReady()
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
|
+
private var periodicUpdateTimer: Timer?
|
|
1154
|
+
|
|
1153
1155
|
@objc func checkForUpdateAfterDelay() {
|
|
1154
1156
|
if periodCheckDelay == 0 || !self._isAutoUpdateEnabled() {
|
|
1155
1157
|
return
|
|
@@ -1158,7 +1160,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1158
1160
|
logger.error("Error no url or wrong format")
|
|
1159
1161
|
return
|
|
1160
1162
|
}
|
|
1161
|
-
|
|
1163
|
+
|
|
1164
|
+
// Clean up any existing timer
|
|
1165
|
+
periodicUpdateTimer?.invalidate()
|
|
1166
|
+
|
|
1167
|
+
periodicUpdateTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(periodCheckDelay), repeats: true) { [weak self] _ in
|
|
1168
|
+
guard let self = self else { return }
|
|
1162
1169
|
DispatchQueue.global(qos: .background).async {
|
|
1163
1170
|
let res = self.implementation.getLatest(url: url, channel: nil)
|
|
1164
1171
|
let current = self.implementation.getCurrentBundle()
|
|
@@ -1169,7 +1176,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1169
1176
|
}
|
|
1170
1177
|
}
|
|
1171
1178
|
}
|
|
1172
|
-
RunLoop.current.add(
|
|
1179
|
+
RunLoop.current.add(periodicUpdateTimer!, forMode: .default)
|
|
1173
1180
|
}
|
|
1174
1181
|
|
|
1175
1182
|
@objc func appMovedToBackground() {
|