mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-23 00:05:22 +03:00
Cleaning up some errors in the javascript console before I start adding new ones. src/js/ConfigStorage.js: forgot to test writing multiple keys at once, can now write multiple keys at once. src/js/FirmwareCache.js: avoid throwing an error if someone comes asking for an undefined firmware src/js/jenkins_loader.js: same .error deprecation as #1568
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// idea here is to abstract around the use of chrome.storage.local as it functions differently from "localStorage" and IndexedDB
|
|
// localStorage deals with strings, not objects, so the objects have been serialized.
|
|
var ConfigStorage = {
|
|
// key can be one string, or array of strings
|
|
get: function(key, callback) {
|
|
if (GUI.isChromeApp()) {
|
|
chrome.storage.local.get(key,callback);
|
|
} else {
|
|
//console.log('Abstraction.get',key);
|
|
if (Array.isArray(key)) {
|
|
var obj = {};
|
|
key.forEach(function (element) {
|
|
try {
|
|
obj = {...obj, ...JSON.parse(window.localStorage.getItem(element))};
|
|
} catch (e) {
|
|
// is okay
|
|
}
|
|
});
|
|
callback(obj);
|
|
} else {
|
|
var keyValue = window.localStorage.getItem(key);
|
|
if (keyValue) {
|
|
var obj = {};
|
|
try {
|
|
obj = JSON.parse(keyValue);
|
|
} catch (e) {
|
|
// It's fine if we fail that parse
|
|
}
|
|
callback(obj);
|
|
} else {
|
|
callback({});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// set takes an object like {'userLanguageSelect':'DEFAULT'}
|
|
set: function(input) {
|
|
if (GUI.isChromeApp()) {
|
|
chrome.storage.local.set(input);
|
|
} else {
|
|
//console.log('Abstraction.set',input);
|
|
Object.keys(input).forEach(function (element) {
|
|
var tmpObj = {};
|
|
tmpObj[element] = input[element];
|
|
window.localStorage.setItem(element, JSON.stringify(tmpObj));
|
|
});
|
|
}
|
|
}
|
|
}
|