1
0
Fork 0

widbt: option to hide when no connection

master
Iakov Davydov 2022-05-14 10:38:37 +02:00
parent 289771c3e3
commit 71ebe9bca5
5 changed files with 50 additions and 7 deletions

View File

@ -5,3 +5,4 @@
0.06: Tweaking colors for dark/light themes and low bpp screens
0.07: Memory usage improvements
0.08: Disable LCD on, on bluetooth status change
0.09: Hide widget when disconnected (a setting)

1
apps/widbt/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwMB/4AG/YFE/IFE/AFFv4FEn4FEj4FEg4FEgYFEHIn4oAFEsAqD/FwFQXx/F4h4FB+H4vgwC+F4vARC/E4uAdC/kYsAiC/0IoIvDgBBEwBNE4AuCAAPgL4nwNYgFFCIodFFIo1EIIpNFLIplF8BxEPoQFC/aJESo6hFVoq5FYorRFborpFeon5Aon7AogADA="))

View File

@ -1,13 +1,16 @@
{
"id": "widbt",
"name": "Bluetooth Widget",
"version": "0.08",
"version": "0.09",
"description": "Show the current Bluetooth connection status in the top right of the clock",
"icon": "widget.png",
"type": "widget",
"tags": "widget,bluetooth",
"supports": ["BANGLEJS","BANGLEJS2"],
"storage": [
{"name":"widbt.wid.js","url":"widget.js"}
]
{"name":"widbt.wid.js","url":"widget.js"},
{"name":"widbt.settings.js","url":"settings.js"},
{"name":"widbt.img","url":"app-icon.js","evaluate":true}
],
"data": [{"name":"widbt.json"}]
}

22
apps/widbt/settings.js Normal file
View File

@ -0,0 +1,22 @@
(function(back) {
var FILE = "widbt.json";
var settings = require('Storage').readJSON(FILE, true) || {};
function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}
E.showMenu({
"" : { "title" : "Bluetooth Widget" },
"< Back" : () => back(),
'No conn. widget': {
value: !!settings.hideDisconnected,
format: v => v?"Hide":"Show",
onchange: v => {
settings.hideDisconnected = v;
writeSettings();
if (WIDGETS.bluetooth) WIDGETS.bluetooth.changed();
}
},
});
})

View File

@ -1,12 +1,28 @@
WIDGETS["bluetooth"]={area:"tr",width:15,draw:function() {
WIDGETS["bluetooth"]={area:"tr",draw:function() {
if (WIDGETS.bluetooth.width==0)
return;
g.reset();
if (NRF.getSecurityStatus().connected)
g.setColor((g.getBPP()>8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f"));
else
g.setColor(g.theme.dark ? "#666" : "#999");
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="),2+this.x,2+this.y);
},getWidth:function(){
if (!NRF.getSecurityStatus().connected) {
const settings = require('Storage').readJSON("widbt.json", true) || {};
if (settings.hideDisconnected)
return 0;
}
return 15;
},changed:function() {
WIDGETS["bluetooth"].draw();
const newWidth = WIDGETS.bluetooth.getWidth();
if (WIDGETS.bluetooth.width != newWidth) {
WIDGETS.bluetooth.width = newWidth;
Bangle.drawWidgets();
} else {
WIDGETS.bluetooth.draw();
}
}};
NRF.on('connect',WIDGETS["bluetooth"].changed);
NRF.on('disconnect',WIDGETS["bluetooth"].changed);
WIDGETS.bluetooth.width = WIDGETS.bluetooth.getWidth();
NRF.on('connect',WIDGETS.bluetooth.changed);
NRF.on('disconnect',WIDGETS.bluetooth.changed);