Skip to content

Commit 019a0f4

Browse files
committed
[fix] remove onClick handler
1 parent 4ea2342 commit 019a0f4

File tree

2 files changed

+51
-82
lines changed

2 files changed

+51
-82
lines changed

src/index.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import chromep from 'chrome-promise'
2+
3+
const { name, icons = {} } = chrome.runtime.getManifest()
4+
5+
const iconUrl =
6+
icons[
7+
Object.keys(icons)
8+
.map((size) => parseInt(size))
9+
.reduce((r, x) => (r > x ? r : x), 0)
10+
]
11+
12+
/**
13+
* @example
14+
* notify.create({
15+
* message: 'Click here for awesomeness.'
16+
* onClick: yesPlease
17+
* buttons: [
18+
* { title: 'OK', onClick: yesPlease },
19+
* { title: 'No way', onClick: dontWantIt }
20+
* ]
21+
* })
22+
*/
23+
const create = ({
24+
buttons = [],
25+
id,
26+
...rest
27+
}: Partial<chrome.notifications.NotificationOptions> & {
28+
id?: string
29+
}) => {
30+
const msg = {
31+
type: 'basic' as browser.notifications.TemplateType,
32+
title: name,
33+
iconUrl,
34+
buttons: buttons.map(({ title, iconUrl }) => ({
35+
title,
36+
iconUrl,
37+
})),
38+
...rest,
39+
} as browser.notifications.CreateNotificationOptions
40+
41+
const created =
42+
typeof id === 'string'
43+
? chromep.notifications.create(id, msg)
44+
: chromep.notifications.create(msg)
45+
46+
return created
47+
}
48+
49+
export const notify = (message: string): Promise<string> => create({ message })
50+
51+
Object.assign(notify, chrome.notifications, chromep.notifications, { create })

0 commit comments

Comments
 (0)