@capgo/capacitor-updater 5.3.14 → 5.3.21
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/CapacitorUpdater.java +13 -6
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +52 -6
- package/dist/docs.json +12 -0
- package/dist/esm/definitions.d.ts +8 -0
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +19 -1
- package/package.json +5 -5
|
@@ -72,7 +72,6 @@ public class CapacitorUpdater {
|
|
|
72
72
|
private static final String bundleDirectory = "versions";
|
|
73
73
|
|
|
74
74
|
public static final String TAG = "Capacitor-updater";
|
|
75
|
-
|
|
76
75
|
public SharedPreferences.Editor editor;
|
|
77
76
|
public SharedPreferences prefs;
|
|
78
77
|
|
|
@@ -83,6 +82,7 @@ public class CapacitorUpdater {
|
|
|
83
82
|
public Activity activity;
|
|
84
83
|
public String PLUGIN_VERSION = "";
|
|
85
84
|
public String versionBuild = "";
|
|
85
|
+
public int periodCheckDelay = 300000;
|
|
86
86
|
public String versionCode = "";
|
|
87
87
|
public String versionOs = "";
|
|
88
88
|
|
|
@@ -257,11 +257,18 @@ public class CapacitorUpdater {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
public void onResume() {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
261
|
+
this.activity.registerReceiver(
|
|
262
|
+
receiver,
|
|
263
|
+
new IntentFilter(DownloadService.NOTIFICATION),
|
|
264
|
+
RECEIVER_NOT_EXPORTED
|
|
265
|
+
);
|
|
266
|
+
} else {
|
|
267
|
+
this.activity.registerReceiver(
|
|
268
|
+
receiver,
|
|
269
|
+
new IntentFilter(DownloadService.NOTIFICATION)
|
|
270
|
+
);
|
|
271
|
+
}
|
|
265
272
|
}
|
|
266
273
|
|
|
267
274
|
public void onPause() {
|
|
@@ -14,10 +14,8 @@ import android.content.SharedPreferences;
|
|
|
14
14
|
import android.content.pm.PackageInfo;
|
|
15
15
|
import android.content.pm.PackageManager;
|
|
16
16
|
import android.os.Build;
|
|
17
|
-
import android.os.
|
|
17
|
+
import android.os.Handler;
|
|
18
18
|
import android.util.Log;
|
|
19
|
-
import androidx.annotation.NonNull;
|
|
20
|
-
import androidx.annotation.Nullable;
|
|
21
19
|
import com.android.volley.toolbox.Volley;
|
|
22
20
|
import com.getcapacitor.CapConfig;
|
|
23
21
|
import com.getcapacitor.JSArray;
|
|
@@ -39,10 +37,10 @@ import java.util.ArrayList;
|
|
|
39
37
|
import java.util.Date;
|
|
40
38
|
import java.util.Iterator;
|
|
41
39
|
import java.util.List;
|
|
40
|
+
import java.util.Timer;
|
|
41
|
+
import java.util.TimerTask;
|
|
42
42
|
import java.util.UUID;
|
|
43
|
-
import java.util.concurrent.CountDownLatch;
|
|
44
43
|
import java.util.concurrent.Phaser;
|
|
45
|
-
import java.util.concurrent.Semaphore;
|
|
46
44
|
import java.util.concurrent.TimeUnit;
|
|
47
45
|
import java.util.concurrent.TimeoutException;
|
|
48
46
|
import org.json.JSONException;
|
|
@@ -58,7 +56,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
58
56
|
private static final String channelUrlDefault =
|
|
59
57
|
"https://api.capgo.app/channel_self";
|
|
60
58
|
|
|
61
|
-
private final String PLUGIN_VERSION = "5.3.
|
|
59
|
+
private final String PLUGIN_VERSION = "5.3.21";
|
|
62
60
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
61
|
|
|
64
62
|
private SharedPreferences.Editor editor;
|
|
@@ -173,6 +171,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
173
171
|
this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
174
172
|
this.implementation.channelUrl =
|
|
175
173
|
this.getConfig().getString("channelUrl", channelUrlDefault);
|
|
174
|
+
int userValue = this.getConfig().getInt("periodCheckDelay", 600);
|
|
175
|
+
|
|
176
|
+
this.implementation.periodCheckDelay =
|
|
177
|
+
(userValue == 0 ? 600 : userValue) * 1000;
|
|
178
|
+
|
|
176
179
|
this.implementation.documentsDir = this.getContext().getFilesDir();
|
|
177
180
|
this.implementation.prefs = this.prefs;
|
|
178
181
|
this.implementation.editor = this.editor;
|
|
@@ -204,6 +207,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
204
207
|
}
|
|
205
208
|
final Application application = (Application) this.getContext()
|
|
206
209
|
.getApplicationContext();
|
|
210
|
+
|
|
211
|
+
this.checkForUpdateAfterDelay();
|
|
207
212
|
// application.registerActivityLifecycleCallbacks(this);
|
|
208
213
|
}
|
|
209
214
|
|
|
@@ -757,6 +762,44 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
757
762
|
}
|
|
758
763
|
}
|
|
759
764
|
|
|
765
|
+
public void checkForUpdateAfterDelay() {
|
|
766
|
+
final Timer timer = new Timer();
|
|
767
|
+
timer.scheduleAtFixedRate(
|
|
768
|
+
new TimerTask() {
|
|
769
|
+
@Override
|
|
770
|
+
public void run() {
|
|
771
|
+
try {
|
|
772
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(
|
|
773
|
+
CapacitorUpdaterPlugin.this.updateUrl,
|
|
774
|
+
res -> {
|
|
775
|
+
if (res.has("error")) {
|
|
776
|
+
Log.e(CapacitorUpdater.TAG, res.getString("error"));
|
|
777
|
+
return;
|
|
778
|
+
} else if (res.has("version")) {
|
|
779
|
+
String newVersion = res.getString("version");
|
|
780
|
+
String currentVersion = String.valueOf(
|
|
781
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle()
|
|
782
|
+
);
|
|
783
|
+
if (!newVersion.equals(currentVersion)) {
|
|
784
|
+
Log.i(
|
|
785
|
+
CapacitorUpdater.TAG,
|
|
786
|
+
"New version found: " + newVersion
|
|
787
|
+
);
|
|
788
|
+
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
} catch (final Exception e) {
|
|
794
|
+
Log.e(CapacitorUpdater.TAG, "Failed to check for update", e);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
0,
|
|
799
|
+
CapacitorUpdaterPlugin.this.implementation.periodCheckDelay
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
|
|
760
803
|
@PluginMethod
|
|
761
804
|
public void notifyAppReady(final PluginCall call) {
|
|
762
805
|
try {
|
|
@@ -1396,6 +1439,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1396
1439
|
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
|
1397
1440
|
List<ActivityManager.AppTask> runningTasks =
|
|
1398
1441
|
activityManager.getAppTasks();
|
|
1442
|
+
if (runningTasks.isEmpty()) {
|
|
1443
|
+
return false;
|
|
1444
|
+
}
|
|
1399
1445
|
ActivityManager.RecentTaskInfo runningTask = runningTasks
|
|
1400
1446
|
.get(0)
|
|
1401
1447
|
.getTaskInfo();
|
package/dist/docs.json
CHANGED
|
@@ -1651,6 +1651,18 @@
|
|
|
1651
1651
|
"docs": "Make the plugin direct install the update when the app what just updated/installed. Only for autoUpdate mode.\n\nOnly available for Android and iOS.",
|
|
1652
1652
|
"complexTypes": [],
|
|
1653
1653
|
"type": "boolean | undefined"
|
|
1654
|
+
},
|
|
1655
|
+
{
|
|
1656
|
+
"name": "periodCheckDelay",
|
|
1657
|
+
"tags": [
|
|
1658
|
+
{
|
|
1659
|
+
"text": "600 // (10 minutes)",
|
|
1660
|
+
"name": "default"
|
|
1661
|
+
}
|
|
1662
|
+
],
|
|
1663
|
+
"docs": "Configure the delay period for period update check. the unit is in seconds.\n\nOnly available for Android and iOS.",
|
|
1664
|
+
"complexTypes": [],
|
|
1665
|
+
"type": "number | undefined"
|
|
1654
1666
|
}
|
|
1655
1667
|
],
|
|
1656
1668
|
"docs": "These configuration values are available:"
|
|
@@ -104,6 +104,14 @@ declare module "@capacitor/cli" {
|
|
|
104
104
|
* @since 5.1.0
|
|
105
105
|
*/
|
|
106
106
|
directUpdate?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Configure the delay period for period update check. the unit is in seconds.
|
|
109
|
+
*
|
|
110
|
+
* Only available for Android and iOS.
|
|
111
|
+
*
|
|
112
|
+
* @default 600 // (10 minutes)
|
|
113
|
+
*/
|
|
114
|
+
periodCheckDelay?: number;
|
|
107
115
|
};
|
|
108
116
|
}
|
|
109
117
|
}
|
|
@@ -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.3.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.3.21"
|
|
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"
|
|
@@ -34,6 +34,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
34
34
|
private var autoDeletePrevious = false
|
|
35
35
|
private var backgroundWork: DispatchWorkItem?
|
|
36
36
|
private var taskRunning = false
|
|
37
|
+
private var periodCheckDelay = 300
|
|
37
38
|
let semaphoreReady = DispatchSemaphore(value: 0)
|
|
38
39
|
|
|
39
40
|
override public func load() {
|
|
@@ -54,6 +55,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
54
55
|
appReadyTimeout = getConfig().getInt("appReadyTimeout", 10000)
|
|
55
56
|
implementation.timeout = Double(getConfig().getInt("responseTimeout", 20))
|
|
56
57
|
resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", true)
|
|
58
|
+
let periodCheckDelayValue = getConfig().getInt("periodCheckDelay", 600)
|
|
59
|
+
periodCheckDelay = (periodCheckDelayValue == 0) ? 600 : periodCheckDelayValue
|
|
57
60
|
|
|
58
61
|
implementation.privateKey = getConfig().getString("privateKey", self.defaultPrivateKey)!
|
|
59
62
|
implementation.notifyDownload = notifyDownload
|
|
@@ -78,6 +81,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
78
81
|
nc.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
|
|
79
82
|
nc.addObserver(self, selector: #selector(appKilled), name: UIApplication.willTerminateNotification, object: nil)
|
|
80
83
|
self.appMovedToForeground()
|
|
84
|
+
self.checkForUpdateAfterDelay()
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
private func semaphoreWait(waitTime: Int) {
|
|
@@ -722,6 +726,20 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
722
726
|
self.checkAppReady()
|
|
723
727
|
}
|
|
724
728
|
|
|
729
|
+
@objc func checkForUpdateAfterDelay() {
|
|
730
|
+
let timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(periodCheckDelay), repeats: true) { _ in
|
|
731
|
+
let url = URL(string: self.updateUrl)!
|
|
732
|
+
let res = self.implementation.getLatest(url: url)
|
|
733
|
+
let current = self.implementation.getCurrentBundle()
|
|
734
|
+
|
|
735
|
+
if res.version != current.getVersionName() {
|
|
736
|
+
print("\(self.implementation.TAG) New version found: \(res.version)")
|
|
737
|
+
self.backgroundDownload()
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
RunLoop.current.add(timer, forMode: .default)
|
|
741
|
+
}
|
|
742
|
+
|
|
725
743
|
@objc func appMovedToBackground() {
|
|
726
744
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
727
745
|
self.implementation.sendStats(action: "app_moved_to_background", versionName: current.getVersionName())
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-updater",
|
|
3
|
-
"version": "5.3.
|
|
4
|
-
"packageManager": "pnpm@8.
|
|
3
|
+
"version": "5.3.21",
|
|
4
|
+
"packageManager": "pnpm@8.9.2",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"description": "Live update for capacitor apps",
|
|
7
7
|
"main": "dist/plugin.cjs.js",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"@capacitor/docgen": "^0.2.1",
|
|
61
61
|
"@capacitor/ios": "^5.0.3",
|
|
62
62
|
"@ionic/eslint-config": "^0.3.0",
|
|
63
|
-
"@ionic/prettier-config": "^
|
|
63
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
64
64
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
65
65
|
"@types/node": "^20.2.3",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
67
|
-
"@typescript-eslint/parser": "^
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
67
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
68
68
|
"eslint": "^8.41.0",
|
|
69
69
|
"eslint-plugin-import": "^2.27.5",
|
|
70
70
|
"prettier": "^2.8.8",
|