MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / notifyDesktop

Function notifyDesktop

src/utils/notify.ts:38–63  ·  view source on GitHub ↗
(n: DesktopNotification)

Source from the content-addressed store, hash-verified

36 * when the (very fast) osascript call finishes. Never rejects.
37 */
38export async function notifyDesktop(n: DesktopNotification): Promise<void> {
39 if (process.platform !== 'darwin') return; // macOS only
40
41 // Build: display notification "msg" with title "t" subtitle "s" sound name "Glass"
42 let script = `display notification "${escapeAppleScript(n.message)}" with title "${escapeAppleScript(n.title)}"`;
43 if (n.subtitle) script += ` subtitle "${escapeAppleScript(n.subtitle)}"`;
44 if (n.sound) script += ` sound name "Glass"`;
45
46 await new Promise<void>((resolve) => {
47 let done = false;
48 const finish = () => { if (!done) { done = true; resolve(); } };
49 try {
50 const child = spawn('osascript', ['-e', script], { stdio: 'ignore' });
51 child.on('error', (e: any) => {
52 logger.debug?.('desktop notification unavailable', { err: e?.message });
53 finish();
54 });
55 child.on('close', () => finish());
56 // Safety: never hang the caller on a stuck osascript.
57 setTimeout(() => { try { child.kill(); } catch {} finish(); }, 5000);
58 } catch (e: any) {
59 logger.debug?.('desktop notification failed to spawn', { err: e?.message });
60 finish();
61 }
62 });
63}

Callers 3

notify.test.tsFile · 0.85
runHeadlessFunction · 0.85
runOneFunction · 0.85

Calls 3

escapeAppleScriptFunction · 0.85
debugMethod · 0.80
finishFunction · 0.70

Tested by

no test coverage detected