Fix some issues with NativeStorage -> LocalStorage recovery

master
Skylar Ittner 2 years ago
parent 6e6a155214
commit 7aabdff33d

@ -162,18 +162,24 @@ function initCordova() {
try {
// Detect if localStorage is gone and try to restore it from NativeStorage plugin
if (getStorage("syncstateversion") == null || getStorage("syncstateversion") == 0) {
console.log("LocalStorage syncstateversion is null or zero, restoring from NativeStorage");
// This shouldn't cause issues if updating from an old version without localstorageok
// because values that only exist in LocalStorage won't be overwritten
if (!inStorage("localstorageok")) {
console.log("LocalStorage key localstorageok isn't present, copying NativeStorage over LocalStorage");
// "restore" localStorage
copyNativeStorageToLocalStorage();
// give it some arbitrary amount of time because I'm too lazy to do real async
setTimeout(function () {
loadSettings();
}, 60 * 1000);
setStorage("localstorageok", "true");
}, 10 * 1000);
} else {
// "back up" localStorage
console.log("Backing up LocalStorage");
setStorage("localstorageok", "true");
copyLocalStorageToNativeStorage();
}
} catch (ex) {
// Well we tried
console.error(ex);

Loading…
Cancel
Save