diff --git a/background/index.js b/background/index.js index 87ff2b4..a54bdb5 100644 --- a/background/index.js +++ b/background/index.js @@ -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 = () => { fetchCalendar().then((json) => { window.calendar = json; @@ -43,6 +52,9 @@ const fetchNewData = () => { }); fetchSpaceApi().then((json) => { + if (window.spaceApi.state.open !== json.state.open) { + sendNotification(json.state.open) + } window.spaceApi = json; updateBadge(window.spaceApi.state.open); }).catch((error) => { diff --git a/manifest.json b/manifest.json index c344066..fc64f40 100644 --- a/manifest.json +++ b/manifest.json @@ -24,7 +24,8 @@ }, "permissions": [ "https://usrspace.at/*", - "webRequest" + "webRequest", + "notifications" ], "author": "Thomas Rupprecht" //"developer": {