From 631abb812e8acdce0cb15ee8947bff2c26acbbe4 Mon Sep 17 00:00:00 2001 From: Richard de Boer Date: Thu, 28 May 2020 23:27:10 +0200 Subject: [PATCH] gbridge: Add setting to show/hide icon --- apps.json | 5 ++++- apps/gbridge/ChangeLog | 1 + apps/gbridge/settings.js | 20 +++++++++++++++++++- apps/gbridge/widget.js | 19 +++++++++++++++---- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/apps.json b/apps.json index 5eede9c05..8b950228c 100644 --- a/apps.json +++ b/apps.json @@ -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", diff --git a/apps/gbridge/ChangeLog b/apps/gbridge/ChangeLog index f66040388..0676652c7 100644 --- a/apps/gbridge/ChangeLog +++ b/apps/gbridge/ChangeLog @@ -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 \ No newline at end of file diff --git a/apps/gbridge/settings.js b/apps/gbridge/settings.js index 723c9cae9..1834aa052 100644 --- a/apps/gbridge/settings.js +++ b/apps/gbridge/settings.js @@ -2,10 +2,28 @@ function gb(j) { Bluetooth.println(JSON.stringify(j)); } - + const storage = require('Storage'); + let settings = storage.readJSON("gbridge.json", true) || {}; + if (!("showIcon" in settings)) { + settings.showIcon = true; + } + function updateSettings() { + storage.write('gbridge.json', settings); + } + function toggleIcon() { + settings.showIcon = !settings.showIcon; + updateSettings(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); + } var mainmenu = { "" : { "title" : "Gadgetbridge" }, "Connected" : { value : NRF.getSecurityStatus().connected?"Yes":"No" }, + "Show Icon" : { + value: settings.showIcon, + format: v => v?"Yes":"No", + onchange: toggleIcon + }, "Find Phone" : function() { E.showMenu(findPhone); }, "< Back" : back, }; diff --git a/apps/gbridge/widget.js b/apps/gbridge/widget.js index ae7d0f8fa..987426022 100644 --- a/apps/gbridge/widget.js +++ b/apps/gbridge/widget.js @@ -1,4 +1,5 @@ (() => { + const storage = require('Storage'); const state = { music: "stop", @@ -12,6 +13,11 @@ scrollPos: 0 }; + let settings = storage.readJSON('gbridge.json',1) || {}; + if (!("showIcon" in settings)) { + settings.showIcon = true; + } + function gbSend(message) { Bluetooth.println(""); Bluetooth.println(JSON.stringify(message)); @@ -192,10 +198,15 @@ g.flip(); // turns screen on } - NRF.on("connect", changedConnectionState); - NRF.on("disconnect", changedConnectionState); - - WIDGETS["gbridgew"] = { area: "tl", width: 24, draw: draw }; + if (settings.showIcon) { + WIDGETS["gbridgew"] = {area: "tl", width: 24, draw: draw}; + NRF.on("connect", changedConnectionState); + NRF.on("disconnect", changedConnectionState); + } else { + NRF.removeListener("connect", changedConnectionState); + NRF.removeListener("disconnect", changedConnectionState); + delete WIDGETS["gbridgew"]; + } function sendBattery() { gbSend({ t: "status", bat: E.getBattery() });