-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
36 lines (33 loc) · 1.26 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { Notification, Notifier } from "./notifiers/notifier.ts";
import { normalizeNotification } from "./notifiers/util.ts";
import { OsascriptNotifier } from "./notifiers/osascript.ts";
import { NotifySendNotifier } from "./notifiers/notify_send.ts";
import { SnoretoastNotifier } from "./notifiers/snoretoast.ts";
export type { Notification, Notifier };
export function notify(title: string, message: string): Promise<void>;
export function notify(notification: Notification): Promise<void>;
export async function notify(
titleOrNotification: string | Notification,
maybeMessage?: string,
): Promise<void> {
const notifier = createNotifier();
const notification = normalizeNotification(
titleOrNotification,
maybeMessage,
);
await notifier.notify(notification);
}
export function createNotifier(): Notifier {
switch (Deno.build.os) {
case "linux":
return new NotifySendNotifier();
case "darwin":
// TODO: Add support for `terminal-notifier` (https://github.com/julienXX/terminal-notifier)
return new OsascriptNotifier();
case "windows":
// TODO: Add support for Snarl and Windows 10 Toast Notifications
return new SnoretoastNotifier();
default:
throw new Error("Not supported: " + Deno.build.os);
}
}