Fix some issues with NativeStorage -> LocalStorage recovery
This commit is contained in:
parent
6e6a155214
commit
7aabdff33d
@ -162,18 +162,24 @@ function initCordova() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Detect if localStorage is gone and try to restore it from NativeStorage plugin
|
// Detect if localStorage is gone and try to restore it from NativeStorage plugin
|
||||||
if (getStorage("syncstateversion") == null || getStorage("syncstateversion") == 0) {
|
// This shouldn't cause issues if updating from an old version without localstorageok
|
||||||
console.log("LocalStorage syncstateversion is null or zero, restoring from NativeStorage");
|
// 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
|
// "restore" localStorage
|
||||||
copyNativeStorageToLocalStorage();
|
copyNativeStorageToLocalStorage();
|
||||||
// give it some arbitrary amount of time because I'm too lazy to do real async
|
// give it some arbitrary amount of time because I'm too lazy to do real async
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}, 60 * 1000);
|
setStorage("localstorageok", "true");
|
||||||
|
}, 10 * 1000);
|
||||||
} else {
|
} else {
|
||||||
// "back up" localStorage
|
// "back up" localStorage
|
||||||
|
console.log("Backing up LocalStorage");
|
||||||
|
setStorage("localstorageok", "true");
|
||||||
copyLocalStorageToNativeStorage();
|
copyLocalStorageToNativeStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// Well we tried
|
// Well we tried
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user