aboutsummaryrefslogtreecommitdiff
path: root/src/background/presenters/NotifyPresenter.ts
blob: 23932f7173ab22cde1c044a9517d927d57a57514 (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
const NOTIFICATION_ID = 'vimvixen-update';

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,
    });
  }
}