File tree Expand file tree Collapse file tree 2 files changed +51
-82
lines changed Expand file tree Collapse file tree 2 files changed +51
-82
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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 } )
You can’t perform that action at this time.
0 commit comments