Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Implemented Notifications for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Feb 4, 2024
1 parent 744d142 commit 10e4382
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Binary file not shown.
10 changes: 10 additions & 0 deletions svelte/src/lib/lib-paths.ts
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
42 changes: 42 additions & 0 deletions svelte/src/lib/modules/notifications.ts
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)
}
}

0 comments on commit 10e4382

Please sign in to comment.