aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/version.js
blob: a681bdfaab0ff07e6f6544a074d1a22a475604e3 (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
39
40
41
import manifest from '../../../manifest.json';
import VersionRepository from '../repositories/version';
import TabRepository from '../repositories/tab';
import Notifier from '../infrastructures/notifier';

export default class VersionInteractor {
  constructor() {
    this.versionRepository = new VersionRepository();
    this.tabRepository = new TabRepository();
    this.notifier = new Notifier();
  }

  async notifyIfUpdated() {
    if (!await this.checkUpdated()) {
      return;
    }

    let title = 'Vim Vixen ' + manifest.version + ' has been installed';
    let message = 'Click here to see release notes';
    this.notifier.notify(title, message, () => {
      let url = this.releaseNoteUrl(manifest.version);
      this.tabRepository.create(url);
    });
    this.versionRepository.update(manifest.version);
  }

  async checkUpdated() {
    let prev = await this.versionRepository.get();
    if (!prev) {
      return true;
    }
    return manifest.version !== prev;
  }

  releaseNoteUrl(version) {
    if (version) {
      return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version;
    }
    return 'https://github.com/ueokande/vim-vixen/releases/';
  }
}