Fix some issues with NativeStorage -> LocalStorage recovery

Skylar Ittner 2 years ago
parent a977851cff
commit 6e6a155214

@ -95,24 +95,6 @@ router.on("routeChange", function (newRoute) {
console.log("Info", "Navigating to ", newRoute.path);
});
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");
// "restore" localStorage
copyNativeStorageToLocalStorage();
// give it some arbitrary amount of time because I'm too lazy to do real async
setTimeout(function () {
loadSettings();
}, 60 * 1000);
} else {
// "back up" localStorage
copyLocalStorageToNativeStorage();
}
} catch (ex) {
// Well we tried
}
// Set alert radius to 100 meters by default
if (getStorage("alertradius") == null) {
setStorage("alertradius", 100);

@ -160,6 +160,25 @@ function initCordova() {
document.addEventListener("backbutton", handleBackButton, false);
document.addEventListener("deviceready", function () {
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");
// "restore" localStorage
copyNativeStorageToLocalStorage();
// give it some arbitrary amount of time because I'm too lazy to do real async
setTimeout(function () {
loadSettings();
}, 60 * 1000);
} else {
// "back up" localStorage
copyLocalStorageToNativeStorage();
}
} catch (ex) {
// Well we tried
console.error(ex);
}
loadSettings();
// Make sure the status bar color is set properly

@ -82,10 +82,12 @@ function copyLocalStorageToNativeStorage() {
function copyNativeStorageToLocalStorage() {
NativeStorage.keys(function (keys) {
for (var key in keys) {
NativeStorage.getItem(key, function (val) {
localStorage.setItem(key, val);
});
for (var i = 0; i < keys.length; i++) {
(function (key) {
NativeStorage.getItem(key, function (val) {
localStorage.setItem(key, val);
});
})(keys[i]);
}
});
}
Loading…
Cancel
Save