@capgo/capacitor-updater 7.51.19 → 7.51.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/CapacitorUpdaterPlugin.java +3 -3
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +202 -35
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +12 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +4 -4
- 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/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 = "7.51.
|
|
149
|
+
private final String pluginVersion = "7.51.21";
|
|
150
150
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
151
151
|
|
|
152
152
|
private SharedPreferences.Editor editor;
|
|
@@ -4783,8 +4783,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
4783
4783
|
final String messageUpdate = initialDirectUpdateAllowed
|
|
4784
4784
|
? "Update will occur now."
|
|
4785
4785
|
: this.shouldAutoSetNextBundle()
|
|
4786
|
-
|
|
4787
|
-
|
|
4786
|
+
? "Update will occur next time app moves to background."
|
|
4787
|
+
: "Update will be downloaded and made available.";
|
|
4788
4788
|
Thread newTask = startNewThread(() -> {
|
|
4789
4789
|
if (CapacitorUpdaterPlugin.this.shouldBlockAutoUpdateForPreviewSession()) {
|
|
4790
4790
|
CapacitorUpdaterPlugin.this.clearBackgroundDownloadState();
|
|
@@ -14,6 +14,7 @@ import androidx.work.WorkerParameters;
|
|
|
14
14
|
import java.io.*;
|
|
15
15
|
import java.io.FileInputStream;
|
|
16
16
|
import java.net.HttpURLConnection;
|
|
17
|
+
import java.net.MalformedURLException;
|
|
17
18
|
import java.net.URL;
|
|
18
19
|
import java.nio.channels.FileChannel;
|
|
19
20
|
import java.security.MessageDigest;
|
|
@@ -30,6 +31,8 @@ import java.util.concurrent.Future;
|
|
|
30
31
|
import java.util.concurrent.TimeUnit;
|
|
31
32
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
32
33
|
import java.util.concurrent.atomic.AtomicLong;
|
|
34
|
+
import java.util.function.BooleanSupplier;
|
|
35
|
+
import java.util.function.LongConsumer;
|
|
33
36
|
import okhttp3.Call;
|
|
34
37
|
import okhttp3.Callback;
|
|
35
38
|
import okhttp3.Dispatcher;
|
|
@@ -47,6 +50,41 @@ import org.json.JSONObject;
|
|
|
47
50
|
|
|
48
51
|
public class DownloadService extends Worker {
|
|
49
52
|
|
|
53
|
+
static final class DownloadRetryException extends RuntimeException {
|
|
54
|
+
|
|
55
|
+
DownloadRetryException(String message) {
|
|
56
|
+
super(message);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
DownloadRetryException(String message, Throwable cause) {
|
|
60
|
+
super(message, cause);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static final class ZipWritePlan {
|
|
65
|
+
|
|
66
|
+
final int statusCode;
|
|
67
|
+
final long writeOffset;
|
|
68
|
+
|
|
69
|
+
ZipWritePlan(int statusCode, long writeOffset) {
|
|
70
|
+
this.statusCode = statusCode;
|
|
71
|
+
this.writeOffset = writeOffset;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static final class ContentRangeInfo {
|
|
76
|
+
|
|
77
|
+
final long start;
|
|
78
|
+
final long end;
|
|
79
|
+
final long total;
|
|
80
|
+
|
|
81
|
+
ContentRangeInfo(long start, long end, long total) {
|
|
82
|
+
this.start = start;
|
|
83
|
+
this.end = end;
|
|
84
|
+
this.total = total;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
50
88
|
private static Logger logger;
|
|
51
89
|
|
|
52
90
|
public static void setLogger(Logger loggerInstance) {
|
|
@@ -389,6 +427,11 @@ public class DownloadService extends Worker {
|
|
|
389
427
|
handleSingleFileDownload(url, id, documentsDir, dest, version, sessionKey, checksum);
|
|
390
428
|
return createSuccessResult(dest, version, sessionKey, checksum, false);
|
|
391
429
|
}
|
|
430
|
+
} catch (DownloadRetryException e) {
|
|
431
|
+
if (logger != null) {
|
|
432
|
+
logger.debug("Download will retry: " + e.getMessage());
|
|
433
|
+
}
|
|
434
|
+
return Result.retry();
|
|
392
435
|
} catch (Exception e) {
|
|
393
436
|
return createFailureResult(e.getMessage());
|
|
394
437
|
}
|
|
@@ -652,7 +695,6 @@ public class DownloadService extends Worker {
|
|
|
652
695
|
|
|
653
696
|
HttpURLConnection httpConn = null;
|
|
654
697
|
InputStream inputStream = null;
|
|
655
|
-
FileOutputStream outputStream = null;
|
|
656
698
|
BufferedReader reader = null;
|
|
657
699
|
BufferedWriter writer = null;
|
|
658
700
|
|
|
@@ -689,6 +731,10 @@ public class DownloadService extends Worker {
|
|
|
689
731
|
clearDownloadData(documentsDir, id);
|
|
690
732
|
}
|
|
691
733
|
|
|
734
|
+
if (isStopped()) {
|
|
735
|
+
throw new DownloadRetryException("download_stopped");
|
|
736
|
+
}
|
|
737
|
+
|
|
692
738
|
if (downloadedBytes > 0) {
|
|
693
739
|
httpConn.setRequestProperty("Range", "bytes=" + downloadedBytes + "-");
|
|
694
740
|
}
|
|
@@ -696,7 +742,13 @@ public class DownloadService extends Worker {
|
|
|
696
742
|
int responseCode = httpConn.getResponseCode();
|
|
697
743
|
|
|
698
744
|
if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_PARTIAL) {
|
|
699
|
-
|
|
745
|
+
ZipWritePlan writePlan = planZipResumeWrite(responseCode, downloadedBytes, httpConn.getHeaderField("Content-Range"));
|
|
746
|
+
long responseBodyLength = httpConn.getContentLength();
|
|
747
|
+
long contentLength = shouldAppendHttpBody(writePlan.statusCode, writePlan.writeOffset)
|
|
748
|
+
? responseBodyLength >= 0
|
|
749
|
+
? responseBodyLength + writePlan.writeOffset
|
|
750
|
+
: -1
|
|
751
|
+
: responseBodyLength;
|
|
700
752
|
|
|
701
753
|
// Check if we have enough space for the actual file
|
|
702
754
|
if (contentLength > 0 && availableSpace < contentLength * 2) {
|
|
@@ -705,44 +757,36 @@ public class DownloadService extends Worker {
|
|
|
705
757
|
|
|
706
758
|
try {
|
|
707
759
|
inputStream = httpConn.getInputStream();
|
|
708
|
-
outputStream = new FileOutputStream(tempFile, downloadedBytes > 0);
|
|
709
760
|
|
|
710
|
-
if (downloadedBytes == 0) {
|
|
761
|
+
if (writePlan.writeOffset == 0 && downloadedBytes == 0) {
|
|
711
762
|
writer = new BufferedWriter(new FileWriter(infoFile));
|
|
712
763
|
writer.write(String.valueOf(version));
|
|
713
764
|
writer.close();
|
|
714
765
|
writer = null;
|
|
715
766
|
}
|
|
716
767
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
// Flush every 1MB to ensure progress is saved
|
|
726
|
-
if (downloadedBytes % (1024 * 1024) == 0) {
|
|
727
|
-
outputStream.flush();
|
|
768
|
+
final int[] lastNotifiedPercent = { 0 };
|
|
769
|
+
final long totalContentLength = contentLength;
|
|
770
|
+
String contentRangeHeader = httpConn.getHeaderField("Content-Range");
|
|
771
|
+
writeHttpBody(tempFile, inputStream, writePlan.statusCode, writePlan.writeOffset, this::isStopped, (written) -> {
|
|
772
|
+
int percent = calcTotalPercent(written, totalContentLength);
|
|
773
|
+
if (percent >= lastNotifiedPercent[0] + 10) {
|
|
774
|
+
lastNotifiedPercent[0] = (percent / 10) * 10;
|
|
775
|
+
setProgress(lastNotifiedPercent[0]);
|
|
728
776
|
}
|
|
729
|
-
|
|
730
|
-
// Computing percentage
|
|
731
|
-
int percent = calcTotalPercent(downloadedBytes, contentLength);
|
|
732
|
-
if (percent >= lastNotifiedPercent + 10) {
|
|
733
|
-
lastNotifiedPercent = (percent / 10) * 10;
|
|
734
|
-
setProgress(lastNotifiedPercent);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// Final flush
|
|
739
|
-
outputStream.flush();
|
|
740
|
-
outputStream.close();
|
|
741
|
-
outputStream = null;
|
|
777
|
+
});
|
|
742
778
|
|
|
743
779
|
inputStream.close();
|
|
744
780
|
inputStream = null;
|
|
745
781
|
|
|
782
|
+
validateZipDownloadComplete(
|
|
783
|
+
tempFile,
|
|
784
|
+
writePlan.statusCode,
|
|
785
|
+
contentRangeHeader,
|
|
786
|
+
writePlan.writeOffset,
|
|
787
|
+
responseBodyLength
|
|
788
|
+
);
|
|
789
|
+
|
|
746
790
|
// Rename the temp file with the final name (dest)
|
|
747
791
|
if (!tempFile.renameTo(new File(documentsDir, dest))) {
|
|
748
792
|
throw new RuntimeException("Failed to rename temp file to final destination");
|
|
@@ -756,13 +800,12 @@ public class DownloadService extends Worker {
|
|
|
756
800
|
// Try to free some memory
|
|
757
801
|
System.gc();
|
|
758
802
|
throw new RuntimeException("low_mem_fail");
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
try {
|
|
763
|
-
outputStream.close();
|
|
764
|
-
} catch (Exception ignored) {}
|
|
803
|
+
} catch (IOException e) {
|
|
804
|
+
if ("download_stopped".equals(e.getMessage())) {
|
|
805
|
+
throw new DownloadRetryException("download_stopped", e);
|
|
765
806
|
}
|
|
807
|
+
throw new DownloadRetryException(e.getMessage(), e);
|
|
808
|
+
} finally {
|
|
766
809
|
if (inputStream != null) {
|
|
767
810
|
try {
|
|
768
811
|
inputStream.close();
|
|
@@ -774,10 +817,14 @@ public class DownloadService extends Worker {
|
|
|
774
817
|
} catch (Exception ignored) {}
|
|
775
818
|
}
|
|
776
819
|
}
|
|
820
|
+
} else if (isRetryableHttpStatus(responseCode)) {
|
|
821
|
+
throw new DownloadRetryException("HTTP error: " + responseCode);
|
|
777
822
|
} else {
|
|
778
823
|
infoFile.delete();
|
|
779
824
|
throw new RuntimeException("HTTP error: " + responseCode);
|
|
780
825
|
}
|
|
826
|
+
} catch (DownloadRetryException e) {
|
|
827
|
+
throw e;
|
|
781
828
|
} catch (OutOfMemoryError e) {
|
|
782
829
|
logger.error("Critical memory error: " + e.getMessage());
|
|
783
830
|
System.gc(); // Suggest garbage collection
|
|
@@ -785,6 +832,12 @@ public class DownloadService extends Worker {
|
|
|
785
832
|
} catch (SecurityException e) {
|
|
786
833
|
logger.error("Security error during download: " + e.getMessage());
|
|
787
834
|
throw new RuntimeException("security_error: " + e.getMessage());
|
|
835
|
+
} catch (MalformedURLException e) {
|
|
836
|
+
logger.error("Invalid download URL: " + e.getMessage());
|
|
837
|
+
throw new RuntimeException("invalid_url: " + e.getMessage());
|
|
838
|
+
} catch (IOException e) {
|
|
839
|
+
logger.error("Download error: " + e.getMessage());
|
|
840
|
+
throw new DownloadRetryException(e.getMessage(), e);
|
|
788
841
|
} catch (Exception e) {
|
|
789
842
|
logger.error("Download error: " + e.getMessage());
|
|
790
843
|
throw new RuntimeException(e.getMessage());
|
|
@@ -798,6 +851,93 @@ public class DownloadService extends Worker {
|
|
|
798
851
|
}
|
|
799
852
|
}
|
|
800
853
|
|
|
854
|
+
static boolean isRetryableHttpStatus(int responseCode) {
|
|
855
|
+
return responseCode >= 500 || responseCode == 408 || responseCode == 429;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
static long parseContentRangeStart(String contentRange) {
|
|
859
|
+
ContentRangeInfo range = parseContentRange(contentRange);
|
|
860
|
+
return range == null ? -1 : range.start;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
static ContentRangeInfo parseContentRange(String contentRange) {
|
|
864
|
+
if (contentRange == null || contentRange.isEmpty()) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
String trimmed = contentRange.trim();
|
|
868
|
+
if (!trimmed.startsWith("bytes ")) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
int slash = trimmed.indexOf('/');
|
|
872
|
+
if (slash < 0) {
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
int dash = trimmed.indexOf('-', 6);
|
|
876
|
+
if (dash < 0 || dash >= slash) {
|
|
877
|
+
return null;
|
|
878
|
+
}
|
|
879
|
+
try {
|
|
880
|
+
long start = Long.parseLong(trimmed.substring(6, dash).trim());
|
|
881
|
+
long end = Long.parseLong(trimmed.substring(dash + 1, slash).trim());
|
|
882
|
+
String totalPart = trimmed.substring(slash + 1).trim();
|
|
883
|
+
long total = "*".equals(totalPart) ? -1 : Long.parseLong(totalPart);
|
|
884
|
+
if (end < start) {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
return new ContentRangeInfo(start, end, total);
|
|
888
|
+
} catch (NumberFormatException e) {
|
|
889
|
+
return null;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
static void validateZipDownloadComplete(
|
|
894
|
+
File tempFile,
|
|
895
|
+
int responseCode,
|
|
896
|
+
String contentRangeHeader,
|
|
897
|
+
long writeOffset,
|
|
898
|
+
long responseBodyLength
|
|
899
|
+
) {
|
|
900
|
+
long fileLen = tempFile.length();
|
|
901
|
+
if (responseCode == HttpURLConnection.HTTP_PARTIAL) {
|
|
902
|
+
ContentRangeInfo range = parseContentRange(contentRangeHeader);
|
|
903
|
+
if (range == null || range.total < 0) {
|
|
904
|
+
throw new DownloadRetryException("unknown_content_range_total");
|
|
905
|
+
}
|
|
906
|
+
if (range.start != writeOffset) {
|
|
907
|
+
throw new DownloadRetryException("content_range_mismatch");
|
|
908
|
+
}
|
|
909
|
+
long advertisedSpan = range.end - range.start + 1;
|
|
910
|
+
long receivedSpan = fileLen - writeOffset;
|
|
911
|
+
if (receivedSpan != advertisedSpan) {
|
|
912
|
+
throw new DownloadRetryException("incomplete_content_range");
|
|
913
|
+
}
|
|
914
|
+
if (fileLen != range.total) {
|
|
915
|
+
throw new DownloadRetryException("incomplete_download");
|
|
916
|
+
}
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (responseBodyLength >= 0 && fileLen != responseBodyLength) {
|
|
920
|
+
throw new DownloadRetryException("incomplete_download");
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
static ZipWritePlan planZipResumeWrite(int responseCode, long downloadedBytes, String contentRange) {
|
|
925
|
+
if (responseCode == HttpURLConnection.HTTP_PARTIAL) {
|
|
926
|
+
long rangeStart = parseContentRangeStart(contentRange);
|
|
927
|
+
if (rangeStart == downloadedBytes) {
|
|
928
|
+
return new ZipWritePlan(HttpURLConnection.HTTP_PARTIAL, downloadedBytes);
|
|
929
|
+
}
|
|
930
|
+
if (rangeStart == 0) {
|
|
931
|
+
return new ZipWritePlan(HttpURLConnection.HTTP_OK, 0);
|
|
932
|
+
}
|
|
933
|
+
throw new DownloadRetryException("invalid_content_range");
|
|
934
|
+
}
|
|
935
|
+
if (responseCode == HttpURLConnection.HTTP_OK && downloadedBytes > 0) {
|
|
936
|
+
return new ZipWritePlan(HttpURLConnection.HTTP_OK, 0);
|
|
937
|
+
}
|
|
938
|
+
return new ZipWritePlan(responseCode, downloadedBytes);
|
|
939
|
+
}
|
|
940
|
+
|
|
801
941
|
private void clearDownloadData(String docDir, String id) {
|
|
802
942
|
File tempFile = new File(docDir, "temp_" + id + ".tmp");
|
|
803
943
|
File infoFile = new File(docDir, "update_" + id + ".dat");
|
|
@@ -995,17 +1135,44 @@ public class DownloadService extends Worker {
|
|
|
995
1135
|
}
|
|
996
1136
|
|
|
997
1137
|
static void writeHttpBody(File dest, InputStream body, int statusCode, long existingBytes) throws IOException {
|
|
1138
|
+
writeHttpBody(dest, body, statusCode, existingBytes, null, null);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
static void writeHttpBody(
|
|
1142
|
+
File dest,
|
|
1143
|
+
InputStream body,
|
|
1144
|
+
int statusCode,
|
|
1145
|
+
long existingBytes,
|
|
1146
|
+
BooleanSupplier shouldStop,
|
|
1147
|
+
LongConsumer onProgress
|
|
1148
|
+
) throws IOException {
|
|
1149
|
+
if (shouldStop != null && shouldStop.getAsBoolean()) {
|
|
1150
|
+
throw new IOException("download_stopped");
|
|
1151
|
+
}
|
|
998
1152
|
boolean append = shouldAppendHttpBody(statusCode, existingBytes);
|
|
999
1153
|
byte[] buffer = new byte[CryptoCipher.ioBufferBytes()];
|
|
1000
1154
|
try (FileOutputStream fos = new FileOutputStream(dest, append)) {
|
|
1001
1155
|
int n;
|
|
1002
1156
|
long written = append ? existingBytes : 0;
|
|
1003
|
-
while (
|
|
1157
|
+
while (true) {
|
|
1158
|
+
if (shouldStop != null && shouldStop.getAsBoolean()) {
|
|
1159
|
+
throw new IOException("download_stopped");
|
|
1160
|
+
}
|
|
1161
|
+
n = body.read(buffer);
|
|
1162
|
+
if (shouldStop != null && shouldStop.getAsBoolean()) {
|
|
1163
|
+
throw new IOException("download_stopped");
|
|
1164
|
+
}
|
|
1165
|
+
if (n == -1) {
|
|
1166
|
+
break;
|
|
1167
|
+
}
|
|
1004
1168
|
fos.write(buffer, 0, n);
|
|
1005
1169
|
written += n;
|
|
1006
1170
|
if (written % (1024 * 1024) == 0) {
|
|
1007
1171
|
fos.flush();
|
|
1008
1172
|
}
|
|
1173
|
+
if (onProgress != null) {
|
|
1174
|
+
onProgress.accept(written);
|
|
1175
|
+
}
|
|
1009
1176
|
}
|
|
1010
1177
|
fos.flush();
|
|
1011
1178
|
}
|
|
@@ -98,7 +98,18 @@ public class Logger {
|
|
|
98
98
|
this.level = options.level;
|
|
99
99
|
this.useSystemLog = options.useSystemLog;
|
|
100
100
|
this.labels.putAll(
|
|
101
|
-
Map.of(
|
|
101
|
+
Map.of(
|
|
102
|
+
LogLevel.silent,
|
|
103
|
+
"",
|
|
104
|
+
LogLevel.error,
|
|
105
|
+
"\uD83D\uDD34",
|
|
106
|
+
LogLevel.warn,
|
|
107
|
+
"\uD83D\uDFE0",
|
|
108
|
+
LogLevel.info,
|
|
109
|
+
"\uD83D\uDFE2",
|
|
110
|
+
LogLevel.debug,
|
|
111
|
+
"\uD83D\uDD0E"
|
|
112
|
+
)
|
|
102
113
|
);
|
|
103
114
|
|
|
104
115
|
if (options.labels != null) {
|
|
@@ -766,10 +766,10 @@ public class ShakeMenu implements ShakeDetector.Listener, ThreeFingerPinchDetect
|
|
|
766
766
|
latestMessage != null && !latestMessage.isEmpty()
|
|
767
767
|
? latestMessage
|
|
768
768
|
: latestError != null && !latestError.isEmpty()
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
769
|
+
? latestError
|
|
770
|
+
: latestKind != null && !latestKind.isEmpty()
|
|
771
|
+
? latestKind
|
|
772
|
+
: "server did not provide a message";
|
|
773
773
|
|
|
774
774
|
// Handle update errors first (before "no new version" check)
|
|
775
775
|
if (
|
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":"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,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AAa,KAAK,OAAO,EAAE,CAAC;gBAC9B,IAAI,aAAa,EAAE,CAAC;oBAClB,oBAAoB,EAAE,CAAC;oBACvB,eAAe,EAAE,CAAC;gBACpB,CAAC;gBACD,OAAO;YACT,CAAC;YACD,aAAa,GAAG,OAAO,CAAC;YACxB,IAAI,aAAa,EAAE,CAAC;gBAClB,YAAY,EAAE,CAAC;gBACf,oBAAoB,EAAE,CAAC;gBACvB,eAAe,EAAE,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,cAAc,EAAE,CAAC;gBACjB,WAAW,EAAE,CAAC;YAChB,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,wCAAwC,EAAE,CAAC,KAAK,EAAE,EAAE;;YAC1E,MAAM,GAAG,GAAG,KAA2C,CAAC;YACxD,MAAM,OAAO,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,0CAAE,OAAO,CAAC;YACrC,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 (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;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC,CAAC;QAIF,MAAM,UAAU,GAAG,GAAkB,EAAE;YACrC,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;gBAC/D,IAAI,CAAC,GAAG,EAAE,CAAC;oBACT,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE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AC,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
|
}
|