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)",
"shortName":"Notifications",
"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",
"tags": "widget",
"type": "notify",
@ -93,7 +93,7 @@
"name": "Fullscreen Notifications",
"shortName":"Notifications",
"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.",
"tags": "widget",
"type": "notify",
@ -121,7 +121,7 @@
{ "id": "gbridge",
"name": "Gadgetbridge",
"icon": "app.png",
"version":"0.15",
"version":"0.16",
"description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget",
"type":"widget",

View File

@ -13,4 +13,6 @@
0.12: Setting to show/hide icon
0.13: Modified to use the 'notify' library
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,25 +24,45 @@
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) {
require("notify").show(event);
Bangle.buzz();
if (event.t === "notify") {
require("notify").show(prettifyNotificationEvent(event));
Bangle.buzz();
} else { // notify-
require("notify").hide(event);
}
}
function updateMusic(options){
if (state.music === "play") {
require("notify").show(Object.assign({size:40, render:y => {
g.setColor(-1);
g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8);
g.setFontAlign(-1, -1);
var x = 40;
g.setFont("4x6", 2).drawString(state.musicInfo.artist, x, y + 8);
g.setFont("6x8", 1).drawString(state.musicInfo.track, x, y + 22);
}}, options));
require("notify").show(Object.assign({
size:40, id:"music",
render:y => {
g.setColor(-1);
g.drawImage(require("heatshrink").decompress(atob("jEYwILI/EAv/8gP/ARcMgOAASN8h+A/kfwP8n4CD/E/gHgjg/HA=")), 8, y + 8);
g.setFontAlign(-1, -1);
var x = 40;
g.setFont("4x6", 2).drawString(state.musicInfo.artist, x, y + 8);
g.setFont("6x8", 1).drawString(state.musicInfo.track, x, y + 22);
}}, options));
}
if (state.music === "pause") {
require("notify").hide();
require("notify").hide("music");
}
}
function handleMusicStateUpdate(event) {
@ -59,7 +79,7 @@
function handleCallEvent(event) {
if (event.cmd === "accept") {
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="))});
Bangle.buzz();
}
@ -81,6 +101,7 @@
global.GB = (event) => {
switch (event.t) {
case "notify":
case "notify-":
handleNotificationEvent(event);
break;
case "musicinfo":

View File

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

View File

@ -12,6 +12,7 @@ options = {
on : bool, // turn screen on, default true
size : int, // height of notification, default 80 (max)
title : string, // optional title
id // optional notification ID, used with hide()
src : string, // optional source name
body : string, // optional body text
icon : string, // optional icon (image string)
@ -28,4 +29,11 @@ require("notify").show({
});
// remove it (can also be removed by tapping)
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 id = null;
/**
options = {
on : bool // turn screen on, default true
size : int // height of notification, default 80 (max)
title : string // optional title
id // optional notification ID, used with hide()
src : string // optional source name
body : string // optional body text
icon : string // optional icon (image string)
@ -14,6 +16,7 @@ var pos = 0;
exports.show = function(options) {
options = options||{};
if (options.on===undefined) options.on=true;
id = ("id" in options)?options.id:null;
var h = options.size||80;
var oldMode = Bangle.getLCDMode();
// TODO: throw exception if double-buffered?
@ -86,7 +89,15 @@ exports.show = function(options) {
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);
function anim() {
pos += 4;

View File

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

View File

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