1
0
Fork 0

Merge pull request #462 from rigrig/gbridge

gbridge: Add setting to show/hide icon
master
Gordon Williams 2020-05-29 12:01:06 +01:00 committed by GitHub
commit 97ff606212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 11 deletions

View File

@ -95,7 +95,7 @@
{ "id": "gbridge",
"name": "Gadgetbridge",
"icon": "app.png",
"version":"0.11",
"version":"0.12",
"description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget",
"type":"widget",
@ -103,6 +103,9 @@
{"name":"gbridge.settings.js","url":"settings.js"},
{"name":"gbridge.img","url":"app-icon.js","evaluate":true},
{"name":"gbridge.wid.js","url":"widget.js"}
],
"data": [
{"name":"gbridge.json"}
]
},
{ "id": "mclock",

View File

@ -10,3 +10,4 @@
0.09: Update Bluetooth connection state automatically
0.10: Make widget play well with other Gadgetbridge widgets/apps
0.11: Report battery status on connect and at regular intervals
0.12: Setting to show/hide icon

View File

@ -2,10 +2,33 @@
function gb(j) {
Bluetooth.println(JSON.stringify(j));
}
function settings() {
let settings = require('Storage').readJSON("gbridge.json", true) || {};
if (!("showIcon" in settings)) {
settings.showIcon = true;
}
return settings
}
function updateSetting(setting, value) {
let settings = require('Storage').readJSON("gbridge.json", true) || {};
settings[setting] = value
require('Storage').write('gbridge.json', settings);
}
function setIcon(visible) {
updateSetting('showIcon', visible);
// need to re-layout widgets
WIDGETS["gbridgew"].reload();
g.clear();
Bangle.drawWidgets();
}
var mainmenu = {
"" : { "title" : "Gadgetbridge" },
"Connected" : { value : NRF.getSecurityStatus().connected?"Yes":"No" },
"Show Icon" : {
value: settings().showIcon,
format: v => v?"Yes":"No",
onchange: setIcon
},
"Find Phone" : function() { E.showMenu(findPhone); },
"< Back" : back,
};

View File

@ -1,5 +1,4 @@
(() => {
const state = {
music: "stop",
@ -12,6 +11,14 @@
scrollPos: 0
};
function settings() {
let settings = require('Storage').readJSON("gbridge.json", true) || {};
if (!("showIcon" in settings)) {
settings.showIcon = true;
}
return settings
}
function gbSend(message) {
Bluetooth.println("");
Bluetooth.println(JSON.stringify(message));
@ -69,7 +76,7 @@
var p = MAXCHARS;
while (p > MAXCHARS - 8 && !" \t-_".includes(l[p]))
p--;
if (p == MAXCHARS - 8) p = MAXCHARS;
if (p === MAXCHARS - 8) p = MAXCHARS;
txt[i] = l.substr(0, p);
txt.splice(i + 1, 0, l.substr(p));
}
@ -102,7 +109,7 @@
const changed = state.music === event.state
state.music = event.state
if (state.music == "play") {
if (state.music === "play") {
showNotification(40, (y) => {
g.setColor("#ffffff");
g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8);
@ -119,14 +126,14 @@
}, changed);
}
if (state.music == "pause") {
if (state.music === "pause") {
hideNotification();
}
}
function handleCallEvent(event) {
if (event.cmd == "accept") {
if (event.cmd === "accept") {
showNotification(40, (y) => {
g.setColor("#ffffff");
g.drawImage(require("heatshrink").decompress(atob("jEYwIMJj4CCwACJh4CCCIMOAQMGAQMHAQMDAQMBCIMB4PwgHz/EAn4CBj4CBg4CBgACCAAw=")), 8, y + 8);
@ -173,7 +180,7 @@
});
Bangle.on("swipe", (dir) => {
if (state.music == "play") {
if (state.music === "play") {
const command = dir > 0 ? "next" : "previous"
gbSend({ t: "music", n: command });
}
@ -192,10 +199,22 @@
g.flip(); // turns screen on
}
NRF.on("connect", changedConnectionState);
NRF.on("disconnect", changedConnectionState);
function reload() {
NRF.removeListener("connect", changedConnectionState);
NRF.removeListener("disconnect", changedConnectionState);
if (settings().showIcon) {
WIDGETS["gbridgew"].width = 24;
WIDGETS["gbridgew"].draw = draw;
NRF.on("connect", changedConnectionState);
NRF.on("disconnect", changedConnectionState);
} else {
WIDGETS["gbridgew"].width = 0;
WIDGETS["gbridgew"].draw = ()=>{};
}
}
WIDGETS["gbridgew"] = { area: "tl", width: 24, draw: draw };
WIDGETS["gbridgew"] = {area: "tl", width: 24, draw: draw, reload: reload};
reload();
function sendBattery() {
gbSend({ t: "status", bat: E.getBattery() });