i have add-on , want issue notifications on desktop, if user actively using computer (e.g mouse pointer moving anywhere, i.e, not in browser window).
it possible using webextensions?
i believe this:
script.js
function notify(id, title, message) { var props = { "type": "basic", "title": title, "iconurl": "images/icon-128px.png", "message": message }; var propscopy = json.parse(json.stringify(props)); propscopy.requireinteraction = true; //prevent exception in firefox try { chrome.notifications.create(id, propscopy, function() {}); } catch (ee) { chrome.notifications.create(id, props, function() {}); } }
background.js
var standbynotifications = []; function registernotification(id, title, message) { if ([user inactive]) { standbynotifications.push({ "id": id, "title": title, "message": message }); } else { notify(id, title, message); } } setinterval(function() { if ([user inactive] === false) { var tmp = standbynotifications.reverse(); (var = tmp.length - 1; >= 0; i--) { notify(tmp[i].id, tmp[i].title, tmp[i].message); } standbynotifications = []; //clear } }, 1000);
chrome has dedicated api, chrome.idle
, detect idle state.
chrome.idle.querystate( 5 * 60, // seconds function(state) { if (state === "active") { // computer not locked, user active in last 5 minutes } else { // computer locked, or user inactive 5 minutes } } );
it provides event, chrome.idle.onstatechanged
, notify when state changes.
webextensions list api not yet supported (2016-07-21).
querystate
reports"active"
state.onstatechanged
not available.
Comments
Post a Comment