mirror of
https://github.com/Ximi1970/systray-x.git
synced 2025-11-06 13:25:49 +01:00
Add message query method
This commit is contained in:
@@ -1 +1,54 @@
|
|||||||
console.log("Hello world!");
|
console.log("Starting background.js");
|
||||||
|
|
||||||
|
var SysTrayX = {};
|
||||||
|
|
||||||
|
SysTrayX.Messaging = {
|
||||||
|
|
||||||
|
initialized: false,
|
||||||
|
|
||||||
|
unreadFilter: { unread: true },
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
if (this.initialized) {
|
||||||
|
console.log("Messaging already initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("Enabling Messaging");
|
||||||
|
|
||||||
|
this.unReadMessages(this.unreadFilter).then(this.unreadCb);
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use the messages API to get the unread messages (Promise)
|
||||||
|
* Be aware that the data is only avaiable inside the callback
|
||||||
|
*/
|
||||||
|
unReadMessages: async function(filter) {
|
||||||
|
let page = await browser.messages.query(filter);
|
||||||
|
|
||||||
|
let unread = page.messages.length;
|
||||||
|
|
||||||
|
while (page.id) {
|
||||||
|
page = await browser.messages.continueList(page.id);
|
||||||
|
|
||||||
|
unread = unread + page.messages.length
|
||||||
|
}
|
||||||
|
|
||||||
|
return unread;
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callback for unReadMessages
|
||||||
|
*/
|
||||||
|
unreadCb: function(count) {
|
||||||
|
console.log("SysTrayX unread "+count);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Starting SysTray-X");
|
||||||
|
|
||||||
|
SysTrayX.Messaging.init();
|
||||||
|
|
||||||
|
console.log("Done");
|
||||||
|
|||||||
@@ -17,11 +17,11 @@
|
|||||||
"48": "icons/message.svg"
|
"48": "icons/message.svg"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"permissions": [
|
||||||
|
"messagesRead"
|
||||||
|
],
|
||||||
|
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["background.js"]
|
"scripts": ["background.js"]
|
||||||
},
|
|
||||||
|
|
||||||
"browser_action": {
|
|
||||||
"default_icon": "icons/message.svg"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user