@capgo/capacitor-updater 4.17.31 → 4.17.32
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.
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
package ee.forgr.capacitor_updater;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
+
import android.app.ActivityManager;
|
|
4
5
|
import android.app.Application;
|
|
6
|
+
import android.content.Context;
|
|
5
7
|
import android.content.SharedPreferences;
|
|
8
|
+
import android.content.pm.ActivityInfo;
|
|
6
9
|
import android.content.pm.PackageInfo;
|
|
7
10
|
import android.content.pm.PackageManager;
|
|
8
11
|
import android.os.Build;
|
|
@@ -47,7 +50,7 @@ public class CapacitorUpdaterPlugin
|
|
|
47
50
|
private static final String channelUrlDefault =
|
|
48
51
|
"https://api.capgo.app/channel_self";
|
|
49
52
|
|
|
50
|
-
private final String PLUGIN_VERSION = "4.17.
|
|
53
|
+
private final String PLUGIN_VERSION = "4.17.32";
|
|
51
54
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
52
55
|
|
|
53
56
|
private SharedPreferences.Editor editor;
|
|
@@ -1026,71 +1029,6 @@ public class CapacitorUpdaterPlugin
|
|
|
1026
1029
|
.start();
|
|
1027
1030
|
}
|
|
1028
1031
|
|
|
1029
|
-
@Override // appMovedToForeground
|
|
1030
|
-
public void onActivityStarted(@NonNull final Activity activity) {
|
|
1031
|
-
this._checkCancelDelay(true);
|
|
1032
|
-
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
1033
|
-
this.backgroundDownload();
|
|
1034
|
-
}
|
|
1035
|
-
this.checkAppReady();
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
@Override // appMovedToBackground
|
|
1039
|
-
public void onActivityStopped(@NonNull final Activity activity) {
|
|
1040
|
-
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
1041
|
-
try {
|
|
1042
|
-
Gson gson = new Gson();
|
|
1043
|
-
String delayUpdatePreferences = prefs.getString(
|
|
1044
|
-
DELAY_CONDITION_PREFERENCES,
|
|
1045
|
-
"[]"
|
|
1046
|
-
);
|
|
1047
|
-
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1048
|
-
ArrayList<DelayCondition> delayConditionList = gson.fromJson(
|
|
1049
|
-
delayUpdatePreferences,
|
|
1050
|
-
type
|
|
1051
|
-
);
|
|
1052
|
-
String backgroundValue = null;
|
|
1053
|
-
for (DelayCondition delayCondition : delayConditionList) {
|
|
1054
|
-
if (delayCondition.getKind().toString().equals("background")) {
|
|
1055
|
-
String value = delayCondition.getValue();
|
|
1056
|
-
backgroundValue = (value != null && !value.isEmpty()) ? value : "0";
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
if (backgroundValue != null) {
|
|
1060
|
-
taskRunning = true;
|
|
1061
|
-
final Long timeout = Long.parseLong(backgroundValue);
|
|
1062
|
-
if (backgroundTask != null) {
|
|
1063
|
-
backgroundTask.interrupt();
|
|
1064
|
-
}
|
|
1065
|
-
backgroundTask =
|
|
1066
|
-
new Thread(
|
|
1067
|
-
new Runnable() {
|
|
1068
|
-
@Override
|
|
1069
|
-
public void run() {
|
|
1070
|
-
try {
|
|
1071
|
-
Thread.sleep(timeout);
|
|
1072
|
-
taskRunning = false;
|
|
1073
|
-
_checkCancelDelay(false);
|
|
1074
|
-
installNext();
|
|
1075
|
-
} catch (InterruptedException e) {
|
|
1076
|
-
Log.i(
|
|
1077
|
-
CapacitorUpdater.TAG,
|
|
1078
|
-
"Background Task canceled, Activity resumed before timer completes"
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
);
|
|
1084
|
-
backgroundTask.start();
|
|
1085
|
-
} else {
|
|
1086
|
-
this._checkCancelDelay(false);
|
|
1087
|
-
this.installNext();
|
|
1088
|
-
}
|
|
1089
|
-
} catch (final Exception e) {
|
|
1090
|
-
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
1032
|
private void installNext() {
|
|
1095
1033
|
try {
|
|
1096
1034
|
Gson gson = new Gson();
|
|
@@ -1216,6 +1154,116 @@ public class CapacitorUpdaterPlugin
|
|
|
1216
1154
|
}
|
|
1217
1155
|
}
|
|
1218
1156
|
|
|
1157
|
+
public void appMovedToForeground() {
|
|
1158
|
+
this._checkCancelDelay(true);
|
|
1159
|
+
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
1160
|
+
this.backgroundDownload();
|
|
1161
|
+
}
|
|
1162
|
+
this.checkAppReady();
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
public void appMovedToBackground() {
|
|
1166
|
+
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
1167
|
+
try {
|
|
1168
|
+
Gson gson = new Gson();
|
|
1169
|
+
String delayUpdatePreferences = prefs.getString(
|
|
1170
|
+
DELAY_CONDITION_PREFERENCES,
|
|
1171
|
+
"[]"
|
|
1172
|
+
);
|
|
1173
|
+
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1174
|
+
ArrayList<DelayCondition> delayConditionList = gson.fromJson(
|
|
1175
|
+
delayUpdatePreferences,
|
|
1176
|
+
type
|
|
1177
|
+
);
|
|
1178
|
+
String backgroundValue = null;
|
|
1179
|
+
for (DelayCondition delayCondition : delayConditionList) {
|
|
1180
|
+
if (delayCondition.getKind().toString().equals("background")) {
|
|
1181
|
+
String value = delayCondition.getValue();
|
|
1182
|
+
backgroundValue = (value != null && !value.isEmpty()) ? value : "0";
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
if (backgroundValue != null) {
|
|
1186
|
+
taskRunning = true;
|
|
1187
|
+
final Long timeout = Long.parseLong(backgroundValue);
|
|
1188
|
+
if (backgroundTask != null) {
|
|
1189
|
+
backgroundTask.interrupt();
|
|
1190
|
+
}
|
|
1191
|
+
backgroundTask =
|
|
1192
|
+
new Thread(
|
|
1193
|
+
new Runnable() {
|
|
1194
|
+
@Override
|
|
1195
|
+
public void run() {
|
|
1196
|
+
try {
|
|
1197
|
+
Thread.sleep(timeout);
|
|
1198
|
+
taskRunning = false;
|
|
1199
|
+
_checkCancelDelay(false);
|
|
1200
|
+
installNext();
|
|
1201
|
+
} catch (InterruptedException e) {
|
|
1202
|
+
Log.i(
|
|
1203
|
+
CapacitorUpdater.TAG,
|
|
1204
|
+
"Background Task canceled, Activity resumed before timer completes"
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
);
|
|
1210
|
+
backgroundTask.start();
|
|
1211
|
+
} else {
|
|
1212
|
+
this._checkCancelDelay(false);
|
|
1213
|
+
this.installNext();
|
|
1214
|
+
}
|
|
1215
|
+
} catch (final Exception e) {
|
|
1216
|
+
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
@Override
|
|
1221
|
+
public void onActivityStarted(@NonNull final Activity activity) {
|
|
1222
|
+
this.appMovedToForeground();
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
@Override
|
|
1226
|
+
public void onActivityStopped(@NonNull final Activity activity) {
|
|
1227
|
+
Context mContext = this.getContext();
|
|
1228
|
+
ActivityManager activityManager = (ActivityManager) mContext.getSystemService(
|
|
1229
|
+
Context.ACTIVITY_SERVICE
|
|
1230
|
+
);
|
|
1231
|
+
List<ActivityManager.AppTask> runningTasks = activityManager.getAppTasks();
|
|
1232
|
+
String runningActivity = runningTasks
|
|
1233
|
+
.get(0)
|
|
1234
|
+
.getTaskInfo()
|
|
1235
|
+
.topActivity.getClassName();
|
|
1236
|
+
ActivityManager.RecentTaskInfo runningTask = runningTasks
|
|
1237
|
+
.get(0)
|
|
1238
|
+
.getTaskInfo();
|
|
1239
|
+
String className = runningTask.baseIntent.getComponent().getClassName();
|
|
1240
|
+
ActivityInfo[] activities = null;
|
|
1241
|
+
try {
|
|
1242
|
+
activities =
|
|
1243
|
+
mContext
|
|
1244
|
+
.getPackageManager()
|
|
1245
|
+
.getPackageInfo(
|
|
1246
|
+
mContext.getPackageName(),
|
|
1247
|
+
PackageManager.GET_ACTIVITIES
|
|
1248
|
+
)
|
|
1249
|
+
.activities;
|
|
1250
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
1251
|
+
e.printStackTrace();
|
|
1252
|
+
}
|
|
1253
|
+
boolean isThisAppActivity = false;
|
|
1254
|
+
for (ActivityInfo activityInfo : activities) {
|
|
1255
|
+
if (
|
|
1256
|
+
activityInfo.name.equals(className) &&
|
|
1257
|
+
!className.equals(runningActivity)
|
|
1258
|
+
) {
|
|
1259
|
+
isThisAppActivity = true;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (!isThisAppActivity) {
|
|
1263
|
+
this.appMovedToBackground();
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1219
1267
|
@Override
|
|
1220
1268
|
public void onActivityResumed(@NonNull final Activity activity) {
|
|
1221
1269
|
if (backgroundTask != null && taskRunning) {
|
|
@@ -9,7 +9,7 @@ import Version
|
|
|
9
9
|
@objc(CapacitorUpdaterPlugin)
|
|
10
10
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
11
11
|
private var implementation = CapacitorUpdater()
|
|
12
|
-
private let PLUGIN_VERSION: String = "4.17.
|
|
12
|
+
private let PLUGIN_VERSION: String = "4.17.32"
|
|
13
13
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
14
14
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
15
15
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|
|
@@ -573,51 +573,6 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
@objc func appMovedToForeground() {
|
|
577
|
-
if backgroundWork != nil && taskRunning {
|
|
578
|
-
backgroundWork!.cancel()
|
|
579
|
-
print("\(self.implementation.TAG) Background Timer Task canceled, Activity resumed before timer completes")
|
|
580
|
-
}
|
|
581
|
-
if self._isAutoUpdateEnabled() {
|
|
582
|
-
self.backgroundDownload()
|
|
583
|
-
}
|
|
584
|
-
self.checkAppReady()
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
@objc func appMovedToBackground() {
|
|
588
|
-
print("\(self.implementation.TAG) Check for pending update")
|
|
589
|
-
let delayUpdatePreferences = UserDefaults.standard.string(forKey: DELAY_CONDITION_PREFERENCES) ?? "[]"
|
|
590
|
-
|
|
591
|
-
let delayConditionList: [DelayCondition] = fromJsonArr(json: delayUpdatePreferences).map { obj -> DelayCondition in
|
|
592
|
-
let kind: String = obj.value(forKey: "kind") as! String
|
|
593
|
-
let value: String? = obj.value(forKey: "value") as? String
|
|
594
|
-
return DelayCondition(kind: kind, value: value)
|
|
595
|
-
}
|
|
596
|
-
var backgroundValue: String?
|
|
597
|
-
for delayCondition in delayConditionList {
|
|
598
|
-
if delayCondition.getKind() == "background" {
|
|
599
|
-
let value: String? = delayCondition.getValue()
|
|
600
|
-
backgroundValue = (value != nil && value != "") ? value! : "0"
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
if backgroundValue != nil {
|
|
604
|
-
self.taskRunning = true
|
|
605
|
-
let interval: Double = (Double(backgroundValue!) ?? 0.0) / 1000
|
|
606
|
-
self.backgroundWork?.cancel()
|
|
607
|
-
self.backgroundWork = DispatchWorkItem(block: {
|
|
608
|
-
// IOS never executes this task in background
|
|
609
|
-
self.taskRunning = false
|
|
610
|
-
self._checkCancelDelay(killed: false)
|
|
611
|
-
self.installNext()
|
|
612
|
-
})
|
|
613
|
-
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + interval, execute: self.backgroundWork!)
|
|
614
|
-
} else {
|
|
615
|
-
self._checkCancelDelay(killed: false)
|
|
616
|
-
self.installNext()
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
|
|
621
576
|
@objc func appKilled() {
|
|
622
577
|
self._checkCancelDelay(killed: true)
|
|
623
578
|
}
|
|
@@ -662,4 +617,49 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
662
617
|
) as? [NSObject]
|
|
663
618
|
return object ?? []
|
|
664
619
|
}
|
|
620
|
+
|
|
621
|
+
@objc func appMovedToForeground() {
|
|
622
|
+
if backgroundWork != nil && taskRunning {
|
|
623
|
+
backgroundWork!.cancel()
|
|
624
|
+
print("\(self.implementation.TAG) Background Timer Task canceled, Activity resumed before timer completes")
|
|
625
|
+
}
|
|
626
|
+
if self._isAutoUpdateEnabled() {
|
|
627
|
+
self.backgroundDownload()
|
|
628
|
+
}
|
|
629
|
+
self.checkAppReady()
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
@objc func appMovedToBackground() {
|
|
633
|
+
print("\(self.implementation.TAG) Check for pending update")
|
|
634
|
+
let delayUpdatePreferences = UserDefaults.standard.string(forKey: DELAY_CONDITION_PREFERENCES) ?? "[]"
|
|
635
|
+
|
|
636
|
+
let delayConditionList: [DelayCondition] = fromJsonArr(json: delayUpdatePreferences).map { obj -> DelayCondition in
|
|
637
|
+
let kind: String = obj.value(forKey: "kind") as! String
|
|
638
|
+
let value: String? = obj.value(forKey: "value") as? String
|
|
639
|
+
return DelayCondition(kind: kind, value: value)
|
|
640
|
+
}
|
|
641
|
+
var backgroundValue: String?
|
|
642
|
+
for delayCondition in delayConditionList {
|
|
643
|
+
if delayCondition.getKind() == "background" {
|
|
644
|
+
let value: String? = delayCondition.getValue()
|
|
645
|
+
backgroundValue = (value != nil && value != "") ? value! : "0"
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if backgroundValue != nil {
|
|
649
|
+
self.taskRunning = true
|
|
650
|
+
let interval: Double = (Double(backgroundValue!) ?? 0.0) / 1000
|
|
651
|
+
self.backgroundWork?.cancel()
|
|
652
|
+
self.backgroundWork = DispatchWorkItem(block: {
|
|
653
|
+
// IOS never executes this task in background
|
|
654
|
+
self.taskRunning = false
|
|
655
|
+
self._checkCancelDelay(killed: false)
|
|
656
|
+
self.installNext()
|
|
657
|
+
})
|
|
658
|
+
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + interval, execute: self.backgroundWork!)
|
|
659
|
+
} else {
|
|
660
|
+
self._checkCancelDelay(killed: false)
|
|
661
|
+
self.installNext()
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
}
|
|
665
665
|
}
|