aboutsummaryrefslogtreecommitdiff
path: root/src/background/presenters/NotifyPresenter.ts
blob: c83c2052bccc675c7a61f089321de872c3d9ec74 (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 {
  notify(
    title: string,
    message: string,
    onclick: () => void,
  ): Promise<string> {
    const listener = (id: string) => {
      if (id !== NOTIFICATION_ID) {
        return;
      }

      onclick();

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

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