aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background/index.js10
-rw-r--r--src/shared/versions/index.js39
-rw-r--r--src/shared/versions/release-notes.js8
-rw-r--r--src/shared/versions/storage.js11
4 files changed, 68 insertions, 0 deletions
diff --git a/src/background/index.js b/src/background/index.js
index 3ef712f..ff27796 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -3,6 +3,7 @@ import messages from 'shared/messages';
import BackgroundComponent from 'background/components/background';
import reducers from 'background/reducers';
import { createStore } from 'shared/store';
+import * as versions from 'shared/versions';
const store = createStore(reducers, (e, sender) => {
console.error('Vim-Vixen:', e);
@@ -17,3 +18,12 @@ const store = createStore(reducers, (e, sender) => {
const backgroundComponent = new BackgroundComponent(store);
store.dispatch(settingActions.load());
+
+versions.checkUpdated().then((updated) => {
+ if (!updated) {
+ return;
+ }
+ return versions.notify();
+}).then(() => {
+ return versions.commit();
+});
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 };
diff --git a/src/shared/versions/release-notes.js b/src/shared/versions/release-notes.js
new file mode 100644
index 0000000..6ef2335
--- /dev/null
+++ b/src/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/shared/versions/storage.js b/src/shared/versions/storage.js
new file mode 100644
index 0000000..37603c8
--- /dev/null
+++ b/src/shared/versions/storage.js
@@ -0,0 +1,11 @@
+const load = () => {
+ return browser.storage.local.get('version').then(({ version }) => {
+ return version;
+ });
+};
+
+const save = (version) => {
+ return browser.storage.local.set({ version });
+};
+
+export { load, save };