From 87ed1f43a96a67c4901c267aee96784de1d45889 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 22 Jul 2018 09:30:01 +0900 Subject: Version as Clean Architecture --- src/background/usecases/version.js | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/background/usecases/version.js (limited to 'src/background/usecases') diff --git a/src/background/usecases/version.js b/src/background/usecases/version.js new file mode 100644 index 0000000..a681bdf --- /dev/null +++ b/src/background/usecases/version.js @@ -0,0 +1,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/'; + } +} -- cgit v1.2.3