From c3e91b4a30711e045f46468bf894327c36345e00 Mon Sep 17 00:00:00 2001 From: Eric Willisson Date: Fri, 9 Jul 2021 14:46:24 -0400 Subject: [PATCH 1/2] Adds support for dismissing Gadgetbridge notifications through notify app. Most of the support was already there, so this is just a few small steps: - notify.js gets a dismiss_and_hide() exported function that can send the "notify-" event to Gadgetbridge, if installed - dismiss_and_hide() is called when the Bangle.js screen is touched, instead of just hide() - Gadgetbridge's widget.js saves "notify"-type events to a variable - Gadgetbridge's widget.js sends a DISMISS action back to the Android app on "notify-" events, using the saved event data Note that this is a limited implementation. For example, only the most recent notfication is saved (when a new one comes in, the old one is overridden in the variable), so it will be dismissed on the phone. A more advanced implementation might make it possible to choose which notification to dismiss. From my own testing, this does properly count as a "swipe-away" style dismiss event in Android, so apps that react to notifications being swiped away will be triggered as expected. --- apps/gbridge/widget.js | 20 +++++++++++++------- apps/notify/notify.js | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/gbridge/widget.js b/apps/gbridge/widget.js index b4ce71907..35aacd846 100644 --- a/apps/gbridge/widget.js +++ b/apps/gbridge/widget.js @@ -1,4 +1,7 @@ (() => { + // Current shown notification, saved for dismissing. + var currentNot = null; + // Music handling const state = { music: "stop", @@ -151,15 +154,18 @@ global.GB = (event) => { switch (event.t) { case "notify": - case "notify-": - if (event.t === "notify") { - require("notify").show(prettifyNotificationEvent(event)); - if (!(require('Storage').readJSON('setting.json',1)||{}).quiet) { + currentNot = prettifyNotificationEvent(event); + require("notify").show(currentNot); + if (!(require('Storage').readJSON('setting.json',1)||{}).quiet) { Bangle.buzz(); - } - } else { // notify- - require("notify").hide(event); } + break; + case "notify-": + currentNot.t = "notify"; + currentNot.n = "DISMISS"; + gbSend(currentNot); + currentNot = null; + require("notify").hide(event); break; case "musicinfo": state.musicInfo = event; diff --git a/apps/notify/notify.js b/apps/notify/notify.js index b5ef32d8b..230cf9d10 100644 --- a/apps/notify/notify.js +++ b/apps/notify/notify.js @@ -141,7 +141,7 @@ exports.show = function(options) { if (pos > -size) setTimeout(anim, 15); } anim(); - Bangle.on("touch", exports.hide); + Bangle.on("touch", exports.dismiss_and_hide); }; /** @@ -162,3 +162,20 @@ exports.hide = function(options) { } anim(); }; + +/** + Calls exports.hide(), but if Gadgetbridge is installed, dismiss through it + instead (which will call call exports.hide() itself). +*/ +exports.dismiss_and_hide = function(options) { + options = options||{}; + if (typeof(options) == "number") { + options = {}; + } + if ("GB" in global) { + options["t"] = "notify-"; + GB(options); + } else { + exports.hide(options); + } +}; From 3e41465d643aa8111c50af94ce56940f9e803098 Mon Sep 17 00:00:00 2001 From: Eric Willisson Date: Fri, 9 Jul 2021 20:10:13 -0400 Subject: [PATCH 2/2] Fix tabbing --- apps/gbridge/widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gbridge/widget.js b/apps/gbridge/widget.js index 35aacd846..70abfd610 100644 --- a/apps/gbridge/widget.js +++ b/apps/gbridge/widget.js @@ -157,9 +157,9 @@ currentNot = prettifyNotificationEvent(event); require("notify").show(currentNot); if (!(require('Storage').readJSON('setting.json',1)||{}).quiet) { - Bangle.buzz(); + Bangle.buzz(); } - break; + break; case "notify-": currentNot.t = "notify"; currentNot.n = "DISMISS";