From 88e216d49bbbf4312dde678a890733a6e4c4cde8 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 5 May 2018 17:35:24 +0900 Subject: Notify when updated --- src/shared/versions/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/shared/versions/index.js (limited to 'src/shared/versions/index.js') diff --git a/src/shared/versions/index.js b/src/shared/versions/index.js new file mode 100644 index 0000000..ee9f3b5 --- /dev/null +++ b/src/shared/versions/index.js @@ -0,0 +1,39 @@ +import * as storage from './storage'; +import * as releaseNotes from './release-notes'; +import manifest from '../../../manifest.json'; + +const NOTIFICATION_ID = 'vimvixen-update'; + +const notificationClickListener = (id) => { + if (id !== NOTIFICATION_ID) { + return; + } + + browser.tabs.create({ url: releaseNotes.url(manifest.version) }); + browser.notifications.onClicked.removeListener(notificationClickListener); +}; + +const checkUpdated = () => { + return storage.load().then((prev) => { + if (!prev) { + return true; + } + return manifest.version !== prev; + }); +}; + +const notify = () => { + browser.notifications.onClicked.addListener(notificationClickListener); + return browser.notifications.create(NOTIFICATION_ID, { + 'type': 'basic', + 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'), + 'title': 'Vim Vixen ' + manifest.version + ' has been installed', + 'message': 'Click here to see release notes', + }); +}; + +const commit = () => { + storage.save(manifest.version); +}; + +export { checkUpdated, notify, commit }; -- cgit v1.2.3