add space status change notification

This commit is contained in:
Thomas Rupprecht 2018-12-27 20:34:05 +01:00
parent e21dac9934
commit 213f4138ff
2 changed files with 14 additions and 1 deletions

View File

@ -35,6 +35,15 @@ const updateBadge = (open) => {
}); });
}; };
const sendNotification = (open) => {
browser.notifications.create('notification-id', {
type: 'basic',
iconUrl: browser.runtime.getURL('icons/logo.svg'),
title: 'Space Status',
message: 'Space ist jetzt ' + (open ? 'offen' : 'geschlossen') + '.'
});
};
const fetchNewData = () => { const fetchNewData = () => {
fetchCalendar().then((json) => { fetchCalendar().then((json) => {
window.calendar = json; window.calendar = json;
@ -43,6 +52,9 @@ const fetchNewData = () => {
}); });
fetchSpaceApi().then((json) => { fetchSpaceApi().then((json) => {
if (window.spaceApi.state.open !== json.state.open) {
sendNotification(json.state.open)
}
window.spaceApi = json; window.spaceApi = json;
updateBadge(window.spaceApi.state.open); updateBadge(window.spaceApi.state.open);
}).catch((error) => { }).catch((error) => {

View File

@ -24,7 +24,8 @@
}, },
"permissions": [ "permissions": [
"https://usrspace.at/*", "https://usrspace.at/*",
"webRequest" "webRequest",
"notifications"
], ],
"author": "Thomas Rupprecht" "author": "Thomas Rupprecht"
//"developer": { //"developer": {