@capgo/capacitor-updater 5.7.4 → 5.7.7
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.
|
@@ -48,6 +48,7 @@ import java.util.ArrayList;
|
|
|
48
48
|
import java.util.Date;
|
|
49
49
|
import java.util.Iterator;
|
|
50
50
|
import java.util.List;
|
|
51
|
+
import java.util.Objects;
|
|
51
52
|
import java.util.zip.CRC32;
|
|
52
53
|
import java.util.zip.ZipEntry;
|
|
53
54
|
import java.util.zip.ZipInputStream;
|
|
@@ -288,11 +289,11 @@ public class CapacitorUpdater {
|
|
|
288
289
|
String action = intent.getAction();
|
|
289
290
|
Bundle bundle = intent.getExtras();
|
|
290
291
|
if (bundle != null) {
|
|
291
|
-
if (action
|
|
292
|
+
if (Objects.equals(action, DownloadService.PERCENTDOWNLOAD)) {
|
|
292
293
|
String id = bundle.getString(DownloadService.ID);
|
|
293
294
|
int percent = bundle.getInt(DownloadService.PERCENT);
|
|
294
295
|
CapacitorUpdater.this.notifyDownload(id, percent);
|
|
295
|
-
} else if (action
|
|
296
|
+
} else if (Objects.equals(action, DownloadService.NOTIFICATION)) {
|
|
296
297
|
String id = bundle.getString(DownloadService.ID);
|
|
297
298
|
String dest = bundle.getString(DownloadService.FILEDEST);
|
|
298
299
|
String version = bundle.getString(DownloadService.VERSION);
|
|
@@ -447,7 +448,7 @@ public class CapacitorUpdater {
|
|
|
447
448
|
final URLConnection connection = u.openConnection();
|
|
448
449
|
|
|
449
450
|
final File target = new File(this.documentsDir, dest);
|
|
450
|
-
target.getParentFile().mkdirs();
|
|
451
|
+
Objects.requireNonNull(target.getParentFile()).mkdirs();
|
|
451
452
|
target.createNewFile();
|
|
452
453
|
|
|
453
454
|
final long totalLength = connection.getContentLength();
|
|
@@ -640,7 +641,7 @@ public class CapacitorUpdater {
|
|
|
640
641
|
final File destHot = new File(this.documentsDir, bundleDirectory);
|
|
641
642
|
Log.d(TAG, "list File : " + destHot.getPath());
|
|
642
643
|
if (destHot.exists()) {
|
|
643
|
-
for (final File i : destHot.listFiles()) {
|
|
644
|
+
for (final File i : Objects.requireNonNull(destHot.listFiles())) {
|
|
644
645
|
final String id = i.getName();
|
|
645
646
|
res.add(this.getBundleInfo(id));
|
|
646
647
|
}
|
|
@@ -872,9 +873,7 @@ public class CapacitorUpdater {
|
|
|
872
873
|
|
|
873
874
|
public void unsetChannel(final Callback callback) {
|
|
874
875
|
String channelUrl = this.channelUrl;
|
|
875
|
-
if (
|
|
876
|
-
channelUrl == null || "".equals(channelUrl) || channelUrl.length() == 0
|
|
877
|
-
) {
|
|
876
|
+
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
878
877
|
Log.e(TAG, "Channel URL is not set");
|
|
879
878
|
final JSObject retError = new JSObject();
|
|
880
879
|
retError.put("message", "channelUrl missing");
|
|
@@ -939,9 +938,7 @@ public class CapacitorUpdater {
|
|
|
939
938
|
|
|
940
939
|
public void setChannel(final String channel, final Callback callback) {
|
|
941
940
|
String channelUrl = this.channelUrl;
|
|
942
|
-
if (
|
|
943
|
-
channelUrl == null || "".equals(channelUrl) || channelUrl.length() == 0
|
|
944
|
-
) {
|
|
941
|
+
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
945
942
|
Log.e(TAG, "Channel URL is not set");
|
|
946
943
|
final JSObject retError = new JSObject();
|
|
947
944
|
retError.put("message", "channelUrl missing");
|
|
@@ -1004,9 +1001,7 @@ public class CapacitorUpdater {
|
|
|
1004
1001
|
|
|
1005
1002
|
public void getChannel(final Callback callback) {
|
|
1006
1003
|
String channelUrl = this.channelUrl;
|
|
1007
|
-
if (
|
|
1008
|
-
channelUrl == null || "".equals(channelUrl) || channelUrl.length() == 0
|
|
1009
|
-
) {
|
|
1004
|
+
if (channelUrl == null || channelUrl.isEmpty()) {
|
|
1010
1005
|
Log.e(TAG, "Channel URL is not set");
|
|
1011
1006
|
final JSObject retError = new JSObject();
|
|
1012
1007
|
retError.put("message", "Channel URL is not set");
|
|
@@ -1068,7 +1063,7 @@ public class CapacitorUpdater {
|
|
|
1068
1063
|
|
|
1069
1064
|
public void sendStats(final String action, final String versionName) {
|
|
1070
1065
|
String statsUrl = this.statsUrl;
|
|
1071
|
-
if (statsUrl == null ||
|
|
1066
|
+
if (statsUrl == null || statsUrl.isEmpty()) {
|
|
1072
1067
|
return;
|
|
1073
1068
|
}
|
|
1074
1069
|
JSONObject json = null;
|
|
@@ -1192,7 +1187,7 @@ public class CapacitorUpdater {
|
|
|
1192
1187
|
|
|
1193
1188
|
public String getCurrentBundlePath() {
|
|
1194
1189
|
String path = this.prefs.getString(WebView.CAP_SERVER_PATH, "public");
|
|
1195
|
-
if (
|
|
1190
|
+
if (path.trim().isEmpty()) {
|
|
1196
1191
|
return "public";
|
|
1197
1192
|
}
|
|
1198
1193
|
return path;
|
|
@@ -8,7 +8,6 @@ package ee.forgr.capacitor_updater;
|
|
|
8
8
|
|
|
9
9
|
import android.app.Activity;
|
|
10
10
|
import android.app.ActivityManager;
|
|
11
|
-
import android.app.Application;
|
|
12
11
|
import android.content.Context;
|
|
13
12
|
import android.content.SharedPreferences;
|
|
14
13
|
import android.content.pm.PackageInfo;
|
|
@@ -36,6 +35,7 @@ import java.util.ArrayList;
|
|
|
36
35
|
import java.util.Date;
|
|
37
36
|
import java.util.Iterator;
|
|
38
37
|
import java.util.List;
|
|
38
|
+
import java.util.Objects;
|
|
39
39
|
import java.util.Timer;
|
|
40
40
|
import java.util.TimerTask;
|
|
41
41
|
import java.util.UUID;
|
|
@@ -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 = "5.7.
|
|
58
|
+
private final String PLUGIN_VERSION = "5.7.7";
|
|
59
59
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
60
|
|
|
61
61
|
private SharedPreferences.Editor editor;
|
|
@@ -70,7 +70,6 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
70
70
|
private Boolean autoUpdate = false;
|
|
71
71
|
private String updateUrl = "";
|
|
72
72
|
private Version currentVersionNative;
|
|
73
|
-
private Boolean resetWhenUpdate = true;
|
|
74
73
|
private Thread backgroundTask;
|
|
75
74
|
private Boolean taskRunning = false;
|
|
76
75
|
|
|
@@ -167,7 +166,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
167
166
|
this.implementation.appId =
|
|
168
167
|
this.getConfig().getString("appId", this.implementation.appId);
|
|
169
168
|
if (
|
|
170
|
-
this.implementation.appId == null ||
|
|
169
|
+
this.implementation.appId == null || this.implementation.appId.isEmpty()
|
|
171
170
|
) {
|
|
172
171
|
// crash the app
|
|
173
172
|
throw new RuntimeException(
|
|
@@ -215,32 +214,29 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
215
214
|
this.appReadyTimeout = this.getConfig().getInt("appReadyTimeout", 10000);
|
|
216
215
|
this.implementation.timeout =
|
|
217
216
|
this.getConfig().getInt("responseTimeout", 20) * 1000;
|
|
218
|
-
|
|
217
|
+
boolean resetWhenUpdate =
|
|
218
|
+
this.getConfig().getBoolean("resetWhenUpdate", true);
|
|
219
219
|
|
|
220
|
-
if (
|
|
220
|
+
if (resetWhenUpdate) {
|
|
221
221
|
this.cleanupObsoleteVersions();
|
|
222
222
|
}
|
|
223
|
-
final Application application = (Application) this.getContext()
|
|
224
|
-
.getApplicationContext();
|
|
225
223
|
|
|
226
224
|
this.checkForUpdateAfterDelay();
|
|
227
|
-
// application.registerActivityLifecycleCallbacks(this);
|
|
228
225
|
}
|
|
229
226
|
|
|
230
227
|
private void semaphoreWait(Number waitTime) {
|
|
231
228
|
Log.i(CapacitorUpdater.TAG, "semaphoreWait " + waitTime);
|
|
232
229
|
try {
|
|
233
230
|
// Log.i(CapacitorUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
semaphoreReady.awaitAdvanceInterruptibly(
|
|
232
|
+
semaphoreReady.getPhase(),
|
|
233
|
+
waitTime.longValue(),
|
|
234
|
+
TimeUnit.SECONDS
|
|
235
|
+
);
|
|
239
236
|
// Log.i(CapacitorUpdater.TAG, "semaphoreReady await " + res);
|
|
240
237
|
Log.i(
|
|
241
238
|
CapacitorUpdater.TAG,
|
|
242
|
-
"semaphoreReady count " +
|
|
243
|
-
CapacitorUpdaterPlugin.this.semaphoreReady.getPhase()
|
|
239
|
+
"semaphoreReady count " + semaphoreReady.getPhase()
|
|
244
240
|
);
|
|
245
241
|
} catch (InterruptedException e) {
|
|
246
242
|
Log.i(CapacitorUpdater.TAG, "semaphoreWait InterruptedException");
|
|
@@ -252,17 +248,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
252
248
|
|
|
253
249
|
private void semaphoreUp() {
|
|
254
250
|
Log.i(CapacitorUpdater.TAG, "semaphoreUp");
|
|
255
|
-
|
|
251
|
+
semaphoreReady.register();
|
|
256
252
|
}
|
|
257
253
|
|
|
258
254
|
private void semaphoreDown() {
|
|
259
255
|
Log.i(CapacitorUpdater.TAG, "semaphoreDown");
|
|
260
256
|
Log.i(
|
|
261
257
|
CapacitorUpdater.TAG,
|
|
262
|
-
"semaphoreDown count " +
|
|
263
|
-
CapacitorUpdaterPlugin.this.semaphoreReady.getPhase()
|
|
258
|
+
"semaphoreDown count " + semaphoreReady.getPhase()
|
|
264
259
|
);
|
|
265
|
-
|
|
260
|
+
semaphoreReady.arriveAndDeregister();
|
|
266
261
|
}
|
|
267
262
|
|
|
268
263
|
private void sendReadyToJs(final BundleInfo current, final String msg) {
|
|
@@ -292,8 +287,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
292
287
|
try {
|
|
293
288
|
if (
|
|
294
289
|
!"".equals(previous.getOriginalString()) &&
|
|
295
|
-
!
|
|
296
|
-
.
|
|
290
|
+
!Objects.equals(
|
|
291
|
+
this.currentVersionNative.getOriginalString(),
|
|
292
|
+
previous.getOriginalString()
|
|
293
|
+
)
|
|
297
294
|
) {
|
|
298
295
|
Log.i(
|
|
299
296
|
CapacitorUpdater.TAG,
|
|
@@ -483,7 +480,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
483
480
|
} else {
|
|
484
481
|
if (
|
|
485
482
|
CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() &&
|
|
486
|
-
triggerAutoUpdate
|
|
483
|
+
Boolean.TRUE.equals(triggerAutoUpdate)
|
|
487
484
|
) {
|
|
488
485
|
Log.i(
|
|
489
486
|
CapacitorUpdater.TAG,
|
|
@@ -528,7 +525,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
528
525
|
} else {
|
|
529
526
|
if (
|
|
530
527
|
CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() &&
|
|
531
|
-
triggerAutoUpdate
|
|
528
|
+
Boolean.TRUE.equals(triggerAutoUpdate)
|
|
532
529
|
) {
|
|
533
530
|
Log.i(
|
|
534
531
|
CapacitorUpdater.TAG,
|
|
@@ -606,7 +603,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
606
603
|
final JSObject ret = new JSObject();
|
|
607
604
|
ret.put("version", version);
|
|
608
605
|
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
609
|
-
|
|
606
|
+
final BundleInfo current =
|
|
607
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
608
|
+
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
609
|
+
"download_fail",
|
|
610
|
+
current.getVersionName()
|
|
611
|
+
);
|
|
610
612
|
}
|
|
611
613
|
});
|
|
612
614
|
} catch (final Exception e) {
|
|
@@ -615,7 +617,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
615
617
|
final JSObject ret = new JSObject();
|
|
616
618
|
ret.put("version", version);
|
|
617
619
|
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
618
|
-
|
|
620
|
+
final BundleInfo current =
|
|
621
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
622
|
+
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
623
|
+
"download_fail",
|
|
624
|
+
current.getVersionName()
|
|
625
|
+
);
|
|
619
626
|
}
|
|
620
627
|
}
|
|
621
628
|
|
|
@@ -822,9 +829,6 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
822
829
|
if (this.periodCheckDelay == 0 || !this._isAutoUpdateEnabled()) {
|
|
823
830
|
return;
|
|
824
831
|
}
|
|
825
|
-
// The delay should be equal to this.periodCheckDelay.
|
|
826
|
-
// In appMovedToForeground we schedule a backgroundDownload and it happens BEFORE this scheduleAtFixedRate
|
|
827
|
-
// As such we get a race condition
|
|
828
832
|
final Timer timer = new Timer();
|
|
829
833
|
timer.scheduleAtFixedRate(
|
|
830
834
|
new TimerTask() {
|
|
@@ -835,14 +839,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
835
839
|
CapacitorUpdaterPlugin.this.updateUrl,
|
|
836
840
|
res -> {
|
|
837
841
|
if (res.has("error")) {
|
|
838
|
-
Log.e(
|
|
842
|
+
Log.e(
|
|
843
|
+
CapacitorUpdater.TAG,
|
|
844
|
+
Objects.requireNonNull(res.getString("error"))
|
|
845
|
+
);
|
|
839
846
|
return;
|
|
840
847
|
} else if (res.has("version")) {
|
|
841
848
|
String newVersion = res.getString("version");
|
|
842
849
|
String currentVersion = String.valueOf(
|
|
843
850
|
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle()
|
|
844
851
|
);
|
|
845
|
-
if (!
|
|
852
|
+
if (!Objects.equals(newVersion, currentVersion)) {
|
|
846
853
|
Log.i(
|
|
847
854
|
CapacitorUpdater.TAG,
|
|
848
855
|
"New version found: " + newVersion
|
|
@@ -857,7 +864,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
857
864
|
}
|
|
858
865
|
}
|
|
859
866
|
},
|
|
860
|
-
|
|
867
|
+
0,
|
|
861
868
|
this.periodCheckDelay
|
|
862
869
|
);
|
|
863
870
|
}
|
|
@@ -967,7 +974,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
967
974
|
for (DelayCondition condition : delayConditionList) {
|
|
968
975
|
String kind = condition.getKind().toString();
|
|
969
976
|
String value = condition.getValue();
|
|
970
|
-
if (!
|
|
977
|
+
if (!kind.isEmpty()) {
|
|
971
978
|
switch (kind) {
|
|
972
979
|
case "background":
|
|
973
980
|
if (!killed) {
|
|
@@ -1020,7 +1027,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1020
1027
|
private Boolean _isAutoUpdateEnabled() {
|
|
1021
1028
|
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
1022
1029
|
String serverUrl = config.getServerUrl();
|
|
1023
|
-
if (serverUrl != null && !
|
|
1030
|
+
if (serverUrl != null && !serverUrl.isEmpty()) {
|
|
1024
1031
|
// log warning autoupdate disabled when serverUrl is set
|
|
1025
1032
|
Log.w(
|
|
1026
1033
|
CapacitorUpdater.TAG,
|
|
@@ -1030,7 +1037,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1030
1037
|
return (
|
|
1031
1038
|
CapacitorUpdaterPlugin.this.autoUpdate &&
|
|
1032
1039
|
!"".equals(CapacitorUpdaterPlugin.this.updateUrl) &&
|
|
1033
|
-
(serverUrl == null ||
|
|
1040
|
+
(serverUrl == null || serverUrl.isEmpty())
|
|
1034
1041
|
);
|
|
1035
1042
|
}
|
|
1036
1043
|
|
|
@@ -1077,7 +1084,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1077
1084
|
Boolean error
|
|
1078
1085
|
) {
|
|
1079
1086
|
if (error) {
|
|
1080
|
-
Log.i(
|
|
1087
|
+
Log.i(
|
|
1088
|
+
CapacitorUpdater.TAG,
|
|
1089
|
+
"endBackGroundTaskWithNotif error" + error.toString()
|
|
1090
|
+
);
|
|
1081
1091
|
this.implementation.sendStats("download_fail", current.getVersionName());
|
|
1082
1092
|
final JSObject ret = new JSObject();
|
|
1083
1093
|
ret.put("version", latestVersionName);
|
|
@@ -1149,7 +1159,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1149
1159
|
|
|
1150
1160
|
if (
|
|
1151
1161
|
latestVersionName != null &&
|
|
1152
|
-
!
|
|
1162
|
+
!latestVersionName.isEmpty() &&
|
|
1153
1163
|
!current.getVersionName().equals(latestVersionName)
|
|
1154
1164
|
) {
|
|
1155
1165
|
final BundleInfo latest =
|
|
@@ -1308,7 +1318,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1308
1318
|
delayUpdatePreferences,
|
|
1309
1319
|
type
|
|
1310
1320
|
);
|
|
1311
|
-
if (delayConditionList != null && delayConditionList.
|
|
1321
|
+
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1312
1322
|
Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
|
|
1313
1323
|
return;
|
|
1314
1324
|
}
|
|
@@ -1442,8 +1452,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1442
1452
|
}
|
|
1443
1453
|
|
|
1444
1454
|
public void appMovedToBackground() {
|
|
1455
|
+
final BundleInfo current =
|
|
1456
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1445
1457
|
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
1446
|
-
"app_moved_to_background"
|
|
1458
|
+
"app_moved_to_background",
|
|
1459
|
+
current.getVersionName()
|
|
1447
1460
|
);
|
|
1448
1461
|
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
1449
1462
|
try {
|
|
@@ -1504,10 +1517,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1504
1517
|
ActivityManager.RecentTaskInfo runningTask = runningTasks
|
|
1505
1518
|
.get(0)
|
|
1506
1519
|
.getTaskInfo();
|
|
1507
|
-
String className =
|
|
1520
|
+
String className = Objects
|
|
1521
|
+
.requireNonNull(runningTask.baseIntent.getComponent())
|
|
1522
|
+
.getClassName();
|
|
1523
|
+
assert runningTask.topActivity != null;
|
|
1508
1524
|
String runningActivity = runningTask.topActivity.getClassName();
|
|
1509
|
-
|
|
1510
|
-
return isThisAppActivity;
|
|
1525
|
+
return className.equals(runningActivity);
|
|
1511
1526
|
} catch (NullPointerException e) {
|
|
1512
1527
|
return false;
|
|
1513
1528
|
}
|
|
@@ -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 = "5.7.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.7.7"
|
|
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"
|