Merge pull request #2636 from haslinghuis/remove_chrome_storage
[chore] migrate remaining deprecated chrome storage API calls to ConfigStorage JSON implementation.10.8-maintenance
commit
ee3ddc197e
|
@ -4,7 +4,7 @@
|
|||
// localStorage deals with strings, not objects, so the objects have been serialized.
|
||||
const ConfigStorage = {
|
||||
// key can be one string, or array of strings
|
||||
get: function(key, callback) {
|
||||
get: function(key) {
|
||||
let result = {};
|
||||
if (Array.isArray(key)) {
|
||||
key.forEach(function (element) {
|
||||
|
@ -14,7 +14,6 @@ const ConfigStorage = {
|
|||
// is okay
|
||||
}
|
||||
});
|
||||
callback?.(result);
|
||||
} else {
|
||||
const keyValue = window.localStorage.getItem(key);
|
||||
if (keyValue) {
|
||||
|
@ -23,9 +22,6 @@ const ConfigStorage = {
|
|||
} catch (e) {
|
||||
// It's fine if we fail that parse
|
||||
}
|
||||
callback?.(result);
|
||||
} else {
|
||||
callback?.(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,4 +35,7 @@ const ConfigStorage = {
|
|||
window.localStorage.setItem(element, JSON.stringify(tmpObj));
|
||||
});
|
||||
},
|
||||
remove: function(item) {
|
||||
window.localStorage.removeItem(item);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -44,19 +44,18 @@ let FirmwareCache = (function () {
|
|||
function persist(data) {
|
||||
let obj = {};
|
||||
obj[CACHEKEY] = data;
|
||||
chrome.storage.local.set(obj);
|
||||
ConfigStorage.set(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} callback
|
||||
*/
|
||||
function load(callback) {
|
||||
chrome.storage.local.get(CACHEKEY, obj => {
|
||||
const obj = ConfigStorage.get(CACHEKEY);
|
||||
let entries = typeof obj === "object" && obj.hasOwnProperty(CACHEKEY)
|
||||
? obj[CACHEKEY]
|
||||
: [];
|
||||
callback(entries);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -76,18 +75,14 @@ let FirmwareCache = (function () {
|
|||
}
|
||||
let key = oldest[0];
|
||||
let cacheKey = withCachePrefix(key);
|
||||
chrome.storage.local.get(cacheKey, obj => {
|
||||
const obj = ConfigStorage.get(cacheKey);
|
||||
/** @type {CacheItem} */
|
||||
let cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey)
|
||||
? obj[cacheKey]
|
||||
: null;
|
||||
const cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey) ? obj[cacheKey] : null;
|
||||
if (cached === null) {
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
chrome.storage.local.remove(cacheKey, () => {
|
||||
ConfigStorage.remove(cacheKey);
|
||||
onRemoveFromCache(cached.release);
|
||||
});
|
||||
});
|
||||
return oldest;
|
||||
};
|
||||
|
||||
|
@ -143,9 +138,8 @@ let FirmwareCache = (function () {
|
|||
release: release,
|
||||
hexdata: hexdata,
|
||||
};
|
||||
chrome.storage.local.set(obj, () => {
|
||||
ConfigStorage.set(obj);
|
||||
onPutToCache(release);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,13 +157,9 @@ let FirmwareCache = (function () {
|
|||
return;
|
||||
}
|
||||
let cacheKey = withCachePrefix(key);
|
||||
chrome.storage.local.get(cacheKey, obj => {
|
||||
/** @type {CacheItem} */
|
||||
let cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey)
|
||||
? obj[cacheKey]
|
||||
: null;
|
||||
const obj = ConfigStorage.get(cacheKey);
|
||||
const cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey) ? obj[cacheKey] : null;
|
||||
callback(cached);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,10 +174,11 @@ let FirmwareCache = (function () {
|
|||
for (let key of journal.keys()) {
|
||||
cacheKeys.push(withCachePrefix(key));
|
||||
}
|
||||
chrome.storage.local.get(cacheKeys, obj => {
|
||||
const obj = ConfigStorage.get(cacheKeys);
|
||||
if (typeof obj !== "object") {
|
||||
return;
|
||||
}
|
||||
console.log(obj.entries());
|
||||
for (let cacheKey of cacheKeys) {
|
||||
if (obj.hasOwnProperty(cacheKey)) {
|
||||
/** @type {CacheItem} */
|
||||
|
@ -195,8 +186,7 @@ let FirmwareCache = (function () {
|
|||
onRemoveFromCache(item.release);
|
||||
}
|
||||
}
|
||||
chrome.storage.local.remove(cacheKeys);
|
||||
});
|
||||
ConfigStorage.remove(cacheKeys);
|
||||
journal.clear();
|
||||
JournalStorage.persist(journal.toJSON());
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ const cordovaUI = {
|
|||
if (screenWidth > 575 && screenHeight > 575) {
|
||||
self.canChangeUI = false;
|
||||
}
|
||||
ConfigStorage.get('cordovaForceComputerUI', function (result) {
|
||||
const result = ConfigStorage.get('cordovaForceComputerUI');
|
||||
if (result.cordovaForceComputerUI === undefined) {
|
||||
if ((orientation === 'landscape' && screenHeight <= 575)
|
||||
|| (orientation === 'portrait' && screenWidth <= 575)) {
|
||||
|
@ -31,12 +31,11 @@ const cordovaUI = {
|
|||
ConfigStorage.set({'cordovaForceComputerUI': true});
|
||||
}
|
||||
}
|
||||
});
|
||||
self.set();
|
||||
},
|
||||
set: function() {
|
||||
const self = this;
|
||||
ConfigStorage.get('cordovaForceComputerUI', function (result) {
|
||||
const result = ConfigStorage.get('cordovaForceComputerUI');
|
||||
if (result.cordovaForceComputerUI) {
|
||||
window.screen.orientation.lock('landscape');
|
||||
$('body').css('zoom', self.uiZoom);
|
||||
|
@ -44,7 +43,6 @@ const cordovaUI = {
|
|||
window.screen.orientation.lock('portrait');
|
||||
$('body').css('zoom', 1);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -389,13 +389,12 @@ GuiControl.prototype.content_ready = function (callback) {
|
|||
};
|
||||
|
||||
GuiControl.prototype.selectDefaultTabWhenConnected = function() {
|
||||
ConfigStorage.get(['rememberLastTab', 'lastTab'], function (result) {
|
||||
const result = ConfigStorage.get(['rememberLastTab', 'lastTab']);
|
||||
if (result.rememberLastTab && result.lastTab) {
|
||||
$(`#tabs ul.mode-connected .${result.lastTab} a`).click();
|
||||
} else {
|
||||
$('#tabs ul.mode-connected .tab_setup a').click();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GuiControl.prototype.isNWJS = function () {
|
||||
|
|
|
@ -21,7 +21,7 @@ JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
|
|||
callback(jobs);
|
||||
};
|
||||
|
||||
chrome.storage.local.get([cacheLastUpdateTag, jobsDataTag], function (result) {
|
||||
const result = ConfigStorage.get([cacheLastUpdateTag, jobsDataTag]);
|
||||
const jobsDataTimestamp = $.now();
|
||||
const cachedJobsData = result[jobsDataTag];
|
||||
const cachedJobsLastUpdate = result[cacheLastUpdateTag];
|
||||
|
@ -49,7 +49,7 @@ JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
|
|||
const object = {};
|
||||
object[jobsDataTag] = jobs;
|
||||
object[cacheLastUpdateTag] = $.now();
|
||||
chrome.storage.local.set(object);
|
||||
ConfigStorage.set(object);
|
||||
|
||||
wrappedCallback(jobs);
|
||||
}).fail(xhr => {
|
||||
|
@ -59,7 +59,6 @@ JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
|
|||
} else {
|
||||
cachedCallback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
|
||||
|
@ -69,7 +68,7 @@ JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
|
|||
const buildsDataTag = `${jobUrl}BuildsData`;
|
||||
const cacheLastUpdateTag = `${jobUrl}BuildsLastUpdate`;
|
||||
|
||||
chrome.storage.local.get([cacheLastUpdateTag, buildsDataTag], function (result) {
|
||||
const result = ConfigStorage.get([cacheLastUpdateTag, buildsDataTag]);
|
||||
const buildsDataTimestamp = $.now();
|
||||
const cachedBuildsData = result[buildsDataTag];
|
||||
const cachedBuildsLastUpdate = result[cacheLastUpdateTag];
|
||||
|
@ -101,7 +100,7 @@ JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
|
|||
const object = {};
|
||||
object[buildsDataTag] = builds;
|
||||
object[cacheLastUpdateTag] = $.now();
|
||||
chrome.storage.local.set(object);
|
||||
ConfigStorage.set(object);
|
||||
|
||||
self._parseBuilds(jobUrl, jobName, builds, callback);
|
||||
}).fail(xhr => {
|
||||
|
@ -111,7 +110,6 @@ JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
|
|||
} else {
|
||||
cachedCallback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
JenkinsLoader.prototype._parseBuilds = function (jobUrl, jobName, builds, callback) {
|
||||
|
|
|
@ -190,22 +190,16 @@ i18n.localizePage = function(forceReTranslate) {
|
|||
* returns the current locale to the callback
|
||||
*/
|
||||
function getStoredUserLocale(cb) {
|
||||
if (typeof ConfigStorage !== 'undefined') {
|
||||
ConfigStorage.get('userLanguageSelect', function (result) {
|
||||
let userLanguage = 'DEFAULT';
|
||||
if (typeof ConfigStorage !== 'undefined') {
|
||||
const result = ConfigStorage.get('userLanguageSelect');
|
||||
if (result.userLanguageSelect) {
|
||||
userLanguage = result.userLanguageSelect;
|
||||
}
|
||||
i18n.selectedLanguage = userLanguage;
|
||||
|
||||
userLanguage = getValidLocale(userLanguage);
|
||||
|
||||
cb(userLanguage);
|
||||
});
|
||||
} else {
|
||||
const userLanguage = getValidLocale('DEFAULT');
|
||||
cb(userLanguage);
|
||||
}
|
||||
userLanguage = getValidLocale(userLanguage);
|
||||
cb(userLanguage);
|
||||
}
|
||||
|
||||
function getValidLocale(userLocale) {
|
||||
|
|
|
@ -45,14 +45,13 @@ function appReady() {
|
|||
function checkSetupAnalytics(callback) {
|
||||
if (!analytics) {
|
||||
setTimeout(function () {
|
||||
ConfigStorage.get(['userId', 'analyticsOptOut', 'checkForConfiguratorUnstableVersions' ], function (result) {
|
||||
const result = ConfigStorage.get(['userId', 'analyticsOptOut', 'checkForConfiguratorUnstableVersions' ]);
|
||||
if (!analytics) {
|
||||
setupAnalytics(result);
|
||||
}
|
||||
|
||||
callback(analytics);
|
||||
});
|
||||
});
|
||||
} else if (callback) {
|
||||
callback(analytics);
|
||||
}
|
||||
|
@ -499,13 +498,12 @@ function startProcess() {
|
|||
$(this).data('state', state);
|
||||
});
|
||||
|
||||
ConfigStorage.get('logopen', function (result) {
|
||||
let result = ConfigStorage.get('logopen');
|
||||
if (result.logopen) {
|
||||
$("#showlog").trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
ConfigStorage.get('permanentExpertMode', function (result) {
|
||||
result = ConfigStorage.get('permanentExpertMode');
|
||||
const expertModeCheckbox = 'input[name="expertModeCheckbox"]';
|
||||
if (result.permanentExpertMode) {
|
||||
$(expertModeCheckbox).prop('checked', true);
|
||||
|
@ -527,20 +525,18 @@ function startProcess() {
|
|||
});
|
||||
|
||||
$(expertModeCheckbox).trigger("change");
|
||||
});
|
||||
|
||||
ConfigStorage.get('cliAutoComplete', function (result) {
|
||||
CliAutoComplete.setEnabled(typeof result.cliAutoComplete == 'undefined' || result.cliAutoComplete); // On by default
|
||||
});
|
||||
result = ConfigStorage.get('cliAutoComplete');
|
||||
CliAutoComplete.setEnabled(typeof result.cliAutoComplete === undefined || result.cliAutoComplete); // On by default
|
||||
|
||||
ConfigStorage.get('darkTheme', function (result) {
|
||||
result = ConfigStorage.get('darkTheme');
|
||||
if (result.darkTheme === undefined || typeof result.darkTheme !== "number") {
|
||||
// sets dark theme to auto if not manually changed
|
||||
setDarkTheme(2);
|
||||
} else {
|
||||
setDarkTheme(result.darkTheme);
|
||||
}
|
||||
});
|
||||
|
||||
if (GUI.isCordova()) {
|
||||
let darkMode = false;
|
||||
const checkDarkMode = function() {
|
||||
|
@ -575,7 +571,7 @@ function checkForConfiguratorUpdates() {
|
|||
}
|
||||
|
||||
function notifyOutdatedVersion(releaseData) {
|
||||
ConfigStorage.get('checkForConfiguratorUnstableVersions', function (result) {
|
||||
const result = ConfigStorage.get('checkForConfiguratorUnstableVersions');
|
||||
let showUnstableReleases = false;
|
||||
if (result.checkForConfiguratorUnstableVersions) {
|
||||
showUnstableReleases = true;
|
||||
|
@ -620,7 +616,6 @@ function notifyOutdatedVersion(releaseData) {
|
|||
|
||||
dialog.showModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isExpertModeEnabled() {
|
||||
|
|
|
@ -32,9 +32,12 @@ PortHandler.initialize = function () {
|
|||
|
||||
PortHandler.check = function () {
|
||||
const self = this;
|
||||
let result;
|
||||
|
||||
ConfigStorage.get('showVirtualMode', res => self.showVirtualMode = res.showVirtualMode);
|
||||
ConfigStorage.get('showAllSerialDevices', res => self.showAllSerialDevices = res.showAllSerialDevices);
|
||||
result = ConfigStorage.get('showVirtualMode');
|
||||
self.showVirtualMode = result.showVirtualMode;
|
||||
result = ConfigStorage.get('showAllSerialDevices');
|
||||
self.showAllSerialDevices = result.showAllSerialDevices;
|
||||
|
||||
self.check_usb_devices();
|
||||
self.check_serial_devices();
|
||||
|
@ -168,7 +171,7 @@ PortHandler.detectPort = function(currentPorts) {
|
|||
currentPorts = self.updatePortSelect(currentPorts);
|
||||
console.log(`PortHandler - Found: ${JSON.stringify(newPorts)}`);
|
||||
|
||||
ConfigStorage.get('last_used_port', function (result) {
|
||||
const result = ConfigStorage.get('last_used_port');
|
||||
if (result.last_used_port) {
|
||||
if (result.last_used_port.includes('tcp')) {
|
||||
self.portPickerElement.val('manual');
|
||||
|
@ -178,7 +181,6 @@ PortHandler.detectPort = function(currentPorts) {
|
|||
self.selectPort(currentPorts);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
self.port_available = true;
|
||||
// Signal board verification
|
||||
|
|
|
@ -11,10 +11,11 @@ const ReleaseChecker = function (releaseName, releaseUrl) {
|
|||
|
||||
ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
|
||||
const self = this;
|
||||
chrome.storage.local.get([self._releaseLastUpdateTag, self._releaseDataTag], function (result) {
|
||||
const result = ConfigStorage.get([self._releaseLastUpdateTag, self._releaseDataTag]);
|
||||
const releaseDataTimestamp = $.now();
|
||||
const cacheReleaseData = result[self._releaseDataTag];
|
||||
const cachedReleaseLastUpdate = result[self._releaseLastUpdateTag];
|
||||
|
||||
if (!cacheReleaseData || !cachedReleaseLastUpdate || releaseDataTimestamp - cachedReleaseLastUpdate > 3600 * 1000) {
|
||||
$.get(self._releaseUrl, function (releaseData) {
|
||||
GUI.log(i18n.getMessage('releaseCheckLoaded',[self._releaseName]));
|
||||
|
@ -22,7 +23,7 @@ ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
|
|||
const data = {};
|
||||
data[self._releaseDataTag] = releaseData;
|
||||
data[self._releaseLastUpdateTag] = releaseDataTimestamp;
|
||||
chrome.storage.local.set(data, function () {});
|
||||
ConfigStorage.set(data);
|
||||
|
||||
self._processReleaseData(releaseData, processFunction);
|
||||
}).fail(function (data) {
|
||||
|
@ -41,7 +42,6 @@ ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
|
|||
|
||||
self._processReleaseData(cacheReleaseData, processFunction);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -33,16 +33,17 @@ function initializeSerialBackend() {
|
|||
ConfigStorage.set({'portOverride': $('#port-override').val()});
|
||||
});
|
||||
|
||||
ConfigStorage.get('portOverride', function (data) {
|
||||
const data = ConfigStorage.get('portOverride');
|
||||
if (data.portOverride) {
|
||||
$('#port-override').val(data.portOverride);
|
||||
});
|
||||
}
|
||||
|
||||
$('div#port-picker #port').change(function (target) {
|
||||
GUI.updateManualPortVisibility();
|
||||
});
|
||||
|
||||
$('div.connect_controls a.connect').click(function () {
|
||||
if (GUI.connect_lock != true) { // GUI control overrides the user control
|
||||
if (!GUI.connect_lock) { // GUI control overrides the user control
|
||||
|
||||
const toggleStatus = function() {
|
||||
clicks = !clicks;
|
||||
|
@ -113,7 +114,7 @@ function initializeSerialBackend() {
|
|||
});
|
||||
|
||||
// auto-connect
|
||||
ConfigStorage.get('auto_connect', function (result) {
|
||||
const result = ConfigStorage.get('auto_connect');
|
||||
if (result.auto_connect === undefined || result.auto_connect) {
|
||||
// default or enabled by user
|
||||
GUI.auto_connect = true;
|
||||
|
@ -130,7 +131,7 @@ function initializeSerialBackend() {
|
|||
$('input.auto_connect, span.auto_connect').prop('title', i18n.getMessage('autoConnectDisabled'));
|
||||
}
|
||||
|
||||
// bind UI hook to auto-connect checkbox
|
||||
// bind UI hook to auto-connect checkbos
|
||||
$('input.auto_connect').change(function () {
|
||||
GUI.auto_connect = $(this).is(':checked');
|
||||
|
||||
|
@ -147,7 +148,6 @@ function initializeSerialBackend() {
|
|||
|
||||
ConfigStorage.set({'auto_connect': GUI.auto_connect});
|
||||
});
|
||||
});
|
||||
|
||||
PortHandler.initialize();
|
||||
PortUsage.initialize();
|
||||
|
|
|
@ -540,7 +540,7 @@ TABS.auxiliary.initialize = function (callback) {
|
|||
}
|
||||
|
||||
let hideUnusedModes = false;
|
||||
ConfigStorage.get('hideUnusedModes', function (result) {
|
||||
const result = ConfigStorage.get('hideUnusedModes');
|
||||
$("input#switch-toggle-unused")
|
||||
.change(function() {
|
||||
hideUnusedModes = $(this).prop("checked");
|
||||
|
@ -549,7 +549,6 @@ TABS.auxiliary.initialize = function (callback) {
|
|||
})
|
||||
.prop("checked", !!result.hideUnusedModes)
|
||||
.change();
|
||||
});
|
||||
|
||||
// update ui instantly on first load
|
||||
update_ui();
|
||||
|
|
|
@ -158,12 +158,11 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
TABS.firmware_flasher.releases = builds;
|
||||
|
||||
ConfigStorage.get('selected_board', function (result) {
|
||||
result = ConfigStorage.get('selected_board');
|
||||
if (result.selected_board) {
|
||||
const boardBuilds = builds[result.selected_board];
|
||||
$('select[name="board"]').val(boardBuilds ? result.selected_board : 0).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function processBoardOptions(releaseData, showDevReleases) {
|
||||
|
@ -244,7 +243,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
if (builds && hasUnifiedTargetBuild(builds)) {
|
||||
console.log('loaded some builds for later');
|
||||
const storageTag = 'unifiedSourceCache';
|
||||
chrome.storage.local.get(storageTag, function (result) {
|
||||
result = ConfigStorage.get(storageTag);
|
||||
let storageObj = result[storageTag];
|
||||
if (!storageObj || !storageObj.lastUpdate || checkTime - storageObj.lastUpdate > expirationPeriod) {
|
||||
console.log('go get', unifiedSource);
|
||||
|
@ -255,7 +254,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
newDataObj.lastUpdate = checkTime;
|
||||
newDataObj.data = data;
|
||||
newStorageObj[storageTag] = newDataObj;
|
||||
chrome.storage.local.set(newStorageObj);
|
||||
ConfigStorage.set(newStorageObj);
|
||||
|
||||
parseUnifiedBuilds(data, builds);
|
||||
}).fail(xhr => {
|
||||
|
@ -267,7 +266,6 @@ firmware_flasher.initialize = function (callback) {
|
|||
console.log('unified config cached data', Math.floor((checkTime - storageObj.lastUpdate)/60), 'mins old');
|
||||
parseUnifiedBuilds(storageObj.data, builds);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
populateBoardOptions(builds);
|
||||
}
|
||||
|
@ -314,13 +312,12 @@ firmware_flasher.initialize = function (callback) {
|
|||
TABS.firmware_flasher.releases = releases;
|
||||
TABS.firmware_flasher.unifiedConfigs = unifiedConfigs;
|
||||
|
||||
ConfigStorage.get('selected_board', function (result) {
|
||||
result = ConfigStorage.get('selected_board');
|
||||
if (result.selected_board) {
|
||||
const boardReleases = TABS.firmware_flasher.unifiedConfigs[result.selected_board]
|
||||
|| TABS.firmware_flasher.releases[result.selected_board];
|
||||
$('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const buildTypes = [
|
||||
|
@ -416,7 +413,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
buildTypesToShow[build_type].loader();
|
||||
}
|
||||
|
||||
chrome.storage.local.set({'selected_build_type': build_type});
|
||||
ConfigStorage.set({'selected_build_type': build_type});
|
||||
});
|
||||
|
||||
function populateBuilds(builds, target, manufacturerId, duplicateName, targetVersions, callback) {
|
||||
|
@ -613,7 +610,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
const storageTag = 'unifiedConfigLast';
|
||||
const expirationPeriod = 3600; // One of your earth hours.
|
||||
const checkTime = Math.floor(Date.now() / 1000); // Lets deal in seconds.
|
||||
chrome.storage.local.get(storageTag, function (result) {
|
||||
result = ConfigStorage.get(storageTag);
|
||||
let storageObj = result[storageTag];
|
||||
const unifiedConfigList = TABS.firmware_flasher.unifiedConfigs[target];
|
||||
const manufacturerIds = Object.keys(unifiedConfigList);
|
||||
|
@ -656,7 +653,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
targetId: targetId,
|
||||
lastUpdate: checkTime,
|
||||
};
|
||||
chrome.storage.local.set(newStorageObj);
|
||||
ConfigStorage.set(newStorageObj);
|
||||
|
||||
populateBuilds(builds, target, manufacturerId, duplicateName, TABS.firmware_flasher.releases[bareBoard], processNext);
|
||||
});
|
||||
|
@ -684,7 +681,6 @@ firmware_flasher.initialize = function (callback) {
|
|||
};
|
||||
|
||||
processManufacturer(0);
|
||||
});
|
||||
} else {
|
||||
self.unifiedTarget = {};
|
||||
finishPopulatingBuilds();
|
||||
|
@ -894,7 +890,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
document.querySelector('select[name="board"]').addEventListener('change', updateDetectBoardButton);
|
||||
document.querySelector('select[name="firmware_version"]').addEventListener('change', updateDetectBoardButton);
|
||||
|
||||
ConfigStorage.get('erase_chip', function (result) {
|
||||
let result = ConfigStorage.get('erase_chip');
|
||||
if (result.erase_chip) {
|
||||
$('input.erase_chip').prop('checked', true);
|
||||
} else {
|
||||
|
@ -904,23 +900,19 @@ firmware_flasher.initialize = function (callback) {
|
|||
$('input.erase_chip').change(function () {
|
||||
ConfigStorage.set({'erase_chip': $(this).is(':checked')});
|
||||
}).change();
|
||||
});
|
||||
|
||||
chrome.storage.local.get('show_development_releases', function (result) {
|
||||
result = ConfigStorage.get('show_development_releases');
|
||||
$('input.show_development_releases')
|
||||
.prop('checked', result.show_development_releases)
|
||||
.change(function () {
|
||||
chrome.storage.local.set({'show_development_releases': $(this).is(':checked')});
|
||||
ConfigStorage.set({'show_development_releases': $(this).is(':checked')});
|
||||
}).change();
|
||||
|
||||
});
|
||||
|
||||
chrome.storage.local.get('selected_build_type', function (result) {
|
||||
result = ConfigStorage.get('selected_build_type');
|
||||
// ensure default build type is selected
|
||||
buildType_e.val(result.selected_build_type || 0).trigger('change');
|
||||
});
|
||||
|
||||
ConfigStorage.get('no_reboot_sequence', function (result) {
|
||||
result = ConfigStorage.get('no_reboot_sequence');
|
||||
if (result.no_reboot_sequence) {
|
||||
$('input.updating').prop('checked', true);
|
||||
$('.flash_on_connect_wrapper').show();
|
||||
|
@ -943,9 +935,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
|
||||
$('input.updating').change();
|
||||
});
|
||||
|
||||
ConfigStorage.get('flash_manual_baud', function (result) {
|
||||
result = ConfigStorage.get('flash_manual_baud');
|
||||
if (result.flash_manual_baud) {
|
||||
$('input.flash_manual_baud').prop('checked', true);
|
||||
} else {
|
||||
|
@ -959,9 +950,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
|
||||
$('input.flash_manual_baud').change();
|
||||
});
|
||||
|
||||
ConfigStorage.get('flash_manual_baud_rate', function (result) {
|
||||
result = ConfigStorage.get('flash_manual_baud_rate');
|
||||
$('#flash_manual_baud_rate').val(result.flash_manual_baud_rate);
|
||||
|
||||
// bind UI hook so the status is saved on change
|
||||
|
@ -971,7 +961,6 @@ firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
|
||||
$('input.flash_manual_baud_rate').change();
|
||||
});
|
||||
|
||||
// UI Hooks
|
||||
$('a.load_file').click(function () {
|
||||
|
@ -1175,17 +1164,16 @@ firmware_flasher.initialize = function (callback) {
|
|||
function setAcknowledgementTimestamp() {
|
||||
const storageObj = {};
|
||||
storageObj[storageTag] = Date.now();
|
||||
chrome.storage.local.set(storageObj);
|
||||
ConfigStorage.set(storageObj);
|
||||
}
|
||||
|
||||
chrome.storage.local.get(storageTag, function (result) {
|
||||
result = ConfigStorage.get(storageTag);
|
||||
if (!result[storageTag] || Date.now() - result[storageTag] > DAY_MS) {
|
||||
|
||||
showAcknowledgementDialog(setAcknowledgementTimestamp);
|
||||
} else {
|
||||
startFlashing();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showAcknowledgementDialog(acknowledgementCallback) {
|
||||
|
@ -1306,8 +1294,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
if (status) {
|
||||
const catch_new_port = function () {
|
||||
PortHandler.port_detected('flash_detected_device', function (result) {
|
||||
const port = result[0];
|
||||
PortHandler.port_detected('flash_detected_device', function (resultPort) {
|
||||
const port = resultPort[0];
|
||||
|
||||
if (!GUI.connect_lock) {
|
||||
GUI.log(i18n.getMessage('firmwareFlasherFlashTrigger', [port]));
|
||||
|
|
|
@ -99,7 +99,7 @@ logging.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
ConfigStorage.get('logging_file_entry', function (result) {
|
||||
const result = ConfigStorage.get('logging_file_entry');
|
||||
if (result.logging_file_entry) {
|
||||
chrome.fileSystem.restoreEntry(result.logging_file_entry, function (entry) {
|
||||
if (checkChromeRuntimeError()) {
|
||||
|
@ -110,7 +110,6 @@ logging.initialize = function (callback) {
|
|||
prepare_writer(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
GUI.content_ready(callback);
|
||||
}
|
||||
|
|
|
@ -559,7 +559,7 @@ TABS.motors.initialize = function (callback) {
|
|||
});
|
||||
|
||||
// set refresh speeds according to configuration saved in storage
|
||||
ConfigStorage.get(['motors_tab_sensor_settings', 'motors_tab_gyro_settings', 'motors_tab_accel_settings'], function (result) {
|
||||
const result = ConfigStorage.get(['motors_tab_sensor_settings', 'motors_tab_gyro_settings', 'motors_tab_accel_settings']);
|
||||
if (result.motors_tab_sensor_settings) {
|
||||
$('.tab-motors select[name="sensor_choice"]').val(result.motors_tab_sensor_settings.sensor);
|
||||
}
|
||||
|
@ -574,7 +574,6 @@ TABS.motors.initialize = function (callback) {
|
|||
TABS.motors.sensorAccelScale = result.motors_tab_accel_settings.scale;
|
||||
}
|
||||
$('.tab-motors .sensor select:first').change();
|
||||
});
|
||||
|
||||
// Amperage
|
||||
function power_data_pull() {
|
||||
|
|
|
@ -32,7 +32,7 @@ options.cleanup = function (callback) {
|
|||
};
|
||||
|
||||
options.initShowWarnings = function () {
|
||||
ConfigStorage.get('showPresetsWarningBackup', function (result) {
|
||||
const result = ConfigStorage.get('showPresetsWarningBackup');
|
||||
if (result.showPresetsWarningBackup) {
|
||||
$('div.presetsWarningBackup input').prop('checked', true);
|
||||
}
|
||||
|
@ -41,11 +41,10 @@ options.initShowWarnings = function () {
|
|||
const checked = $(this).is(':checked');
|
||||
ConfigStorage.set({'showPresetsWarningBackup': checked});
|
||||
}).change();
|
||||
});
|
||||
};
|
||||
|
||||
options.initPermanentExpertMode = function () {
|
||||
ConfigStorage.get('permanentExpertMode', function (result) {
|
||||
const result = ConfigStorage.get('permanentExpertMode');
|
||||
if (result.permanentExpertMode) {
|
||||
$('div.permanentExpertMode input').prop('checked', true);
|
||||
}
|
||||
|
@ -57,20 +56,18 @@ options.initPermanentExpertMode = function () {
|
|||
|
||||
$('input[name="expertModeCheckbox"]').prop('checked', checked).change();
|
||||
}).change();
|
||||
});
|
||||
};
|
||||
|
||||
options.initRememberLastTab = function () {
|
||||
ConfigStorage.get('rememberLastTab', function (result) {
|
||||
const result = ConfigStorage.get('rememberLastTab');
|
||||
$('div.rememberLastTab input')
|
||||
.prop('checked', !!result.rememberLastTab)
|
||||
.change(function() { ConfigStorage.set({rememberLastTab: $(this).is(':checked')}); })
|
||||
.change();
|
||||
});
|
||||
};
|
||||
|
||||
options.initCheckForConfiguratorUnstableVersions = function () {
|
||||
ConfigStorage.get('checkForConfiguratorUnstableVersions', function (result) {
|
||||
const result = ConfigStorage.get('checkForConfiguratorUnstableVersions');
|
||||
if (result.checkForConfiguratorUnstableVersions) {
|
||||
$('div.checkForConfiguratorUnstableVersions input').prop('checked', true);
|
||||
}
|
||||
|
@ -82,11 +79,10 @@ options.initCheckForConfiguratorUnstableVersions = function () {
|
|||
|
||||
checkForConfiguratorUpdates();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
options.initAnalyticsOptOut = function () {
|
||||
ConfigStorage.get('analyticsOptOut', function (result) {
|
||||
const result = ConfigStorage.get('analyticsOptOut');
|
||||
if (result.analyticsOptOut) {
|
||||
$('div.analyticsOptOut input').prop('checked', true);
|
||||
}
|
||||
|
@ -108,7 +104,6 @@ options.initAnalyticsOptOut = function () {
|
|||
}
|
||||
});
|
||||
}).change();
|
||||
});
|
||||
};
|
||||
|
||||
options.initCliAutoComplete = function () {
|
||||
|
@ -122,19 +117,29 @@ options.initCliAutoComplete = function () {
|
|||
}).change();
|
||||
};
|
||||
|
||||
options.initAutoConnectConnectionTimeout = function () {
|
||||
const result = ConfigStorage.get('connectionTimeout');
|
||||
if (result.connectionTimeout) {
|
||||
$('#connectionTimeoutSelect').val(result.connectionTimeout);
|
||||
}
|
||||
$('#connectionTimeoutSelect').on('change', function () {
|
||||
const value = parseInt($(this).val());
|
||||
ConfigStorage.set({'connectionTimeout': value});
|
||||
});
|
||||
};
|
||||
|
||||
options.initShowAllSerialDevices = function() {
|
||||
const showAllSerialDevicesElement = $('div.showAllSerialDevices input');
|
||||
ConfigStorage.get('showAllSerialDevices', result => {
|
||||
const result = ConfigStorage.get('showAllSerialDevices');
|
||||
showAllSerialDevicesElement
|
||||
.prop('checked', !!result.showAllSerialDevices)
|
||||
.on('change', () => ConfigStorage.set({ showAllSerialDevices: showAllSerialDevicesElement.is(':checked') }))
|
||||
.trigger('change');
|
||||
});
|
||||
};
|
||||
|
||||
options.initShowVirtualMode = function() {
|
||||
const showVirtualModeElement = $('div.showVirtualMode input');
|
||||
ConfigStorage.get('showVirtualMode', result => {
|
||||
const result = ConfigStorage.get('showVirtualMode');
|
||||
showVirtualModeElement
|
||||
.prop('checked', !!result.showVirtualMode)
|
||||
.on('change', () => {
|
||||
|
@ -142,12 +147,11 @@ options.initShowVirtualMode = function() {
|
|||
PortHandler.initialPorts = false;
|
||||
})
|
||||
.trigger('change');
|
||||
});
|
||||
};
|
||||
|
||||
options.initCordovaForceComputerUI = function () {
|
||||
if (GUI.isCordova() && cordovaUI.canChangeUI) {
|
||||
ConfigStorage.get('cordovaForceComputerUI', function (result) {
|
||||
const result = ConfigStorage.get('cordovaForceComputerUI');
|
||||
if (result.cordovaForceComputerUI) {
|
||||
$('div.cordovaForceComputerUI input').prop('checked', true);
|
||||
}
|
||||
|
@ -161,7 +165,6 @@ options.initCordovaForceComputerUI = function () {
|
|||
cordovaUI.set();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$('div.cordovaForceComputerUI').hide();
|
||||
}
|
||||
|
|
|
@ -783,13 +783,12 @@ TABS.receiver.initialize = function (callback) {
|
|||
GUI.interval_add('receiver_pull', get_rc_refresh_data, plotUpdateRate, true);
|
||||
});
|
||||
|
||||
ConfigStorage.get('rx_refresh_rate', function (result) {
|
||||
const result = ConfigStorage.get('rx_refresh_rate');
|
||||
if (result.rxRefreshRate) {
|
||||
rxRefreshRate.val(result.rxRefreshRate).change();
|
||||
} else {
|
||||
rxRefreshRate.change(); // start with default value
|
||||
}
|
||||
});
|
||||
|
||||
// Setup model for preview
|
||||
tab.initModelPreview();
|
||||
|
|
|
@ -428,7 +428,7 @@ TABS.sensors.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
ConfigStorage.get('sensor_settings', function (result) {
|
||||
const result = ConfigStorage.get('sensor_settings');
|
||||
// set refresh speeds according to configuration saved in storage
|
||||
if (result.sensor_settings) {
|
||||
$('.tab-sensors select[name="gyro_refresh_rate"]').val(result.sensor_settings.rates.gyro);
|
||||
|
@ -451,7 +451,8 @@ TABS.sensors.initialize = function (callback) {
|
|||
// start polling immediatly (as there is no configuration saved in the storage)
|
||||
$('.tab-sensors .rate select:first').change();
|
||||
}
|
||||
ConfigStorage.get('graphs_enabled', function (resultGraphs) {
|
||||
|
||||
const resultGraphs = ConfigStorage.get('graphs_enabled');
|
||||
if (resultGraphs.graphs_enabled) {
|
||||
const _checkboxes = $('.tab-sensors .info .checkboxes input');
|
||||
for (let i = 0; i < resultGraphs.graphs_enabled.length; i++) {
|
||||
|
@ -460,8 +461,6 @@ TABS.sensors.initialize = function (callback) {
|
|||
} else {
|
||||
$('.tab-sensors .info input:lt(4):not(:disabled)').prop('checked', true).change();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// status data pulled via separate timer with static speed
|
||||
GUI.interval_add('status_pull', function status_pull() {
|
||||
|
|
Loading…
Reference in New Issue