gbridge: improve settings handling
No need to keep them in memory after reload() is donemaster
parent
fa692c4d8e
commit
855186f7c9
|
|
@ -2,17 +2,20 @@
|
||||||
function gb(j) {
|
function gb(j) {
|
||||||
Bluetooth.println(JSON.stringify(j));
|
Bluetooth.println(JSON.stringify(j));
|
||||||
}
|
}
|
||||||
const storage = require('Storage');
|
function settings() {
|
||||||
let settings = storage.readJSON("gbridge.json", true) || {};
|
let settings = require('Storage').readJSON("gbridge.json", true) || {};
|
||||||
if (!("showIcon" in settings)) {
|
if (!("showIcon" in settings)) {
|
||||||
settings.showIcon = true;
|
settings.showIcon = true;
|
||||||
|
}
|
||||||
|
return settings
|
||||||
}
|
}
|
||||||
function updateSettings() {
|
function updateSetting(setting, value) {
|
||||||
storage.write('gbridge.json', settings);
|
let settings = require('Storage').readJSON("gbridge.json", true) || {};
|
||||||
|
settings[setting] = value
|
||||||
|
require('Storage').write('gbridge.json', settings);
|
||||||
}
|
}
|
||||||
function toggleIcon() {
|
function setIcon(visible) {
|
||||||
settings.showIcon = !settings.showIcon;
|
updateSetting('showIcon', visible);
|
||||||
updateSettings();
|
|
||||||
// need to re-layout widgets
|
// need to re-layout widgets
|
||||||
WIDGETS["gbridgew"].reload();
|
WIDGETS["gbridgew"].reload();
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
@ -22,9 +25,9 @@
|
||||||
"" : { "title" : "Gadgetbridge" },
|
"" : { "title" : "Gadgetbridge" },
|
||||||
"Connected" : { value : NRF.getSecurityStatus().connected?"Yes":"No" },
|
"Connected" : { value : NRF.getSecurityStatus().connected?"Yes":"No" },
|
||||||
"Show Icon" : {
|
"Show Icon" : {
|
||||||
value: settings.showIcon,
|
value: settings().showIcon,
|
||||||
format: v => v?"Yes":"No",
|
format: v => v?"Yes":"No",
|
||||||
onchange: toggleIcon
|
onchange: setIcon
|
||||||
},
|
},
|
||||||
"Find Phone" : function() { E.showMenu(findPhone); },
|
"Find Phone" : function() { E.showMenu(findPhone); },
|
||||||
"< Back" : back,
|
"< Back" : back,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
(() => {
|
(() => {
|
||||||
const storage = require('Storage');
|
|
||||||
let settings;
|
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
music: "stop",
|
music: "stop",
|
||||||
|
|
||||||
|
|
@ -14,6 +11,13 @@
|
||||||
scrollPos: 0
|
scrollPos: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function settings() {
|
||||||
|
let settings = require('Storage').readJSON("gbridge.json", true) || {};
|
||||||
|
if (!("showIcon" in settings)) {
|
||||||
|
settings.showIcon = true;
|
||||||
|
}
|
||||||
|
return settings
|
||||||
|
}
|
||||||
|
|
||||||
function gbSend(message) {
|
function gbSend(message) {
|
||||||
Bluetooth.println("");
|
Bluetooth.println("");
|
||||||
|
|
@ -183,7 +187,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
if (!settings.showIcon) return;
|
|
||||||
g.setColor(-1);
|
g.setColor(-1);
|
||||||
if (NRF.getSecurityStatus().connected)
|
if (NRF.getSecurityStatus().connected)
|
||||||
g.drawImage(require("heatshrink").decompress(atob("i0WwgHExAABCIwJCBYwJEBYkIBQ2ACgvzCwoECx/z/AKDD4WD+YLBEIYKCx//+cvnAKCBwU/mc4/8/HYv//Ev+Y4EEAePn43DBQkzn4rCEIoABBIwKHO4cjmczK42I6mqlqEEBQeIBQaDED4IgDUhi6KaBbmIA==")), this.x + 1, this.y + 1);
|
g.drawImage(require("heatshrink").decompress(atob("i0WwgHExAABCIwJCBYwJEBYkIBQ2ACgvzCwoECx/z/AKDD4WD+YLBEIYKCx//+cvnAKCBwU/mc4/8/HYv//Ev+Y4EEAePn43DBQkzn4rCEIoABBIwKHO4cjmczK42I6mqlqEEBQeIBQaDED4IgDUhi6KaBbmIA==")), this.x + 1, this.y + 1);
|
||||||
|
|
@ -197,18 +200,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
settings = storage.readJSON('gbridge.json', 1) || {};
|
NRF.removeListener("connect", changedConnectionState);
|
||||||
if (!("showIcon" in settings)) {
|
NRF.removeListener("disconnect", changedConnectionState);
|
||||||
settings.showIcon = true;
|
if (settings().showIcon) {
|
||||||
}
|
|
||||||
if (settings.showIcon) {
|
|
||||||
WIDGETS["gbridgew"].width = 24;
|
WIDGETS["gbridgew"].width = 24;
|
||||||
|
WIDGETS["gbridgew"].draw = draw;
|
||||||
NRF.on("connect", changedConnectionState);
|
NRF.on("connect", changedConnectionState);
|
||||||
NRF.on("disconnect", changedConnectionState);
|
NRF.on("disconnect", changedConnectionState);
|
||||||
} else {
|
} else {
|
||||||
WIDGETS["gbridgew"].width = 0;
|
WIDGETS["gbridgew"].width = 0;
|
||||||
NRF.removeListener("connect", changedConnectionState);
|
WIDGETS["gbridgew"].draw = ()=>{};
|
||||||
NRF.removeListener("disconnect", changedConnectionState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue