diff --git a/www/js/accounts.js b/www/js/accounts.js index 41e0bdb..0179aa7 100644 --- a/www/js/accounts.js +++ b/www/js/accounts.js @@ -33,6 +33,15 @@ function saveaccounts(accounts) { NativeStorage.setItem("accounts", JSON.stringify(accounts)); } +function recoveraccounts(callback) { + NativeStorage.getItem("accounts", function (data) { + localStorage.setItem("accounts", data); + callback(true); + }, function () { + callback(false); + }); +} + /** * Switch to a different account. * @param {int} account The selected account index from localStorage.getItem('accounts') diff --git a/www/js/app.js b/www/js/app.js index 1fe914b..fabb41b 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -204,7 +204,6 @@ function displayNotifications(callback) { $.post(localStorage.getItem("syncurl"), { username: localStorage.getItem("username"), key: localStorage.getItem("key"), - password: localStorage.getItem("password"), action: "checknotifications" }, function (data) { if (data.status === 'OK') { @@ -312,11 +311,19 @@ document.addEventListener("deviceready", function () { minimumFetchInterval: 1, stopOnTerminate: false, startOnBoot: true, - forceReload: true + forceReload: false, + enableHeadless: true }); }); } else { - openscreen("setup1"); + // Try to recover data from NativeStorage back to localStorage + recoveraccounts(function (ok) { + if (ok) { + restartApplication(); + } else { + openscreen("setup1"); + } + }) } setTimeout(navigator.splashscreen.hide, 500); }, false); \ No newline at end of file diff --git a/www/views/addotp.html b/www/views/addotp.html index 2f26a3b..bc68b75 100644 --- a/www/views/addotp.html +++ b/www/views/addotp.html @@ -75,6 +75,7 @@ keys.push({"secret": key, "label": label, "issuer": issuer}); localStorage.setItem("otp", JSON.stringify(keys)); + NativeStorage.setItem("otp", JSON.stringify(keys)); navigator.notification.alert("2-factor key saved.", null, "Key added", 'Dismiss'); openscreen("otp"); } diff --git a/www/views/otp.html b/www/views/otp.html index 4ce8ddd..cac410f 100644 --- a/www/views/otp.html +++ b/www/views/otp.html @@ -26,27 +26,39 @@ var totp = new jsOTP.totp(); - var ls_text = localStorage.getItem("otp"); - var keys = []; - if (ls_text !== null && ls_text != "") { - var keys = JSON.parse(ls_text || "[]"); - if (keys.length > 0) { - $("#nokeys").css("display", "none"); - } - for (var i = 0; i < keys.length; i++) { - var code = totp.getOtp(keys[i]["secret"]); - // Escape HTML characters - var label = $('
').html(keys[i]["label"]).html(); - var issuer = $('').text(keys[i]["issuer"]).html(); - $("#codelist").append("" + label + "
" - + "" + issuer + "
" - + "" + label + "
" + + "" + issuer + "
" + + "