mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 12:55:14 +03:00
Chrome Apps don't get window.localStorage
This commit is contained in:
parent
a156ebd31e
commit
9fa5cca011
3 changed files with 43 additions and 18 deletions
|
@ -5,6 +5,9 @@
|
||||||
var ConfigStorage = {
|
var ConfigStorage = {
|
||||||
// key can be one string, or array of strings
|
// key can be one string, or array of strings
|
||||||
get: function(key, callback) {
|
get: function(key, callback) {
|
||||||
|
if (GUI.isChromeApp()) {
|
||||||
|
chrome.storage.local.get(key,callback);
|
||||||
|
} else {
|
||||||
//console.log('Abstraction.get',key);
|
//console.log('Abstraction.get',key);
|
||||||
if (Array.isArray(key)) {
|
if (Array.isArray(key)) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
|
@ -30,12 +33,17 @@ var ConfigStorage = {
|
||||||
callback({});
|
callback({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// set takes an object like {'userLanguageSelect':'DEFAULT'}
|
// set takes an object like {'userLanguageSelect':'DEFAULT'}
|
||||||
set: function(input) {
|
set: function(input) {
|
||||||
|
if (GUI.isChromeApp()) {
|
||||||
|
chrome.storage.local.set(input);
|
||||||
|
} else {
|
||||||
//console.log('Abstraction.set',input);
|
//console.log('Abstraction.set',input);
|
||||||
Object.keys(input).forEach(function (element) {
|
Object.keys(input).forEach(function (element) {
|
||||||
window.localStorage.setItem(element, JSON.stringify(input));
|
window.localStorage.setItem(element, JSON.stringify(input));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,27 @@ var GUI_control = function () {
|
||||||
else if (navigator.appVersion.indexOf("Linux") != -1) this.operating_system = "Linux";
|
else if (navigator.appVersion.indexOf("Linux") != -1) this.operating_system = "Linux";
|
||||||
else if (navigator.appVersion.indexOf("X11") != -1) this.operating_system = "UNIX";
|
else if (navigator.appVersion.indexOf("X11") != -1) this.operating_system = "UNIX";
|
||||||
else this.operating_system = "Unknown";
|
else this.operating_system = "Unknown";
|
||||||
|
|
||||||
|
// Check the method of execution
|
||||||
|
this.nwGui = null;
|
||||||
|
try {
|
||||||
|
this.nwGui = require('nw.gui');
|
||||||
|
this.Mode = GUI_Modes.NWJS;
|
||||||
|
} catch (ex) {
|
||||||
|
if (window.chrome && chrome.storage && chrome.storage.local) {
|
||||||
|
this.Mode = GUI_Modes.ChromeApp;
|
||||||
|
} else {
|
||||||
|
this.Mode = GUI_Modes.Other;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const GUI_Modes = {
|
||||||
|
NWJS: "NW.js",
|
||||||
|
ChromeApp: "Chrome",
|
||||||
|
Other: "Other"
|
||||||
|
}
|
||||||
|
|
||||||
// Timer managing methods
|
// Timer managing methods
|
||||||
|
|
||||||
// name = string
|
// name = string
|
||||||
|
@ -358,5 +377,16 @@ GUI_control.prototype.selectDefaultTabWhenConnected = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GUI_control.prototype.isChromeApp = function () {
|
||||||
|
return this.Mode == GUI_Modes.ChromeApp;
|
||||||
|
}
|
||||||
|
GUI_control.prototype.isNWJS = function () {
|
||||||
|
return this.Mode == GUI_Modes.NWJS;
|
||||||
|
}
|
||||||
|
GUI_control.prototype.isOther = function () {
|
||||||
|
return this.Mode == GUI_Modes.Other;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// initialize object into GUI variable
|
// initialize object into GUI variable
|
||||||
var GUI = new GUI_control();
|
var GUI = new GUI_control();
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var nwGui = getNwGui();
|
|
||||||
|
|
||||||
var googleAnalytics = analytics;
|
var googleAnalytics = analytics;
|
||||||
var analytics = undefined;
|
var analytics = undefined;
|
||||||
|
|
||||||
|
@ -16,17 +14,6 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getNwGui() {
|
|
||||||
var gui = null;
|
|
||||||
try {
|
|
||||||
gui = require('nw.gui');
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("Could not require 'nw.gui', maybe inside chrome");
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkSetupAnalytics(callback) {
|
function checkSetupAnalytics(callback) {
|
||||||
if (!analytics) {
|
if (!analytics) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -44,7 +31,7 @@ function checkSetupAnalytics(callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function getBuildType() {
|
function getBuildType() {
|
||||||
return nwGui ? 'NW.js' : 'Chrome';
|
return GUI.Mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupAnalytics(result) {
|
function setupAnalytics(result) {
|
||||||
|
@ -79,8 +66,8 @@ function setupAnalytics(result) {
|
||||||
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' })
|
analytics.sendEvent(analytics.EVENT_CATEGORIES.APPLICATION, 'AppClose', { sessionControl: 'end' })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nwGui) {
|
if (GUI.isNWJS()) {
|
||||||
var win = nwGui.Window.get();
|
var win = GUI.nwGui.Window.get();
|
||||||
win.on('close', function () {
|
win.on('close', function () {
|
||||||
sendCloseEvent();
|
sendCloseEvent();
|
||||||
|
|
||||||
|
@ -90,7 +77,7 @@ function setupAnalytics(result) {
|
||||||
// do not open the window
|
// do not open the window
|
||||||
policy.ignore();
|
policy.ignore();
|
||||||
// and open it in external browser
|
// and open it in external browser
|
||||||
nwGui.Shell.openExternal(url);
|
GUI.nwGui.Shell.openExternal(url);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Looks like we're in Chrome - but the event does not actually get fired
|
// Looks like we're in Chrome - but the event does not actually get fired
|
||||||
|
@ -293,7 +280,7 @@ function startProcess() {
|
||||||
TABS.onboard_logging.initialize(content_ready);
|
TABS.onboard_logging.initialize(content_ready);
|
||||||
break;
|
break;
|
||||||
case 'cli':
|
case 'cli':
|
||||||
TABS.cli.initialize(content_ready, nwGui);
|
TABS.cli.initialize(content_ready, GUI.nwGui);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue