notify/notifyfs: Add notification ID option
So you can hide a notification only if it hasn't been replaced yet.master
parent
350bec8aaf
commit
9c55b47263
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
0.01: New Library!
|
0.01: New Library!
|
||||||
|
0.02: Add notification ID option
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
0.01: New Library!
|
0.01: New Library!
|
||||||
|
0.02: Add notification ID option
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue