Merge pull request #770 from epw/master

Add support for dismissing Gadgetbridge notifications through notify
master
Gordon Williams 2021-07-10 19:41:38 +01:00 committed by GitHub
commit 4a01fa1c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View File

@ -1,4 +1,7 @@
(() => {
// Current shown notification, saved for dismissing.
var currentNot = null;
// Music handling
const state = {
music: "stop",
@ -151,16 +154,19 @@
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) {
Bangle.buzz();
}
} else { // notify-
require("notify").hide(event);
currentNot = prettifyNotificationEvent(event);
require("notify").show(currentNot);
if (!(require('Storage').readJSON('setting.json',1)||{}).quiet) {
Bangle.buzz();
}
break;
case "notify-":
currentNot.t = "notify";
currentNot.n = "DISMISS";
gbSend(currentNot);
currentNot = null;
require("notify").hide(event);
break;
case "musicinfo":
state.musicInfo = event;
updateMusic({on: false});

View File

@ -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);
}
};