1
0
Fork 0

Merge pull request #522 from rigrig/gbridge

Gbridge
master
Gordon Williams 2020-07-08 08:45:18 +01:00 committed by GitHub
commit 5ae38e02a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 18 deletions

View File

@ -80,7 +80,7 @@
"name": "Notifications (default)", "name": "Notifications (default)",
"shortName":"Notifications", "shortName":"Notifications",
"icon": "notify.png", "icon": "notify.png",
"version":"0.01", "version":"0.02",
"description": "A handler for displaying notifications that displays them in a bar at the top of the screen", "description": "A handler for displaying notifications that displays them in a bar at the top of the screen",
"tags": "widget", "tags": "widget",
"type": "notify", "type": "notify",
@ -93,7 +93,7 @@
"name": "Fullscreen Notifications", "name": "Fullscreen Notifications",
"shortName":"Notifications", "shortName":"Notifications",
"icon": "notify.png", "icon": "notify.png",
"version":"0.01", "version":"0.02",
"description": "A handler for displaying notifications that displays them fullscreen. This may not fully restore the screen after on some apps. See `Notifications (default)` for more information about the notifications library.", "description": "A handler for displaying notifications that displays them fullscreen. This may not fully restore the screen after on some apps. See `Notifications (default)` for more information about the notifications library.",
"tags": "widget", "tags": "widget",
"type": "notify", "type": "notify",
@ -121,7 +121,7 @@
{ "id": "gbridge", { "id": "gbridge",
"name": "Gadgetbridge", "name": "Gadgetbridge",
"icon": "app.png", "icon": "app.png",
"version":"0.15", "version":"0.16",
"description": "The default notification handler for Gadgetbridge notifications from Android", "description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget", "tags": "tool,system,android,widget",
"type":"widget", "type":"widget",

View File

@ -14,3 +14,5 @@
0.13: Modified to use the 'notify' library 0.13: Modified to use the 'notify' library
0.14: Added 'find' event handling 0.14: Added 'find' event handling
0.15: Don't keep LCD on while playing music 0.15: Don't keep LCD on while playing music
0.16: Handle dismissing notifications on the phone
Nicer display of alarm clock notifications

View File

@ -24,14 +24,34 @@
Bluetooth.println(JSON.stringify(message)); Bluetooth.println(JSON.stringify(message));
} }
function prettifyNotificationEvent(event) {
switch (event.src) {
case "ALARMCLOCKRECEIVER":
return {
id: event.id,
title: event.title || "Alarm",
body: event.body,
// same icon as apps/alarm/app-icon.js
icon: require("heatshrink").decompress(atob("mEwwkGswAhiMRCCAREAo4eHBIQLEAgwYHsIJDiwHB5gACBpIhHCoYZEGA4gFCw4ABGA4HEjgXJ4IXGAwcUB4VEmf//8zogICoJIFAodMBoNDCoIADmgJB4gXIFwXDCwoABngwFC4guB4k/CQXwh4EC+YMCC44iBp4qDC4n/+gNBC41sEIJCEC4v/GAPGC4dhXYRdFC4xhCCYIXCdQRdDC5HzegQXCsxGHC45IDCwQXCUgwXHJAIXGRogXJSIIXcOw4XIPAYXcBwv/mEDBAwXOgtQC65QGC5vzoEAJAx3Nmk/mEABIiPN+dDAQIwFC4zXGFwKRCGAjvMFwQECGAgXI4YuGGAUvAgU8C4/EFwwGCAgdMC4p4EFwobFOwoXDJAIoEAApGBC4xIEABJGHGAapEAAqNBFwwXD4heI+YuBC5BIBVQhdHIw4wD5inFS4IKCCxFmigNCokzCoMzogICoIWIsMRjgPCAA3BiMWC48RBQIXJEgMRFxAJCCw4lEC44IECooOIBAaBJKwhgIAH4ACA==")),
};
default:
return event;
}
}
function handleNotificationEvent(event) { function handleNotificationEvent(event) {
require("notify").show(event); if (event.t === "notify") {
require("notify").show(prettifyNotificationEvent(event));
Bangle.buzz(); Bangle.buzz();
} else { // notify-
require("notify").hide(event);
}
} }
function updateMusic(options){ function updateMusic(options){
if (state.music === "play") { if (state.music === "play") {
require("notify").show(Object.assign({size:40, render:y => { require("notify").show(Object.assign({
size:40, id:"music",
render:y => {
g.setColor(-1); g.setColor(-1);
g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8); g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8);
g.setFontAlign(-1, -1); g.setFontAlign(-1, -1);
@ -42,7 +62,7 @@
} }
if (state.music === "pause") { if (state.music === "pause") {
require("notify").hide(); require("notify").hide("music");
} }
} }
function handleMusicStateUpdate(event) { function handleMusicStateUpdate(event) {
@ -59,7 +79,7 @@
function handleCallEvent(event) { function handleCallEvent(event) {
if (event.cmd === "accept") { if (event.cmd === "accept") {
require("notify").show({ require("notify").show({
size: 55, title: event.name, size: 55, title: event.name, id: "call",
body: event.number, icon:require("heatshrink").decompress(atob("jEYwIMJj4CCwACJh4CCCIMOAQMGAQMHAQMDAQMBCIMB4PwgHz/EAn4CBj4CBg4CBgACCAAw="))}); body: event.number, icon:require("heatshrink").decompress(atob("jEYwIMJj4CCwACJh4CCCIMOAQMGAQMHAQMDAQMBCIMB4PwgHz/EAn4CBj4CBg4CBgACCAAw="))});
Bangle.buzz(); Bangle.buzz();
} }
@ -81,6 +101,7 @@
global.GB = (event) => { global.GB = (event) => {
switch (event.t) { switch (event.t) {
case "notify": case "notify":
case "notify-":
handleNotificationEvent(event); handleNotificationEvent(event);
break; break;
case "musicinfo": case "musicinfo":

View File

@ -1 +1,2 @@
0.01: New Library! 0.01: New Library!
0.02: Add notification ID option

View File

@ -12,6 +12,7 @@ options = {
on : bool, // turn screen on, default true on : bool, // turn screen on, default true
size : int, // height of notification, default 80 (max) size : int, // height of notification, default 80 (max)
title : string, // optional title title : string, // optional title
id // optional notification ID, used with hide()
src : string, // optional source name src : string, // optional source name
body : string, // optional body text body : string, // optional body text
icon : string, // optional icon (image string) icon : string, // optional icon (image string)
@ -28,4 +29,11 @@ require("notify").show({
}); });
// remove it (can also be removed by tapping) // remove it (can also be removed by tapping)
require("notify").hide(); require("notify").hide();
// Use ID to only hide a specific notification if it is still visible
require("notify").show({id:1, title:"Test", body:"Some Alert"});
require("notify").show({id:"msg", title:"Message", body:"Incoming Message"}); // replaces Test Alert
require("notify").hide({id:1}); // does nothing, because the Test Alert was already replaced
require("notify").hide({id:"msg"}); // hides Message
require("notify").hide(); // hides current notification, whatever it was
``` ```

View File

@ -1,10 +1,12 @@
var pos = 0; var pos = 0;
var id = null;
/** /**
options = { options = {
on : bool // turn screen on, default true on : bool // turn screen on, default true
size : int // height of notification, default 80 (max) size : int // height of notification, default 80 (max)
title : string // optional title title : string // optional title
id // optional notification ID, used with hide()
src : string // optional source name src : string // optional source name
body : string // optional body text body : string // optional body text
icon : string // optional icon (image string) icon : string // optional icon (image string)
@ -14,6 +16,7 @@ var pos = 0;
exports.show = function(options) { exports.show = function(options) {
options = options||{}; options = options||{};
if (options.on===undefined) options.on=true; if (options.on===undefined) options.on=true;
id = ("id" in options)?options.id:null;
var h = options.size||80; var h = options.size||80;
var oldMode = Bangle.getLCDMode(); var oldMode = Bangle.getLCDMode();
// TODO: throw exception if double-buffered? // TODO: throw exception if double-buffered?
@ -86,7 +89,15 @@ exports.show = function(options) {
Bangle.on("touch", exports.hide); Bangle.on("touch", exports.hide);
} }
exports.hide = function() { /**
options = {
id // optional, only hide if current notification has this ID
}
*/
exports.hide = function(options) {
options = options||{};
if ("id" in options && options.id!==id) return;
id = null;
Bangle.removeListener("touch", exports.hide); Bangle.removeListener("touch", exports.hide);
function anim() { function anim() {
pos += 4; pos += 4;

View File

@ -1 +1,2 @@
0.01: New Library! 0.01: New Library!
0.02: Add notification ID option

View File

@ -1,11 +1,13 @@
var pos = 0; var pos = 0;
var oldg; var oldg;
var id = null;
/** /**
options = { options = {
on : bool // turn screen on, default true on : bool // turn screen on, default true
size : int // height of notification, default 120 (max) size : int // height of notification, default 120 (max)
title : string // optional title title : string // optional title
id // optional notification ID, used with hide()
src : string // optional source name src : string // optional source name
body : string // optional body text body : string // optional body text
icon : string // optional icon (image string) icon : string // optional icon (image string)
@ -16,6 +18,7 @@ exports.show = function(options) {
if (oldg) g=oldg; if (oldg) g=oldg;
options = options||{}; options = options||{};
if (options.on===undefined) options.on=true; if (options.on===undefined) options.on=true;
id = ("id" in options)?options.id:null;
var h = options.size||120; var h = options.size||120;
Bangle.setLCDMode("direct"); Bangle.setLCDMode("direct");
var y = 40; var y = 40;
@ -75,7 +78,15 @@ exports.show = function(options) {
g.flip = function() {}; g.flip = function() {};
}; };
exports.hide = function() { /**
options = {
id // optional, only hide if current notification has this ID
}
*/
exports.hide = function(options) {
options = options||{};
if ("id" in options && options.id!==id) return;
id = null;
g=oldg; g=oldg;
oldg = undefined; oldg = undefined;
Bangle.removeListener("touch", exports.hide); Bangle.removeListener("touch", exports.hide);