diff --git a/www/assets/js/main.js b/www/assets/js/main.js index c79fb04..a43b70c 100644 --- a/www/assets/js/main.js +++ b/www/assets/js/main.js @@ -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); diff --git a/www/assets/js/platform.js b/www/assets/js/platform.js index 0971afc..eb76c41 100644 --- a/www/assets/js/platform.js +++ b/www/assets/js/platform.js @@ -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 diff --git a/www/assets/js/storage.js b/www/assets/js/storage.js index d29e77e..e69fd90 100644 --- a/www/assets/js/storage.js +++ b/www/assets/js/storage.js @@ -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]); } }); } \ No newline at end of file