widbt_notify 0.18: Use notify lib to stop this widget clearing the screen of the running clock/app

pull/3629/head
Gordon Williams 2024-10-28 17:21:31 +00:00
parent 595e4a71ea
commit a4f5978fb6
3 changed files with 12 additions and 21 deletions

View File

@ -13,4 +13,5 @@
0.14: Added configuration option
0.15: Added option to hide widget when connected
0.16: Simplify code, add option to disable displaying a message
0.17: Minor display fix
0.17: Minor display fix
0.18: Use notify lib to stop this widget clearing the screen of the running clock/app

View File

@ -1,13 +1,14 @@
{
"id": "widbt_notify",
"name": "Bluetooth Widget with Notification",
"version": "0.17",
"version": "0.18",
"description": "Show the current Bluetooth connection status with some optional features: show message, buzz on connect/loss, hide always/if connected.",
"icon": "widget.png",
"type": "widget",
"tags": "widget,bluetooth",
"provides_widgets" : ["bluetooth"],
"supports": ["BANGLEJS","BANGLEJS2"],
"dependencies" : { "notify":"module" },
"storage": [
{"name":"widbt_notify.wid.js","url":"widget.js"},
{"name":"widbt_notify.settings.js","url":"settings.js"}

View File

@ -1,6 +1,6 @@
(function() {
{
// load settings
var settings = Object.assign({
let settings = Object.assign({
showWidget: true,
buzzOnConnect: true,
buzzOnLoss: true,
@ -10,7 +10,7 @@
}, require("Storage").readJSON("widbt_notify.json", true) || {});
// setup widget with to hide if connected and option set
var widWidth = settings.hideConnected && NRF.getSecurityStatus().connected ? 0 : 15;
let widWidth = settings.hideConnected && NRF.getSecurityStatus().connected ? 0 : 15;
// write widget with loaded settings
WIDGETS.bluetooth_notify = Object.assign(settings, {
@ -31,24 +31,13 @@
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y);
}
} else {
// g.setColor(g.theme.dark ? "#666" : "#999");
// g.setColor(g.theme.dark ? "#666" : "#999");
g.setColor("#f00"); // red is easier to distinguish from blue
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y);
}
}
},
redrawCurrentApp: function() {
if (typeof(draw) == 'function') {
g.reset().clear();
draw();
Bangle.loadWidgets();
Bangle.drawWidgets();
} else {
load(); // fallback. This might reset some variables
}
},
onNRF: function(connect) {
// setup widget with and reload widgets to show/hide if hideConnected is enabled
if (this.hideConnected) {
@ -61,10 +50,10 @@
if (this.warningEnabled) {
if (this.showMessage) {
E.showMessage( /*LANG*/ 'Connection\n' + (connect ? /*LANG*/ 'restored.' : /*LANG*/ 'lost.'), 'Bluetooth');
require("notify").show({id:"widbtnotify", title:"Bluetooth", body:/*LANG*/ 'Connection\n' + (connect ? /*LANG*/ 'restored.' : /*LANG*/ 'lost.')});
setTimeout(() => {
WIDGETS.bluetooth_notify.redrawCurrentApp();
}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'.
require("notify").hide({id:"widbtnotify"});
}, 3000);
}
this.warningEnabled = 0;
@ -87,4 +76,4 @@
NRF.on('connect', (addr) => WIDGETS.bluetooth_notify.onNRF(addr));
NRF.on('disconnect', () => WIDGETS.bluetooth_notify.onNRF());
})()
}