This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
744d142
commit 10e4382
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const LibPaths = { | ||
notifications: { | ||
darwin: { | ||
prod: window.NL_PATH + "/lib/alerter", | ||
dev: window.NL_PATH + "/building/_app_scaffolds/mac/myapp.app/Contents/Resources/lib/alerter" | ||
} | ||
} | ||
} | ||
|
||
export default LibPaths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { os, window as w } from "@neutralinojs/lib" | ||
import LibPaths from "../lib-paths"; | ||
import { getMode } from "./env"; | ||
import { focusWindow } from "./window"; | ||
|
||
const mode = getMode() | ||
|
||
export interface NotificationOptions { | ||
title: string, | ||
content: string, | ||
sound?: boolean, | ||
timeout?: number, | ||
type?: os.Icon, | ||
} | ||
|
||
export async function showNotification(options: NotificationOptions) { | ||
try { | ||
switch (window.NL_OS) { | ||
case "Darwin": | ||
await darwin(options); | ||
break; | ||
default: | ||
await os.showNotification(options.title,options.content,(options.type || os.Icon.INFO)) | ||
break; | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
async function darwin(options: NotificationOptions) { | ||
try { | ||
const alerter = LibPaths.notifications.darwin[mode] | ||
os.execCommand(`${alerter} -message "${options.content}" -title "${options.title}" -sender "AutoEvent" ${options.timeout ? '-timeout ' + Math.floor(options.timeout) : ''} ${options.sound ? '-sound default' : ''}`).then(cmd => { | ||
if (cmd.stdOut === "@ACTIONCLICKED") { | ||
focusWindow() | ||
} | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} |