diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-11 21:01:48 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-11 21:01:48 +0900 |
commit | 067da88d06fbffca323ecdbaf8b1011f88225219 (patch) | |
tree | 3aab1472374310a5b724f1b7d08a7ab465a7718d /src/background/shared | |
parent | b69cc04856fd21d325193d56e212e4dbf07cb762 (diff) |
Move versions to background
Diffstat (limited to 'src/background/shared')
-rw-r--r-- | src/background/shared/versions/index.js | 38 | ||||
-rw-r--r-- | src/background/shared/versions/release-notes.js | 8 | ||||
-rw-r--r-- | src/background/shared/versions/storage.js | 10 |
3 files changed, 56 insertions, 0 deletions
diff --git a/src/background/shared/versions/index.js b/src/background/shared/versions/index.js new file mode 100644 index 0000000..aa09c92 --- /dev/null +++ b/src/background/shared/versions/index.js @@ -0,0 +1,38 @@ +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 = async() => { + let prev = await storage.load(); + 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 }; diff --git a/src/background/shared/versions/release-notes.js b/src/background/shared/versions/release-notes.js new file mode 100644 index 0000000..6ef2335 --- /dev/null +++ b/src/background/shared/versions/release-notes.js @@ -0,0 +1,8 @@ +const url = (version) => { + if (version) { + return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version; + } + return 'https://github.com/ueokande/vim-vixen/releases/'; +}; + +export { url }; diff --git a/src/background/shared/versions/storage.js b/src/background/shared/versions/storage.js new file mode 100644 index 0000000..7883258 --- /dev/null +++ b/src/background/shared/versions/storage.js @@ -0,0 +1,10 @@ +const load = async() => { + let { version } = await browser.storage.local.get('version'); + return version; +}; + +const save = (version) => { + return browser.storage.local.set({ version }); +}; + +export { load, save }; |