notify/notifyfs: Add notification ID option

So you can hide a notification only if it hasn't been replaced yet.
master
Richard de Boer 2020-07-07 20:45:03 +02:00
parent 350bec8aaf
commit 9c55b47263
6 changed files with 36 additions and 4 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",

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