Use NativeStorage plugin as backup for localStorage data #60
This commit is contained in:
parent
18a49da6b0
commit
ee091277dd
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.netsyms.packagehelper",
|
"name": "com.netsyms.packagehelper",
|
||||||
"version": "1.6.3",
|
"version": "1.6.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -620,6 +620,12 @@
|
|||||||
"integrity": "sha512-jPvcwDx2/L5ZbVG69NT2xmlG1E+MljRxkdsFpgj/5aoaF4oPqxg44J/bYxJNWgQtGnRSRWoqCRmU7FgmmMNMxA==",
|
"integrity": "sha512-jPvcwDx2/L5ZbVG69NT2xmlG1E+MljRxkdsFpgj/5aoaF4oPqxg44J/bYxJNWgQtGnRSRWoqCRmU7FgmmMNMxA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"cordova-plugin-nativestorage": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/cordova-plugin-nativestorage/-/cordova-plugin-nativestorage-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-olg/BzYRk0NGbKQ5f7rf21RYQEyJI19CCZn6RpVMO9/kbRRFqae/6ixjDNy81dXSu2TQ42brjBddGe1Qpn5ViA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"cordova-plugin-powermanagement-netsyms": {
|
"cordova-plugin-powermanagement-netsyms": {
|
||||||
"version": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement#1cca6de3d8153b369cef147d7e1689272d0944f3",
|
"version": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement#1cca6de3d8153b369cef147d7e1689272d0944f3",
|
||||||
"from": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement"
|
"from": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement"
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
"phonegap-plugin-barcodescanner": {
|
"phonegap-plugin-barcodescanner": {
|
||||||
"ANDROID_SUPPORT_V4_VERSION": "27.+"
|
"ANDROID_SUPPORT_V4_VERSION": "27.+"
|
||||||
},
|
},
|
||||||
"cordova-plugin-velda-devicefeedback": {}
|
"cordova-plugin-velda-devicefeedback": {},
|
||||||
|
"cordova-plugin-nativestorage": {}
|
||||||
},
|
},
|
||||||
"platforms": [
|
"platforms": [
|
||||||
"browser",
|
"browser",
|
||||||
@ -51,6 +52,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cordova-ios": "^6.1.1",
|
"cordova-ios": "^6.1.1",
|
||||||
"cordova-plugin-inappbrowser": "^4.1.0",
|
"cordova-plugin-inappbrowser": "^4.1.0",
|
||||||
|
"cordova-plugin-nativestorage": "^2.3.2",
|
||||||
"cordova-plugin-velda-devicefeedback": "0.0.2",
|
"cordova-plugin-velda-devicefeedback": "0.0.2",
|
||||||
"phonegap-plugin-barcodescanner": "^8.1.0"
|
"phonegap-plugin-barcodescanner": "^8.1.0"
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,24 @@ router.on("routeChange", function (newRoute) {
|
|||||||
console.log("Info", "Navigating to ", newRoute.path);
|
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
|
// Set alert radius to 100 meters by default
|
||||||
if (getStorage("alertradius") == null) {
|
if (getStorage("alertradius") == null) {
|
||||||
setStorage("alertradius", 100);
|
setStorage("alertradius", 100);
|
||||||
@ -188,7 +206,6 @@ function setAnimations(enabled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyColorTheme();
|
loadSettings();
|
||||||
setAnimations();
|
|
||||||
|
|
||||||
router.navigate("/home");
|
router.navigate("/home");
|
@ -10,9 +10,10 @@ function logout() {
|
|||||||
"Are you sure you want to log out?",
|
"Are you sure you want to log out?",
|
||||||
"Log out?",
|
"Log out?",
|
||||||
function () {
|
function () {
|
||||||
localStorage.removeItem('password');
|
removeStorage('username');
|
||||||
localStorage.removeItem('username');
|
removeStorage('password');
|
||||||
localStorage.removeItem('lastsync');
|
removeStorage('lastsync');
|
||||||
|
removeStorage('syncstateversion');
|
||||||
restartApplication();
|
restartApplication();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,11 @@ function setStorage(key, value, nochangeupdate) {
|
|||||||
nochangeupdate = false;
|
nochangeupdate = false;
|
||||||
}
|
}
|
||||||
localStorage.setItem(key, value);
|
localStorage.setItem(key, value);
|
||||||
|
try {
|
||||||
|
NativeStorage.setItem(key, value);
|
||||||
|
} catch (ex) {
|
||||||
|
// skip
|
||||||
|
}
|
||||||
if (!nochangeupdate && !SETTINGS.synckeyblacklist.includes(key)) {
|
if (!nochangeupdate && !SETTINGS.synckeyblacklist.includes(key)) {
|
||||||
var version = getStorage("syncstateversion") == null ? 0 : getStorage("syncstateversion");
|
var version = getStorage("syncstateversion") == null ? 0 : getStorage("syncstateversion");
|
||||||
localStorage.setItem("syncstateversion", Number(version) + 1);
|
localStorage.setItem("syncstateversion", Number(version) + 1);
|
||||||
@ -41,6 +46,15 @@ function inStorage(key) {
|
|||||||
return localStorage.getItem(key) != null;
|
return localStorage.getItem(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erase the key and its value from the persistent storage.
|
||||||
|
* @param {string} key
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
|
function removeStorage(key) {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all item from persistent storage.
|
* Get all item from persistent storage.
|
||||||
* @returns {Array} [{key: "", value: ""},...]
|
* @returns {Array} [{key: "", value: ""},...]
|
||||||
@ -56,4 +70,22 @@ function getAllStorage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return all;
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyLocalStorageToNativeStorage() {
|
||||||
|
for (var key in localStorage) {
|
||||||
|
if (localStorage.hasOwnProperty(key)) {
|
||||||
|
NativeStorage.setItem(key, localStorage.getItem(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyNativeStorageToLocalStorage() {
|
||||||
|
NativeStorage.keys(function (keys) {
|
||||||
|
for (var key in keys) {
|
||||||
|
NativeStorage.getItem(key, function (val) {
|
||||||
|
localStorage.setItem(key, val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
@ -81,6 +81,7 @@ function syncNow(callback) {
|
|||||||
|
|
||||||
function loadSettings() {
|
function loadSettings() {
|
||||||
applyColorTheme();
|
applyColorTheme();
|
||||||
|
setAnimations();
|
||||||
|
|
||||||
if (platform_type == "cordova") {
|
if (platform_type == "cordova") {
|
||||||
if (getStorage("wakelock") == "true") {
|
if (getStorage("wakelock") == "true") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user