Notify when updated
This commit is contained in:
parent
a63311bd34
commit
88e216d49b
7 changed files with 161 additions and 1 deletions
39
src/shared/versions/index.js
Normal file
39
src/shared/versions/index.js
Normal file
|
@ -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 };
|
5
src/shared/versions/release-notes.js
Normal file
5
src/shared/versions/release-notes.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const url = (version) => {
|
||||
return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version;
|
||||
};
|
||||
|
||||
export { url };
|
11
src/shared/versions/storage.js
Normal file
11
src/shared/versions/storage.js
Normal file
|
@ -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 };
|
Reference in a new issue