MCPcopy Index your code
hub / github.com/MALSync/MALSync / sendNotification

Function sendNotification

src/background/notifications.ts:5–34  ·  view source on GitHub ↗
(options: {
  url: string;
  title: string;
  text: string;
  image?: string;
  sticky?: boolean;
})

Source from the content-addressed store, hash-verified

3
4// Only works on the background Page
5export async function sendNotification(options: {
6 url: string;
7 title: string;
8 text: string;
9 image?: string;
10 sticky?: boolean;
11}) {
12 if (!options.image) options.image = defaultImg;
13
14 con.m('Notification').log(options);
15
16 const imgBlob = await getImageBlob(options.image);
17 const messageArray = {
18 type: 'basic' as const,
19 title: options.title,
20 message: options.text,
21 iconUrl: imgBlob,
22 contextMessage: 'MAL-Sync',
23 requireInteraction: options.sticky ?? false,
24 eventTime: Date.now(),
25 };
26 try {
27 chrome.notifications.create(options.url, messageArray);
28 } catch (e) {
29 con.error(e);
30 // @ts-ignore
31 delete messageArray.requireInteraction;
32 chrome.notifications.create(options.url, messageArray);
33 }
34}
35
36function getImageBlob(url, fallback = false): Promise<string> {
37 if (fallback) url = defaultImg;

Callers 1

messageHandlerFunction · 0.90

Calls 2

getImageBlobFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected