aboutsummaryrefslogtreecommitdiff
path: root/src/shared/versions/index.js
blob: ba3d18398ead923d39c582f7245203d48e00cb7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 };