From a4f5978fb699ecb3bb10acead419e1f4fd2084d5 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 28 Oct 2024 17:21:31 +0000 Subject: [PATCH] widbt_notify 0.18: Use notify lib to stop this widget clearing the screen of the running clock/app --- apps/widbt_notify/ChangeLog | 3 ++- apps/widbt_notify/metadata.json | 3 ++- apps/widbt_notify/widget.js | 27 ++++++++------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/apps/widbt_notify/ChangeLog b/apps/widbt_notify/ChangeLog index d48cdca63..74f8515db 100644 --- a/apps/widbt_notify/ChangeLog +++ b/apps/widbt_notify/ChangeLog @@ -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 \ No newline at end of file +0.17: Minor display fix +0.18: Use notify lib to stop this widget clearing the screen of the running clock/app \ No newline at end of file diff --git a/apps/widbt_notify/metadata.json b/apps/widbt_notify/metadata.json index 5e3f15af2..4eda86941 100644 --- a/apps/widbt_notify/metadata.json +++ b/apps/widbt_notify/metadata.json @@ -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"} diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index 4730db5b5..bde218236 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -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()); -})() \ No newline at end of file +} \ No newline at end of file