@capgo/capacitor-updater 7.51.23 → 7.53.0
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/CapgoCapacitorUpdater.podspec +0 -3
- package/Package.swift +3 -11
- package/README.md +201 -66
- package/android/build.gradle +2 -3
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +593 -176
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +775 -162
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +2 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +226 -106
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +107 -30
- package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +325 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +63 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
- package/dist/docs.json +394 -27
- package/dist/esm/definitions.d.ts +220 -7
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +104 -52
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +472 -144
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +162 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +392 -82
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +2 -1
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +204 -93
- package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +75 -5
- package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
- package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +53 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +5 -2
- package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
- package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
- package/package.json +7 -3
|
@@ -150,11 +150,12 @@ public class CryptoCipher {
|
|
|
150
150
|
}
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
|
+
// The bundle is encrypted from here on: an unusable key must fail, never leave it encrypted.
|
|
153
154
|
if (!publicKey.startsWith("-----BEGIN RSA PUBLIC KEY-----")) {
|
|
154
155
|
if (logger != null) {
|
|
155
156
|
logger.error("The public key is not a valid RSA Public key");
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
throw new IOException("AES file decryption failed: the public key is not a valid RSA public key");
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
try {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package ee.forgr.capacitor_updater;
|
|
2
2
|
|
|
3
3
|
import android.content.SharedPreferences;
|
|
4
|
-
import io.github.g00fy2.versioncompare.Version;
|
|
5
4
|
import java.text.ParsePosition;
|
|
6
5
|
import java.text.SimpleDateFormat;
|
|
7
6
|
import java.util.ArrayList;
|
|
@@ -17,6 +16,9 @@ public class DelayUpdateUtils {
|
|
|
17
16
|
private final Logger logger;
|
|
18
17
|
|
|
19
18
|
public static final String DELAY_CONDITION_PREFERENCES = "DELAY_CONDITION_PREFERENCES_CAPGO";
|
|
19
|
+
public static final String DELAY_CONDITION_MODE_PREFERENCES = "DELAY_CONDITION_MODE_PREFERENCES_CAPGO";
|
|
20
|
+
public static final String DELAY_CONDITION_MODE_AND = "and";
|
|
21
|
+
public static final String DELAY_CONDITION_MODE_OR = "or";
|
|
20
22
|
public static final String BACKGROUND_TIMESTAMP_KEY = "BACKGROUND_TIMESTAMP_KEY_CAPGO";
|
|
21
23
|
|
|
22
24
|
private final SharedPreferences prefs;
|
|
@@ -39,128 +41,242 @@ public class DelayUpdateUtils {
|
|
|
39
41
|
public void checkCancelDelay(CancelDelaySource source) {
|
|
40
42
|
String delayUpdatePreferences = prefs.getString(DELAY_CONDITION_PREFERENCES, "[]");
|
|
41
43
|
ArrayList<DelayCondition> delayConditionList = parseDelayConditions(delayUpdatePreferences);
|
|
44
|
+
if (delayConditionList.isEmpty()) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
final boolean useOrMode = isOrConditionMode();
|
|
42
49
|
ArrayList<DelayCondition> delayConditionListToKeep = new ArrayList<>(delayConditionList.size());
|
|
43
50
|
int index = 0;
|
|
51
|
+
boolean anyConditionMet = false;
|
|
44
52
|
|
|
45
53
|
for (DelayCondition condition : delayConditionList) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"Background condition (value: " +
|
|
60
|
-
value +
|
|
61
|
-
") had an invalid value at index " +
|
|
62
|
-
index +
|
|
63
|
-
". We will likely remove it."
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (delta > longValue) {
|
|
68
|
-
logger.info(
|
|
69
|
-
"Background condition (value: " +
|
|
70
|
-
value +
|
|
71
|
-
") deleted at index " +
|
|
72
|
-
index +
|
|
73
|
-
". Delta: " +
|
|
74
|
-
delta +
|
|
75
|
-
", longValue: " +
|
|
76
|
-
longValue
|
|
77
|
-
);
|
|
78
|
-
} else {
|
|
79
|
-
delayConditionListToKeep.add(condition);
|
|
80
|
-
logger.info(
|
|
81
|
-
"Background delay (value: " +
|
|
82
|
-
value +
|
|
83
|
-
") condition kept at index " +
|
|
84
|
-
index +
|
|
85
|
-
" (source: " +
|
|
86
|
-
source.toString() +
|
|
87
|
-
")"
|
|
88
|
-
);
|
|
89
|
-
}
|
|
54
|
+
ConditionCheckResult result = evaluateCondition(condition, source, index);
|
|
55
|
+
if (result.met) {
|
|
56
|
+
anyConditionMet = true;
|
|
57
|
+
if (!useOrMode) {
|
|
58
|
+
logger.info(result.logMessage);
|
|
59
|
+
}
|
|
60
|
+
} else if (!useOrMode) {
|
|
61
|
+
if (result.keep) {
|
|
62
|
+
delayConditionListToKeep.add(condition);
|
|
63
|
+
}
|
|
64
|
+
if (result.logMessage != null) {
|
|
65
|
+
if (result.error) {
|
|
66
|
+
logger.error(result.logMessage);
|
|
90
67
|
} else {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
68
|
+
logger.info(result.logMessage);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else if (result.keep) {
|
|
72
|
+
delayConditionListToKeep.add(condition);
|
|
73
|
+
}
|
|
74
|
+
index++;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (useOrMode) {
|
|
78
|
+
if (anyConditionMet || delayConditionListToKeep.isEmpty()) {
|
|
79
|
+
logger.info("Delay condition met in OR mode (source: " + source + "), canceling delay");
|
|
80
|
+
this.cancelDelay("checkCancelDelay");
|
|
81
|
+
} else if (delayConditionListToKeep.size() != delayConditionList.size()) {
|
|
82
|
+
this.setMultiDelay(convertDelayConditionsToJson(delayConditionListToKeep));
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (delayConditionListToKeep.isEmpty()) {
|
|
88
|
+
this.cancelDelay("checkCancelDelay");
|
|
89
|
+
} else {
|
|
90
|
+
this.setMultiDelay(convertDelayConditionsToJson(delayConditionListToKeep));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private static final class ConditionCheckResult {
|
|
95
|
+
|
|
96
|
+
final boolean met;
|
|
97
|
+
final boolean keep;
|
|
98
|
+
final boolean error;
|
|
99
|
+
final String logMessage;
|
|
100
|
+
|
|
101
|
+
ConditionCheckResult(boolean met, boolean keep, boolean error, String logMessage) {
|
|
102
|
+
this.met = met;
|
|
103
|
+
this.keep = keep;
|
|
104
|
+
this.error = error;
|
|
105
|
+
this.logMessage = logMessage;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private ConditionCheckResult evaluateCondition(DelayCondition condition, CancelDelaySource source, int index) {
|
|
110
|
+
DelayUntilNext kind = condition.getKind();
|
|
111
|
+
String value = condition.getValue();
|
|
112
|
+
switch (kind) {
|
|
113
|
+
case background:
|
|
114
|
+
if (source == CancelDelaySource.FOREGROUND) {
|
|
115
|
+
long backgroundedAt = getBackgroundTimestamp();
|
|
116
|
+
long now = System.currentTimeMillis();
|
|
117
|
+
long delta = Math.max(0, now - backgroundedAt);
|
|
118
|
+
long longValue = 0L;
|
|
119
|
+
try {
|
|
120
|
+
longValue = Long.parseLong(value);
|
|
121
|
+
} catch (NumberFormatException e) {
|
|
122
|
+
return new ConditionCheckResult(
|
|
123
|
+
false,
|
|
124
|
+
false,
|
|
125
|
+
true,
|
|
126
|
+
"Background condition (value: " +
|
|
94
127
|
value +
|
|
95
|
-
")
|
|
128
|
+
") had an invalid value at index " +
|
|
96
129
|
index +
|
|
97
|
-
"
|
|
98
|
-
source.toString() +
|
|
99
|
-
")"
|
|
130
|
+
". We will likely remove it."
|
|
100
131
|
);
|
|
101
132
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
133
|
+
|
|
134
|
+
if (delta > longValue) {
|
|
135
|
+
return new ConditionCheckResult(
|
|
136
|
+
true,
|
|
137
|
+
false,
|
|
138
|
+
false,
|
|
139
|
+
"Background condition (value: " +
|
|
140
|
+
value +
|
|
141
|
+
") deleted at index " +
|
|
142
|
+
index +
|
|
143
|
+
". Delta: " +
|
|
144
|
+
delta +
|
|
145
|
+
", longValue: " +
|
|
146
|
+
longValue
|
|
110
147
|
);
|
|
111
148
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
149
|
+
return new ConditionCheckResult(
|
|
150
|
+
false,
|
|
151
|
+
true,
|
|
152
|
+
false,
|
|
153
|
+
"Background delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return new ConditionCheckResult(
|
|
157
|
+
false,
|
|
158
|
+
true,
|
|
159
|
+
false,
|
|
160
|
+
"Background delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
161
|
+
);
|
|
162
|
+
case kill:
|
|
163
|
+
if (source == CancelDelaySource.KILLED) {
|
|
164
|
+
return new ConditionCheckResult(
|
|
165
|
+
true,
|
|
166
|
+
false,
|
|
167
|
+
false,
|
|
168
|
+
"Kill delay (value: " + value + ") condition removed at index " + index + " after app kill"
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return new ConditionCheckResult(
|
|
172
|
+
false,
|
|
173
|
+
true,
|
|
174
|
+
false,
|
|
175
|
+
"Kill delay (value: " + value + ") condition kept at index " + index + " (source: " + source + ")"
|
|
176
|
+
);
|
|
177
|
+
case date:
|
|
178
|
+
if (!"".equals(value)) {
|
|
179
|
+
Date date = parseDateCondition(value);
|
|
180
|
+
if (date != null) {
|
|
181
|
+
if (new Date().compareTo(date) > 0) {
|
|
182
|
+
return new ConditionCheckResult(
|
|
183
|
+
true,
|
|
184
|
+
false,
|
|
185
|
+
false,
|
|
186
|
+
"Date delay (value: " + value + ") condition removed due to expired date at index " + index
|
|
187
|
+
);
|
|
125
188
|
}
|
|
126
|
-
|
|
127
|
-
|
|
189
|
+
return new ConditionCheckResult(
|
|
190
|
+
false,
|
|
191
|
+
true,
|
|
192
|
+
false,
|
|
193
|
+
"Date delay (value: " + value + ") condition kept at index " + index
|
|
194
|
+
);
|
|
128
195
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
196
|
+
return new ConditionCheckResult(
|
|
197
|
+
false,
|
|
198
|
+
false,
|
|
199
|
+
true,
|
|
200
|
+
"Date delay (value: " + value + ") condition removed due to parsing issue at index " + index
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return new ConditionCheckResult(
|
|
204
|
+
false,
|
|
205
|
+
false,
|
|
206
|
+
false,
|
|
207
|
+
"Date delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
208
|
+
);
|
|
209
|
+
case nativeVersion:
|
|
210
|
+
if (!"".equals(value)) {
|
|
211
|
+
try {
|
|
212
|
+
final Version versionLimit = new Version(value);
|
|
213
|
+
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
214
|
+
return new ConditionCheckResult(
|
|
215
|
+
true,
|
|
216
|
+
false,
|
|
217
|
+
false,
|
|
218
|
+
"Native version delay (value: " + value + ") condition removed due to above limit at index " + index
|
|
150
219
|
);
|
|
151
220
|
}
|
|
152
|
-
|
|
153
|
-
|
|
221
|
+
return new ConditionCheckResult(
|
|
222
|
+
false,
|
|
223
|
+
true,
|
|
224
|
+
false,
|
|
225
|
+
"Native version delay (value: " + value + ") condition kept at index " + index
|
|
226
|
+
);
|
|
227
|
+
} catch (final Exception e) {
|
|
228
|
+
return new ConditionCheckResult(
|
|
229
|
+
false,
|
|
230
|
+
false,
|
|
231
|
+
true,
|
|
232
|
+
"Native version delay (value: " +
|
|
233
|
+
value +
|
|
234
|
+
") condition removed due to parsing issue at index " +
|
|
235
|
+
index +
|
|
236
|
+
" " +
|
|
237
|
+
e.getMessage()
|
|
238
|
+
);
|
|
154
239
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
240
|
+
}
|
|
241
|
+
return new ConditionCheckResult(
|
|
242
|
+
false,
|
|
243
|
+
false,
|
|
244
|
+
false,
|
|
245
|
+
"Native version delay (value: " + value + ") condition removed due to empty value at index " + index
|
|
246
|
+
);
|
|
247
|
+
default:
|
|
248
|
+
return new ConditionCheckResult(false, false, true, "Unknown delay condition kind at index " + index);
|
|
158
249
|
}
|
|
250
|
+
}
|
|
159
251
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
252
|
+
public boolean isOrConditionMode() {
|
|
253
|
+
return DELAY_CONDITION_MODE_OR.equals(getConditionMode());
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public String getConditionMode() {
|
|
257
|
+
String mode = prefs.getString(DELAY_CONDITION_MODE_PREFERENCES, DELAY_CONDITION_MODE_AND);
|
|
258
|
+
if (DELAY_CONDITION_MODE_OR.equals(mode)) {
|
|
259
|
+
return DELAY_CONDITION_MODE_OR;
|
|
260
|
+
}
|
|
261
|
+
return DELAY_CONDITION_MODE_AND;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
public Boolean setConditionMode(String conditionMode) {
|
|
265
|
+
try {
|
|
266
|
+
String normalized = DELAY_CONDITION_MODE_OR.equals(conditionMode) ? DELAY_CONDITION_MODE_OR : DELAY_CONDITION_MODE_AND;
|
|
267
|
+
if (!DELAY_CONDITION_MODE_AND.equals(conditionMode) && !DELAY_CONDITION_MODE_OR.equals(conditionMode)) {
|
|
268
|
+
logger.warn("Unknown delay condition mode '" + conditionMode + "', defaulting to '" + DELAY_CONDITION_MODE_AND + "'");
|
|
269
|
+
}
|
|
270
|
+
this.editor.putString(DELAY_CONDITION_MODE_PREFERENCES, normalized);
|
|
271
|
+
if (!this.editor.commit()) {
|
|
272
|
+
logger.error("Failed to save delay condition mode: commit returned false");
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
logger.info("Delay condition mode saved: " + normalized);
|
|
276
|
+
return true;
|
|
277
|
+
} catch (final Exception e) {
|
|
278
|
+
logger.error("Failed to save delay condition mode: " + e.getMessage());
|
|
279
|
+
return false;
|
|
164
280
|
}
|
|
165
281
|
}
|
|
166
282
|
|
|
@@ -255,7 +371,10 @@ public class DelayUpdateUtils {
|
|
|
255
371
|
public Boolean setMultiDelay(String delayConditions) {
|
|
256
372
|
try {
|
|
257
373
|
this.editor.putString(DELAY_CONDITION_PREFERENCES, delayConditions);
|
|
258
|
-
this.editor.commit()
|
|
374
|
+
if (!this.editor.commit()) {
|
|
375
|
+
logger.error("Failed to delay update: commit returned false");
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
259
378
|
logger.info("Delay update saved");
|
|
260
379
|
return true;
|
|
261
380
|
} catch (final Exception e) {
|
|
@@ -296,6 +415,7 @@ public class DelayUpdateUtils {
|
|
|
296
415
|
public boolean cancelDelay(String source) {
|
|
297
416
|
try {
|
|
298
417
|
this.editor.remove(DELAY_CONDITION_PREFERENCES);
|
|
418
|
+
this.editor.remove(DELAY_CONDITION_MODE_PREFERENCES);
|
|
299
419
|
this.editor.commit();
|
|
300
420
|
logger.info("All delays canceled from " + source);
|
|
301
421
|
return true;
|