diff --git a/apps.json b/apps.json index c8ca4e4e5..0e852bc7d 100644 --- a/apps.json +++ b/apps.json @@ -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", diff --git a/apps/notify/ChangeLog b/apps/notify/ChangeLog index 305624366..0dccc7930 100644 --- a/apps/notify/ChangeLog +++ b/apps/notify/ChangeLog @@ -1 +1,2 @@ 0.01: New Library! +0.02: Add notification ID option diff --git a/apps/notify/README.md b/apps/notify/README.md index d1751999b..a17caccea 100644 --- a/apps/notify/README.md +++ b/apps/notify/README.md @@ -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 ``` diff --git a/apps/notify/notify.js b/apps/notify/notify.js index 2fdec54ac..51569d912 100644 --- a/apps/notify/notify.js +++ b/apps/notify/notify.js @@ -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; diff --git a/apps/notifyfs/ChangeLog b/apps/notifyfs/ChangeLog index 305624366..0dccc7930 100644 --- a/apps/notifyfs/ChangeLog +++ b/apps/notifyfs/ChangeLog @@ -1 +1,2 @@ 0.01: New Library! +0.02: Add notification ID option diff --git a/apps/notifyfs/notify.js b/apps/notifyfs/notify.js index 703b4379f..3e6418e55 100644 --- a/apps/notifyfs/notify.js +++ b/apps/notifyfs/notify.js @@ -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);