forked from XimeX/usrspace-browser-addon
add space status change notification
This commit is contained in:
parent
e21dac9934
commit
213f4138ff
|
@ -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) => {
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"https://usrspace.at/*",
|
"https://usrspace.at/*",
|
||||||
"webRequest"
|
"webRequest",
|
||||||
|
"notifications"
|
||||||
],
|
],
|
||||||
"author": "Thomas Rupprecht"
|
"author": "Thomas Rupprecht"
|
||||||
//"developer": {
|
//"developer": {
|
||||||
|
|
Loading…
Reference in New Issue