Merge pull request #539 from ueokande/webext-on-install-event

Use browser.runtime.onInstalled event
jh-changes
Shin'ya Ueoka 6 years ago committed by GitHub
commit cebd64a69f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/background/controllers/VersionController.js
  2. 13
      src/background/controllers/version.js
  3. 8
      src/background/index.js
  4. 2
      src/background/presenters/NotifyPresenter.js
  5. 29
      src/background/usecases/VersionUseCase.js

@ -5,7 +5,7 @@ export default class VersionController {
this.versionUseCase = new VersionUseCase();
}
notifyIfUpdated() {
this.versionUseCase.notifyIfUpdated();
notify() {
this.versionUseCase.notify();
}
}

@ -0,0 +1,13 @@
import VersionInteractor from '../usecases/version';
export default class VersionController {
constructor() {
this.versionInteractor = new VersionInteractor();
}
notifyIfUpdated() {
browser.runtime.onInstalled.addListener(() => {
return this.versionInteractor.notify();
});
}
}

@ -3,6 +3,12 @@ import SettingController from './controllers/SettingController';
import VersionController from './controllers/VersionController';
new SettingController().reload();
new VersionController().notifyIfUpdated();
browser.runtime.onInstalled.addListener((details) => {
if (details.reason !== 'install' && details.reason !== 'update') {
return;
}
new VersionController().notify();
});
new ContentMessageListener().run();

@ -1,6 +1,6 @@
const NOTIFICATION_ID = 'vimvixen-update';
export default class Notifier {
export default class NotifyPresenter {
notify(title, message, onclick) {
const listener = (id) => {
if (id !== NOTIFICATION_ID) {

@ -1,40 +1,25 @@
import manifest from '../../../manifest.json';
import VersionRepository from '../repositories/VersionRepository';
import TabPresenter from '../presenters/TabPresenter';
import Notifier from '../infrastructures/Notifier';
import NotifyPresenter from '../presenters/NotifyPresenter';
export default class VersionUseCase {
constructor() {
this.versionRepository = new VersionRepository();
this.tabPresenter = new TabPresenter();
this.notifier = new Notifier();
this.notifyPresenter = new NotifyPresenter();
}
async notifyIfUpdated() {
if (!await this.checkUpdated()) {
return;
}
let title = 'Vim Vixen ' + manifest.version + ' has been installed';
notify() {
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);
let url = this.releaseNoteUrl(manifest.version);
this.notifyPresenter.notify(title, message, () => {
this.tabPresenter.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/tag/${version}`;
}
return 'https://github.com/ueokande/vim-vixen/releases/';
}