@capgo/capacitor-updater 8.51.20 → 8.51.22
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 +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +14 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +42 -17
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +75 -24
- package/dist/esm/history.js +7 -7
- package/dist/esm/history.js.map +1 -1
- package/dist/plugin.cjs.js +7 -7
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +7 -7
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +130 -53
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +97 -20
- package/package.json +6 -8
|
@@ -146,7 +146,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
146
146
|
static final int APPLICATION_EXIT_REASON_USER_REQUESTED = 10;
|
|
147
147
|
static final int APPLICATION_EXIT_REASON_DEPENDENCY_DIED = 12;
|
|
148
148
|
|
|
149
|
-
private final String pluginVersion = "8.51.
|
|
149
|
+
private final String pluginVersion = "8.51.22";
|
|
150
150
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
151
151
|
|
|
152
152
|
private SharedPreferences.Editor editor;
|
|
@@ -285,6 +285,15 @@ public class CapgoUpdater {
|
|
|
285
285
|
this.cachedKeyId = CryptoCipher.calcKeyId(publicKey);
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
static boolean containsPathTraversalSegment(final String relativePath) {
|
|
289
|
+
for (final String segment : relativePath.split("/")) {
|
|
290
|
+
if ("..".equals(segment)) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
288
297
|
static File resolvePathInsideDirectory(final File baseDirectory, final String relativePath) throws IOException {
|
|
289
298
|
if (relativePath == null || relativePath.isEmpty()) {
|
|
290
299
|
throw new IOException("Invalid empty path");
|
|
@@ -292,6 +301,9 @@ public class CapgoUpdater {
|
|
|
292
301
|
if (relativePath.contains("\\") || relativePath.indexOf('\0') >= 0) {
|
|
293
302
|
throw new IOException("Invalid path separator");
|
|
294
303
|
}
|
|
304
|
+
if (containsPathTraversalSegment(relativePath)) {
|
|
305
|
+
throw new IOException("Path traversal segments are not allowed");
|
|
306
|
+
}
|
|
295
307
|
if (new File(relativePath).isAbsolute()) {
|
|
296
308
|
throw new IOException("Absolute paths are not allowed");
|
|
297
309
|
}
|
|
@@ -302,7 +314,8 @@ public class CapgoUpdater {
|
|
|
302
314
|
final String targetPath = canonicalTarget.getPath();
|
|
303
315
|
final String normalizedBasePath = basePath.endsWith(File.separator) ? basePath : basePath + File.separator;
|
|
304
316
|
|
|
305
|
-
|
|
317
|
+
// Require a strict child of the base. Equality would accept "." and wipe/write the root.
|
|
318
|
+
if (!targetPath.startsWith(normalizedBasePath)) {
|
|
306
319
|
throw new IOException("Path escapes base directory: " + relativePath);
|
|
307
320
|
}
|
|
308
321
|
|
|
@@ -50,17 +50,15 @@ public class CryptoCipher {
|
|
|
50
50
|
return decryptedBytes;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
public static byte[] decryptAES(byte[] cipherText, SecretKey key, byte[] iv) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
57
|
-
SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");
|
|
58
|
-
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
|
|
59
|
-
return cipher.doFinal(cipherText);
|
|
60
|
-
} catch (Exception e) {
|
|
61
|
-
e.printStackTrace();
|
|
53
|
+
public static byte[] decryptAES(byte[] cipherText, SecretKey key, byte[] iv) throws GeneralSecurityException {
|
|
54
|
+
if (key == null || iv == null) {
|
|
55
|
+
throw new IllegalArgumentException("AES key and IV must not be null");
|
|
62
56
|
}
|
|
63
|
-
|
|
57
|
+
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
|
|
58
|
+
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
59
|
+
SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");
|
|
60
|
+
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
|
|
61
|
+
return cipher.doFinal(cipherText);
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
public static SecretKey byteToSessionKey(byte[] sessionKey) {
|
|
@@ -139,11 +137,15 @@ public class CryptoCipher {
|
|
|
139
137
|
|
|
140
138
|
public static void decryptFile(final File file, final String publicKey, final String ivSessionKey) throws IOException {
|
|
141
139
|
if (publicKey.isEmpty() || ivSessionKey == null || ivSessionKey.isEmpty() || ivSessionKey.split(":").length != 2) {
|
|
142
|
-
logger
|
|
140
|
+
if (logger != null) {
|
|
141
|
+
logger.info("Encryption not set, no public key or session, ignored");
|
|
142
|
+
}
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
if (!publicKey.startsWith("-----BEGIN RSA PUBLIC KEY-----")) {
|
|
146
|
-
logger
|
|
146
|
+
if (logger != null) {
|
|
147
|
+
logger.error("The public key is not a valid RSA Public key");
|
|
148
|
+
}
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
149
151
|
|
|
@@ -152,29 +154,50 @@ public class CryptoCipher {
|
|
|
152
154
|
String sessionKeyB64 = ivSessionKey.split(":")[1];
|
|
153
155
|
byte[] iv = Base64.decode(ivB64.getBytes(), Base64.DEFAULT);
|
|
154
156
|
byte[] sessionKey = Base64.decode(sessionKeyB64.getBytes(), Base64.DEFAULT);
|
|
157
|
+
if (iv.length != 16) {
|
|
158
|
+
throw new IOException("AES file decryption failed: IV must be 16 bytes");
|
|
159
|
+
}
|
|
155
160
|
PublicKey pKey = CryptoCipher.stringToPublicKey(publicKey);
|
|
156
161
|
byte[] decryptedSessionKey = CryptoCipher.decryptRSA(sessionKey, pKey);
|
|
162
|
+
if (decryptedSessionKey == null || decryptedSessionKey.length != 16) {
|
|
163
|
+
throw new IOException("AES file decryption failed: decrypted session key must be 16 bytes");
|
|
164
|
+
}
|
|
157
165
|
|
|
158
166
|
SecretKey sKey = CryptoCipher.byteToSessionKey(decryptedSessionKey);
|
|
159
167
|
decryptAesFile(file, sKey, iv);
|
|
160
168
|
} catch (GeneralSecurityException e) {
|
|
161
|
-
logger
|
|
162
|
-
|
|
169
|
+
if (logger != null) {
|
|
170
|
+
logger.info("decryptFile fail");
|
|
171
|
+
}
|
|
172
|
+
throw new IOException("AES file decryption failed: " + e.getMessage(), e);
|
|
163
173
|
}
|
|
164
174
|
}
|
|
165
175
|
|
|
166
|
-
static void decryptAesFile(File file, SecretKey key, byte[] iv) throws IOException
|
|
176
|
+
static void decryptAesFile(File file, SecretKey key, byte[] iv) throws IOException {
|
|
177
|
+
if (key == null) {
|
|
178
|
+
throw new IOException("AES file decryption failed: missing session key");
|
|
179
|
+
}
|
|
180
|
+
if (iv == null) {
|
|
181
|
+
throw new IOException("AES file decryption failed: missing IV");
|
|
182
|
+
}
|
|
183
|
+
if (iv.length != 16) {
|
|
184
|
+
throw new IOException("AES file decryption failed: IV must be 16 bytes");
|
|
185
|
+
}
|
|
186
|
+
byte[] keyBytes = key.getEncoded();
|
|
187
|
+
if (keyBytes == null || keyBytes.length != 16) {
|
|
188
|
+
throw new IOException("AES file decryption failed: session key must be 16 bytes");
|
|
189
|
+
}
|
|
167
190
|
if (file.length() == 0) {
|
|
168
191
|
throw new IOException("Empty encrypted data");
|
|
169
192
|
}
|
|
170
|
-
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
171
|
-
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getEncoded(), "AES"), new IvParameterSpec(iv));
|
|
172
193
|
File parent = file.getAbsoluteFile().getParentFile();
|
|
173
194
|
if (parent == null) {
|
|
174
195
|
throw new IOException("Cannot create temp file for " + file.getAbsolutePath());
|
|
175
196
|
}
|
|
176
197
|
File tempFile = File.createTempFile("capgo-aes-", ".tmp", parent);
|
|
177
198
|
try {
|
|
199
|
+
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
200
|
+
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, "AES"), new IvParameterSpec(iv));
|
|
178
201
|
byte[] inBuf = new byte[ioBufferBytes()];
|
|
179
202
|
// Reuse one output buffer. cipher.update(in) allocates a new byte[] per chunk.
|
|
180
203
|
byte[] outBuf = new byte[inBuf.length + 16];
|
|
@@ -196,6 +219,8 @@ public class CryptoCipher {
|
|
|
196
219
|
}
|
|
197
220
|
replaceFile(tempFile, file);
|
|
198
221
|
tempFile = null;
|
|
222
|
+
} catch (GeneralSecurityException e) {
|
|
223
|
+
throw new IOException("AES file decryption failed: " + e.getMessage(), e);
|
|
199
224
|
} finally {
|
|
200
225
|
if (tempFile != null && tempFile.exists()) {
|
|
201
226
|
tempFile.delete();
|
|
@@ -363,6 +363,38 @@ public class DownloadService extends Worker {
|
|
|
363
363
|
return seenTargets.add(targetFile.getCanonicalPath());
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
private static final class ManifestDownloadTask {
|
|
367
|
+
|
|
368
|
+
final String fileName;
|
|
369
|
+
final String finalFileHash;
|
|
370
|
+
final String downloadUrl;
|
|
371
|
+
final boolean isBrotli;
|
|
372
|
+
final File targetFile;
|
|
373
|
+
final File builtinFile;
|
|
374
|
+
final File cacheFile;
|
|
375
|
+
final File legacyCacheFile;
|
|
376
|
+
|
|
377
|
+
ManifestDownloadTask(
|
|
378
|
+
final String fileName,
|
|
379
|
+
final String finalFileHash,
|
|
380
|
+
final String downloadUrl,
|
|
381
|
+
final boolean isBrotli,
|
|
382
|
+
final File targetFile,
|
|
383
|
+
final File builtinFile,
|
|
384
|
+
final File cacheFile,
|
|
385
|
+
final File legacyCacheFile
|
|
386
|
+
) {
|
|
387
|
+
this.fileName = fileName;
|
|
388
|
+
this.finalFileHash = finalFileHash;
|
|
389
|
+
this.downloadUrl = downloadUrl;
|
|
390
|
+
this.isBrotli = isBrotli;
|
|
391
|
+
this.targetFile = targetFile;
|
|
392
|
+
this.builtinFile = builtinFile;
|
|
393
|
+
this.cacheFile = cacheFile;
|
|
394
|
+
this.legacyCacheFile = legacyCacheFile;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
366
398
|
static boolean tryCopyBuiltinAsset(final AssetManager assets, final String fileName, final File dest, final String expectedHash) {
|
|
367
399
|
if (assets == null || fileName == null || dest == null) {
|
|
368
400
|
return false;
|
|
@@ -535,9 +567,7 @@ public class DownloadService extends Worker {
|
|
|
535
567
|
int totalFiles = manifest.length();
|
|
536
568
|
final AtomicLong completedFiles = new AtomicLong(0);
|
|
537
569
|
final AtomicBoolean hasError = new AtomicBoolean(false);
|
|
538
|
-
|
|
539
|
-
ExecutorService executor = Executors.newFixedThreadPool(Math.min(MANIFEST_MAX_CONCURRENT_FILES, Math.max(1, totalFiles)));
|
|
540
|
-
List<Future<?>> futures = new ArrayList<>();
|
|
570
|
+
final List<ManifestDownloadTask> tasks = new ArrayList<>();
|
|
541
571
|
final Set<String> seenTargets = new HashSet<>();
|
|
542
572
|
|
|
543
573
|
for (int i = 0; i < totalFiles; i++) {
|
|
@@ -592,35 +622,56 @@ public class DownloadService extends Worker {
|
|
|
592
622
|
final File legacyCacheFile =
|
|
593
623
|
isBrotli && cacheFile != null ? new File(cacheFolder, finalFileHash + "_" + new File(fileName).getName()) : null;
|
|
594
624
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
625
|
+
tasks.add(
|
|
626
|
+
new ManifestDownloadTask(
|
|
627
|
+
fileName,
|
|
628
|
+
finalFileHash,
|
|
629
|
+
downloadUrl,
|
|
630
|
+
isBrotli,
|
|
631
|
+
targetFile,
|
|
632
|
+
builtinFile,
|
|
633
|
+
cacheFile,
|
|
634
|
+
legacyCacheFile
|
|
635
|
+
)
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (hasError.get()) {
|
|
640
|
+
throw new IOException("Manifest contains invalid or duplicate file paths");
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
for (final ManifestDownloadTask task : tasks) {
|
|
644
|
+
if (!Objects.requireNonNull(task.targetFile.getParentFile()).exists() && !task.targetFile.getParentFile().mkdirs()) {
|
|
645
|
+
logger.error("Failed to create parent directory for: " + task.targetFile.getAbsolutePath());
|
|
646
|
+
throw new IOException("Failed to create parent directory for: " + task.targetFile.getAbsolutePath());
|
|
600
647
|
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
ExecutorService executor = Executors.newFixedThreadPool(Math.min(MANIFEST_MAX_CONCURRENT_FILES, Math.max(1, totalFiles)));
|
|
651
|
+
List<Future<?>> futures = new ArrayList<>();
|
|
601
652
|
|
|
602
|
-
|
|
653
|
+
for (final ManifestDownloadTask task : tasks) {
|
|
603
654
|
Future<?> future = executor.submit(() -> {
|
|
604
655
|
try {
|
|
605
|
-
if (tryCopyBuiltinAsset(assets, fileName, targetFile, finalFileHash)) {
|
|
606
|
-
logger.debug("using builtin asset " + fileName);
|
|
607
|
-
} else if (tryCopyBuiltinFile(builtinFile, targetFile, finalFileHash)) {
|
|
608
|
-
logger.debug("using builtin file " + fileName);
|
|
656
|
+
if (tryCopyBuiltinAsset(assets, task.fileName, task.targetFile, task.finalFileHash)) {
|
|
657
|
+
logger.debug("using builtin asset " + task.fileName);
|
|
658
|
+
} else if (tryCopyBuiltinFile(task.builtinFile, task.targetFile, task.finalFileHash)) {
|
|
659
|
+
logger.debug("using builtin file " + task.fileName);
|
|
609
660
|
} else if (
|
|
610
|
-
tryCopyFromCache(cacheFile, targetFile, finalFileHash) ||
|
|
611
|
-
(legacyCacheFile != null && tryCopyFromCache(legacyCacheFile, targetFile, finalFileHash))
|
|
661
|
+
tryCopyFromCache(task.cacheFile, task.targetFile, task.finalFileHash) ||
|
|
662
|
+
(task.legacyCacheFile != null && tryCopyFromCache(task.legacyCacheFile, task.targetFile, task.finalFileHash))
|
|
612
663
|
) {
|
|
613
|
-
logger.debug("already cached " + fileName);
|
|
664
|
+
logger.debug("already cached " + task.fileName);
|
|
614
665
|
} else {
|
|
615
666
|
downloadAndVerify(
|
|
616
|
-
downloadUrl,
|
|
617
|
-
targetFile,
|
|
618
|
-
cacheFile,
|
|
619
|
-
finalFileHash,
|
|
667
|
+
task.downloadUrl,
|
|
668
|
+
task.targetFile,
|
|
669
|
+
task.cacheFile,
|
|
670
|
+
task.finalFileHash,
|
|
620
671
|
sessionKey,
|
|
621
672
|
publicKey,
|
|
622
|
-
|
|
623
|
-
fileName
|
|
673
|
+
task.isBrotli,
|
|
674
|
+
task.fileName
|
|
624
675
|
);
|
|
625
676
|
}
|
|
626
677
|
|
|
@@ -628,8 +679,8 @@ public class DownloadService extends Worker {
|
|
|
628
679
|
int percent = calcTotalPercent(completed, totalFiles);
|
|
629
680
|
setProgress(percent);
|
|
630
681
|
} catch (Exception e) {
|
|
631
|
-
logger.error("Error processing file: " + fileName + " " + e.getMessage());
|
|
632
|
-
sendStatsAsync("download_manifest_file_fail", version + ":" + fileName);
|
|
682
|
+
logger.error("Error processing file: " + task.fileName + " " + e.getMessage());
|
|
683
|
+
sendStatsAsync("download_manifest_file_fail", version + ":" + task.fileName);
|
|
633
684
|
hasError.set(true);
|
|
634
685
|
}
|
|
635
686
|
});
|
package/dist/esm/history.js
CHANGED
|
@@ -15,13 +15,13 @@ if (isBrowser) {
|
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
catch (
|
|
18
|
+
catch (_a) {
|
|
19
19
|
// ignore access issues
|
|
20
20
|
}
|
|
21
21
|
try {
|
|
22
22
|
return window.localStorage.getItem(KEEP_FLAG_KEY) === '1';
|
|
23
23
|
}
|
|
24
|
-
catch (
|
|
24
|
+
catch (_b) {
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
@@ -37,7 +37,7 @@ if (isBrowser) {
|
|
|
37
37
|
}
|
|
38
38
|
return parsed;
|
|
39
39
|
}
|
|
40
|
-
catch (
|
|
40
|
+
catch (_a) {
|
|
41
41
|
return { stack: [], index: -1 };
|
|
42
42
|
}
|
|
43
43
|
};
|
|
@@ -45,7 +45,7 @@ if (isBrowser) {
|
|
|
45
45
|
try {
|
|
46
46
|
window.sessionStorage.setItem(HISTORY_STORAGE_KEY, JSON.stringify({ stack, index }));
|
|
47
47
|
}
|
|
48
|
-
catch (
|
|
48
|
+
catch (_a) {
|
|
49
49
|
// Storage might be unavailable; fail silently.
|
|
50
50
|
}
|
|
51
51
|
};
|
|
@@ -53,7 +53,7 @@ if (isBrowser) {
|
|
|
53
53
|
try {
|
|
54
54
|
window.sessionStorage.removeItem(HISTORY_STORAGE_KEY);
|
|
55
55
|
}
|
|
56
|
-
catch (
|
|
56
|
+
catch (_a) {
|
|
57
57
|
// ignore
|
|
58
58
|
}
|
|
59
59
|
};
|
|
@@ -63,7 +63,7 @@ if (isBrowser) {
|
|
|
63
63
|
const parsed = new URL(base instanceof URL ? base.toString() : base, window.location.href);
|
|
64
64
|
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
65
65
|
}
|
|
66
|
-
catch (
|
|
66
|
+
catch (_a) {
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
@@ -168,7 +168,7 @@ if (isBrowser) {
|
|
|
168
168
|
history.pushState(history.state, document.title, stored.stack[i]);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
catch (
|
|
171
|
+
catch (_a) {
|
|
172
172
|
isRestoring = false;
|
|
173
173
|
return;
|
|
174
174
|
}
|
package/dist/esm/history.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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igation history across Capgo-controlled reloads when keepUrlPathAfterReload is enabled.\n */\n\nconst KEEP_FLAG_KEY = '__capgo_keep_url_path_after_reload';\nconst HISTORY_STORAGE_KEY = '__capgo_history_stack__';\nconst MAX_STACK_ENTRIES = 100;\n\nconst isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof history !== 'undefined';\n\nif (isBrowser) {\n const win = window as typeof window & {\n __capgoHistoryPatched?: boolean;\n __capgoKeepUrlPathAfterReload?: boolean;\n };\n\n if (!win.__capgoHistoryPatched) {\n win.__capgoHistoryPatched = true;\n\n const isFeatureConfigured = (): boolean => {\n try {\n if (win.__capgoKeepUrlPathAfterReload) {\n return true;\n }\n } catch (err) {\n // ignore access issues\n }\n try {\n return window.localStorage.getItem(KEEP_FLAG_KEY) === '1';\n } catch (err) {\n return false;\n }\n };\n\n type StoredHistory = { stack: string[]; index: number };\n\n const readStored = (): StoredHistory => {\n try {\n const raw = window.sessionStorage.getItem(HISTORY_STORAGE_KEY);\n if (!raw) {\n return { stack: [], index: -1 };\n }\n const parsed = JSON.parse(raw) as StoredHistory;\n if (!parsed || !Array.isArray(parsed.stack) || typeof parsed.index !== 'number') {\n return { stack: [], index: -1 };\n }\n return parsed;\n } catch (err) {\n return { stack: [], index: -1 };\n }\n };\n\n const writeStored = (stack: string[], index: number): void => {\n try {\n window.sessionStorage.setItem(HISTORY_STORAGE_KEY, JSON.stringify({ stack, index }));\n } catch (err) {\n // Storage might be unavailable; fail silently.\n }\n };\n\n const clearStored = (): void => {\n try {\n window.sessionStorage.removeItem(HISTORY_STORAGE_KEY);\n } catch (err) {\n // ignore\n }\n };\n\n const normalize = (url?: string | URL | null): string | null => {\n try {\n const base = url ?? window.location.href;\n const parsed = new URL(base instanceof URL ? base.toString() : base, window.location.href);\n return `${parsed.pathname}${parsed.search}${parsed.hash}`;\n } catch (err) {\n return null;\n }\n };\n\n const trimStack = (stack: string[], index: number): StoredHistory => {\n if (stack.length <= MAX_STACK_ENTRIES) {\n return { stack, index };\n }\n const start = stack.length - MAX_STACK_ENTRIES;\n const trimmed = stack.slice(start);\n const adjustedIndex = Math.max(0, index - start);\n return { stack: trimmed, index: adjustedIndex };\n };\n\n const runWhenReady = (fn: () => void): void => {\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n fn();\n } else {\n window.addEventListener('DOMContentLoaded', fn, { once: true });\n }\n };\n\n let featureActive = false;\n let isRestoring = false;\n let restoreScheduled = false;\n\n const ensureCurrentTracked = () => {\n if (!featureActive) {\n return;\n }\n const stored = readStored();\n const current = normalize();\n if (!current) {\n return;\n }\n if (stored.stack.length === 0) {\n stored.stack.push(current);\n stored.index = 0;\n writeStored(stored.stack, stored.index);\n return;\n }\n if (stored.index < 0 || stored.index >= stored.stack.length) {\n stored.index = stored.stack.length - 1;\n }\n if (stored.stack[stored.index] !== current) {\n stored.stack[stored.index] = current;\n writeStored(stored.stack, stored.index);\n }\n };\n\n const record = (url: string | URL | null | undefined, replace: boolean) => {\n if (!featureActive || isRestoring) {\n return;\n }\n const normalized = normalize(url);\n if (!normalized) {\n return;\n }\n let { stack, index } = readStored();\n if (stack.length === 0) {\n stack.push(normalized);\n index = stack.length - 1;\n } else if (replace) {\n if (index < 0 || index >= stack.length) {\n index = stack.length - 1;\n }\n stack[index] = normalized;\n } else {\n if (index >= stack.length - 1) {\n stack.push(normalized);\n index = stack.length - 1;\n } else {\n stack = stack.slice(0, index + 1);\n stack.push(normalized);\n index = stack.length - 1;\n }\n }\n ({ stack, index } = trimStack(stack, index));\n writeStored(stack, index);\n };\n\n const restoreHistory = () => {\n if (!featureActive || isRestoring) {\n return;\n }\n const stored = readStored();\n if (stored.stack.length === 0) {\n ensureCurrentTracked();\n return;\n }\n const targetIndex =\n stored.index >= 0 && stored.index < stored.stack.length ? stored.index : stored.stack.length - 1;\n const normalizedCurrent = normalize();\n if (stored.stack.length === 1 && normalizedCurrent === stored.stack[0]) {\n return;\n }\n const firstEntry = stored.stack[0];\n if (!firstEntry) {\n return;\n }\n isRestoring = true;\n try {\n history.replaceState(history.state, document.title, firstEntry);\n for (let i = 1; i < stored.stack.length; i += 1) {\n history.pushState(history.state, document.title, stored.stack[i]);\n }\n } catch (err) {\n isRestoring = false;\n return;\n }\n isRestoring = false;\n const currentIndex = stored.stack.length - 1;\n const offset = targetIndex - currentIndex;\n if (offset !== 0) {\n history.go(offset);\n } else {\n history.replaceState(history.state, document.title, stored.stack[targetIndex]);\n window.dispatchEvent(new PopStateEvent('popstate'));\n }\n };\n\n const scheduleRestore = () => {\n if (!featureActive || restoreScheduled) {\n return;\n }\n restoreScheduled = true;\n runWhenReady(() => {\n restoreScheduled = false;\n restoreHistory();\n });\n };\n\n let originalPushState: typeof history.pushState | null = null;\n let originalReplaceState: typeof history.replaceState | null = null;\n\n const popstateHandler = () => {\n if (!featureActive || isRestoring) {\n return;\n }\n const normalized = normalize();\n if (!normalized) {\n return;\n }\n const stored = readStored();\n const idx = stored.stack.lastIndexOf(normalized);\n if (idx >= 0) {\n stored.index = idx;\n } else {\n stored.stack.push(normalized);\n stored.index = stored.stack.length - 1;\n }\n const trimmed = trimStack(stored.stack, stored.index);\n writeStored(trimmed.stack, trimmed.index);\n };\n\n const patchHistory = () => {\n if (originalPushState && originalReplaceState) {\n return;\n }\n originalPushState = history.pushState;\n originalReplaceState = history.replaceState;\n\n history.pushState = function pushStatePatched(state: any, title: string, url?: string | URL | null) {\n const result = originalPushState?.call(history, state, title, url as any);\n record(url, false);\n return result;\n };\n\n history.replaceState = function replaceStatePatched(state: any, title: string, url?: string | URL | null) {\n const result = originalReplaceState?.call(history, state, title, url as any);\n record(url, true);\n return result;\n };\n\n window.addEventListener('popstate', popstateHandler);\n };\n\n const unpatchHistory = () => {\n if (originalPushState) {\n history.pushState = originalPushState;\n originalPushState = null;\n }\n if (originalReplaceState) {\n history.replaceState = originalReplaceState;\n originalReplaceState = null;\n }\n window.removeEventListener('popstate', popstateHandler);\n };\n\n const setFeatureActive = (enabled: boolean) => {\n if (featureActive === enabled) {\n if (featureActive) {\n ensureCurrentTracked();\n scheduleRestore();\n }\n return;\n }\n featureActive = enabled;\n if (featureActive) {\n patchHistory();\n ensureCurrentTracked();\n scheduleRestore();\n } else {\n unpatchHistory();\n clearStored();\n }\n };\n\n window.addEventListener('CapacitorUpdaterKeepUrlPathAfterReload', (event) => {\n const evt = event as CustomEvent<{ enabled?: boolean }>;\n const enabled = evt?.detail?.enabled;\n if (typeof enabled === 'boolean') {\n win.__capgoKeepUrlPathAfterReload = enabled;\n setFeatureActive(enabled);\n } else {\n win.__capgoKeepUrlPathAfterReload = true;\n setFeatureActive(true);\n }\n });\n\n setFeatureActive(isFeatureConfigured());\n }\n}\n\nexport {};\n"]}
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,aAAa,GAAG,oCAAoC,CAAC;AAC3D,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AACtD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,OAAO,OAAO,KAAK,WAAW,CAAC;AAErH,IAAI,SAAS,EAAE,CAAC;IACd,MAAM,GAAG,GAAG,MAGX,CAAC;IAEF,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAC/B,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAEjC,MAAM,mBAAmB,GAAG,GAAY,EAAE;YACxC,IAAI,CAAC;gBACH,IAAI,GAAG,CAAC,6BAA6B,EAAE,CAAC;oBACtC,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YAAC,WAAM,CAAC;gBACP,uBAAuB;YACzB,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,GAAG,CAAC;YAC5D,CAAC;YAAC,WAAM,CAAC;g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,IAAI,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC;gBACjC,GAAG,CAAC,6BAA6B,GAAG,OAAO,CAAC;gBAC5C,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,6BAA6B,GAAG,IAAI,CAAC;gBACzC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC","sourcesContent":["/*\n * Maintains navigation history across Capgo-controlled reloads when keepUrlPathAfterReload is enabled.\n */\n\nconst KEEP_FLAG_KEY = '__capgo_keep_url_path_after_reload';\nconst HISTORY_STORAGE_KEY = '__capgo_history_stack__';\nconst MAX_STACK_ENTRIES = 100;\n\nconst isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof history !== 'undefined';\n\nif (isBrowser) {\n const win = window as typeof window & {\n __capgoHistoryPatched?: boolean;\n __capgoKeepUrlPathAfterReload?: boolean;\n };\n\n if (!win.__capgoHistoryPatched) {\n win.__capgoHistoryPatched = true;\n\n const isFeatureConfigured = (): boolean => {\n try {\n if (win.__capgoKeepUrlPathAfterReload) {\n return true;\n }\n } catch {\n // ignore access issues\n }\n try {\n return window.localStorage.getItem(KEEP_FLAG_KEY) === '1';\n } catch {\n return false;\n }\n };\n\n type StoredHistory = { stack: string[]; index: number };\n\n const readStored = (): StoredHistory => {\n try {\n const raw = window.sessionStorage.getItem(HISTORY_STORAGE_KEY);\n if (!raw) {\n return { stack: [], index: -1 };\n }\n const parsed = JSON.parse(raw) as StoredHistory;\n if (!parsed || !Array.isArray(parsed.stack) || typeof parsed.index !== 'number') {\n return { stack: [], index: -1 };\n }\n return parsed;\n } catch {\n return { stack: [], index: -1 };\n }\n };\n\n const writeStored = (stack: string[], index: number): void => {\n try {\n window.sessionStorage.setItem(HISTORY_STORAGE_KEY, JSON.stringify({ stack, index }));\n } catch {\n // Storage might be unavailable; fail silently.\n }\n };\n\n const clearStored = (): void => {\n try {\n window.sessionStorage.removeItem(HISTORY_STORAGE_KEY);\n } catch {\n // ignore\n }\n };\n\n const normalize = (url?: string | URL | null): string | null => {\n try {\n const base = url ?? window.location.href;\n const parsed = new URL(base instanceof URL ? base.toString() : base, window.location.href);\n return `${parsed.pathname}${parsed.search}${parsed.hash}`;\n } catch {\n return null;\n }\n };\n\n const trimStack = (stack: string[], index: number): StoredHistory => {\n if (stack.length <= MAX_STACK_ENTRIES) {\n return { stack, index };\n }\n const start = stack.length - MAX_STACK_ENTRIES;\n const trimmed = stack.slice(start);\n const adjustedIndex = Math.max(0, index - start);\n return { stack: trimmed, index: adjustedIndex };\n };\n\n const runWhenReady = (fn: () => void): void => {\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n fn();\n } else {\n window.addEventListener('DOMContentLoaded', fn, { once: true });\n }\n };\n\n let featureActive = false;\n let isRestoring = false;\n let restoreScheduled = false;\n\n const ensureCurrentTracked = () => {\n if (!featureActive) {\n return;\n }\n const stored = readStored();\n const current = normalize();\n if (!current) {\n return;\n }\n if (stored.stack.length === 0) {\n stored.stack.push(current);\n stored.index = 0;\n writeStored(stored.stack, stored.index);\n return;\n }\n if (stored.index < 0 || stored.index >= stored.stack.length) {\n stored.index = stored.stack.length - 1;\n }\n if (stored.stack[stored.index] !== current) {\n stored.stack[stored.index] = current;\n writeStored(stored.stack, stored.index);\n }\n };\n\n const record = (url: string | URL | null | undefined, replace: boolean) => {\n if (!featureActive || isRestoring) {\n return;\n }\n const normalized = normalize(url);\n if (!normalized) {\n return;\n }\n let { stack, index } = readStored();\n if (stack.length === 0) {\n stack.push(normalized);\n index = stack.length - 1;\n } else if (replace) {\n if (index < 0 || index >= stack.length) {\n index = stack.length - 1;\n }\n stack[index] = normalized;\n } else {\n if (index >= stack.length - 1) {\n stack.push(normalized);\n index = stack.length - 1;\n } else {\n stack = stack.slice(0, index + 1);\n stack.push(normalized);\n index = stack.length - 1;\n }\n }\n ({ stack, index } = trimStack(stack, index));\n writeStored(stack, index);\n };\n\n const restoreHistory = () => {\n if (!featureActive || isRestoring) {\n return;\n }\n const stored = readStored();\n if (stored.stack.length === 0) {\n ensureCurrentTracked();\n return;\n }\n const targetIndex =\n stored.index >= 0 && stored.index < stored.stack.length ? stored.index : stored.stack.length - 1;\n const normalizedCurrent = normalize();\n if (stored.stack.length === 1 && normalizedCurrent === stored.stack[0]) {\n return;\n }\n const firstEntry = stored.stack[0];\n if (!firstEntry) {\n return;\n }\n isRestoring = true;\n try {\n history.replaceState(history.state, document.title, firstEntry);\n for (let i = 1; i < stored.stack.length; i += 1) {\n history.pushState(history.state, document.title, stored.stack[i]);\n }\n } catch {\n isRestoring = false;\n return;\n }\n isRestoring = false;\n const currentIndex = stored.stack.length - 1;\n const offset = targetIndex - currentIndex;\n if (offset !== 0) {\n history.go(offset);\n } else {\n history.replaceState(history.state, document.title, stored.stack[targetIndex]);\n window.dispatchEvent(new PopStateEvent('popstate'));\n }\n };\n\n const scheduleRestore = () => {\n if (!featureActive || restoreScheduled) {\n return;\n }\n restoreScheduled = true;\n runWhenReady(() => {\n restoreScheduled = false;\n restoreHistory();\n });\n };\n\n let originalPushState: typeof history.pushState | null = null;\n let originalReplaceState: typeof history.replaceState | null = null;\n\n const popstateHandler = () => {\n if (!featureActive || isRestoring) {\n return;\n }\n const normalized = normalize();\n if (!normalized) {\n return;\n }\n const stored = readStored();\n const idx = stored.stack.lastIndexOf(normalized);\n if (idx >= 0) {\n stored.index = idx;\n } else {\n stored.stack.push(normalized);\n stored.index = stored.stack.length - 1;\n }\n const trimmed = trimStack(stored.stack, stored.index);\n writeStored(trimmed.stack, trimmed.index);\n };\n\n const patchHistory = () => {\n if (originalPushState && originalReplaceState) {\n return;\n }\n originalPushState = history.pushState;\n originalReplaceState = history.replaceState;\n\n history.pushState = function pushStatePatched(state: any, title: string, url?: string | URL | null) {\n const result = originalPushState?.call(history, state, title, url as any);\n record(url, false);\n return result;\n };\n\n history.replaceState = function replaceStatePatched(state: any, title: string, url?: string | URL | null) {\n const result = originalReplaceState?.call(history, state, title, url as any);\n record(url, true);\n return result;\n };\n\n window.addEventListener('popstate', popstateHandler);\n };\n\n const unpatchHistory = () => {\n if (originalPushState) {\n history.pushState = originalPushState;\n originalPushState = null;\n }\n if (originalReplaceState) {\n history.replaceState = originalReplaceState;\n originalReplaceState = null;\n }\n window.removeEventListener('popstate', popstateHandler);\n };\n\n const setFeatureActive = (enabled: boolean) => {\n if (featureActive === enabled) {\n if (featureActive) {\n ensureCurrentTracked();\n scheduleRestore();\n }\n return;\n }\n featureActive = enabled;\n if (featureActive) {\n patchHistory();\n ensureCurrentTracked();\n scheduleRestore();\n } else {\n unpatchHistory();\n clearStored();\n }\n };\n\n window.addEventListener('CapacitorUpdaterKeepUrlPathAfterReload', (event) => {\n const evt = event as CustomEvent<{ enabled?: boolean }>;\n const enabled = evt?.detail?.enabled;\n if (typeof enabled === 'boolean') {\n win.__capgoKeepUrlPathAfterReload = enabled;\n setFeatureActive(enabled);\n } else {\n win.__capgoKeepUrlPathAfterReload = true;\n setFeatureActive(true);\n }\n });\n\n setFeatureActive(isFeatureConfigured());\n }\n}\n\nexport {};\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -19,13 +19,13 @@ if (isBrowser) {
|
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
catch (
|
|
22
|
+
catch (_a) {
|
|
23
23
|
// ignore access issues
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
26
|
return window.localStorage.getItem(KEEP_FLAG_KEY) === '1';
|
|
27
27
|
}
|
|
28
|
-
catch (
|
|
28
|
+
catch (_b) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -41,7 +41,7 @@ if (isBrowser) {
|
|
|
41
41
|
}
|
|
42
42
|
return parsed;
|
|
43
43
|
}
|
|
44
|
-
catch (
|
|
44
|
+
catch (_a) {
|
|
45
45
|
return { stack: [], index: -1 };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -49,7 +49,7 @@ if (isBrowser) {
|
|
|
49
49
|
try {
|
|
50
50
|
window.sessionStorage.setItem(HISTORY_STORAGE_KEY, JSON.stringify({ stack, index }));
|
|
51
51
|
}
|
|
52
|
-
catch (
|
|
52
|
+
catch (_a) {
|
|
53
53
|
// Storage might be unavailable; fail silently.
|
|
54
54
|
}
|
|
55
55
|
};
|
|
@@ -57,7 +57,7 @@ if (isBrowser) {
|
|
|
57
57
|
try {
|
|
58
58
|
window.sessionStorage.removeItem(HISTORY_STORAGE_KEY);
|
|
59
59
|
}
|
|
60
|
-
catch (
|
|
60
|
+
catch (_a) {
|
|
61
61
|
// ignore
|
|
62
62
|
}
|
|
63
63
|
};
|
|
@@ -67,7 +67,7 @@ if (isBrowser) {
|
|
|
67
67
|
const parsed = new URL(base instanceof URL ? base.toString() : base, window.location.href);
|
|
68
68
|
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
69
69
|
}
|
|
70
|
-
catch (
|
|
70
|
+
catch (_a) {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
@@ -172,7 +172,7 @@ if (isBrowser) {
|
|
|
172
172
|
history.pushState(history.state, document.title, stored.stack[i]);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
catch (
|
|
175
|
+
catch (_a) {
|
|
176
176
|
isRestoring = false;
|
|
177
177
|
return;
|
|
178
178
|
}
|