Move versions to background
This commit is contained in:
parent
b69cc04856
commit
067da88d06
6 changed files with 5 additions and 5 deletions
|
@ -6,7 +6,7 @@ import IndicatorComponent from 'background/components/indicator';
|
|||
import reducers from 'background/reducers';
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import promise from 'redux-promise';
|
||||
import * as versions from 'shared/versions';
|
||||
import * as versions from './shared/versions';
|
||||
|
||||
const store = createStore(
|
||||
reducers,
|
||||
|
|
38
src/background/shared/versions/index.js
Normal file
38
src/background/shared/versions/index.js
Normal file
|
@ -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 };
|
8
src/background/shared/versions/release-notes.js
Normal file
8
src/background/shared/versions/release-notes.js
Normal file
|
@ -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 };
|
10
src/background/shared/versions/storage.js
Normal file
10
src/background/shared/versions/storage.js
Normal file
|
@ -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 };
|
Reference in a new issue