aboutsummaryrefslogtreecommitdiff
path: root/src/background/presenters/NotifyPresenter.ts
blob: 8fa4acbb961b11f60e2120ee6fffab416de2562c (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
import { injectable } from 'tsyringe';

const NOTIFICATION_ID = 'vimvixen-update';

@injectable()
export default class NotifyPresenter {
  async notify(
    title: string,
    message: string,
    onclick: () => void,
  ): Promise<void> {
    const listener = (id: string) => {
      if (id !== NOTIFICATION_ID) {
        return;
      }

      onclick();

      browser.notifications.onClicked.removeListener(listener);
    };
    browser.notifications.onClicked.addListener(listener);

    await browser.notifications.create(NOTIFICATION_ID, {
      'type': 'basic',
      'iconUrl': browser.extension.getURL('resources/icon_48x48.png'),
      title,
      message,
    });
  }
}