From 213f4138ffbe23ec382c04c279a5f8271f0265eb Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Thu, 27 Dec 2018 20:34:05 +0100 Subject: [PATCH] add space status change notification --- background/index.js | 12 ++++++++++++ manifest.json | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) 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": {