(text, title, image, onclick)
| 16 | |
| 17 | /** @this {GMContext} */ |
| 18 | export function createNotification(text, title, image, onclick) { |
| 19 | let options; |
| 20 | let tag; |
| 21 | if (isObject(text)) { |
| 22 | options = nullObjFrom(text); |
| 23 | text = options.text; |
| 24 | tag = options.tag; |
| 25 | } else { |
| 26 | options = createNullObj(); |
| 27 | options.text = text; |
| 28 | options.title = title; |
| 29 | options.image = image; |
| 30 | options.onclick = onclick; |
| 31 | } |
| 32 | if (!text) throw new SafeError('Notification `text` is required!'); |
| 33 | const id = `${this.id}:${options.tag = tag ?? safeGetUniqId()}`; |
| 34 | const msg = createNullObj(); |
| 35 | for (const k in options) { |
| 36 | msg[k] = isFunction(options[k]) ? true : options[k]; |
| 37 | } |
| 38 | msg.id = id; |
| 39 | notifications[id] = options; |
| 40 | bridge.post('Notification', msg); |
| 41 | return { |
| 42 | remove: () => bridge.promise('RemoveNotification', id), |
| 43 | }; |
| 44 | } |
nothing calls this directly
no test coverage detected