-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(windows): Experimental support for Snoretoast (#3)
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
deno-notifier.ts is a Deno module for sending desktop notifications. It is | ||
written in pure TypeScript. | ||
|
||
> **This module is still highly experimental! In particular, it has not been | ||
> fully tested on Windows and Mac OS.** | ||
## Usage | ||
|
||
```typescript | ||
|
@@ -16,6 +19,26 @@ import { notify } from "https://deno.land/x/[email protected]/mod.ts"; | |
await notify("This is a title", "This is a message"); | ||
``` | ||
|
||
## Requirements | ||
|
||
### Linux | ||
|
||
You'll need to install one of the following: | ||
|
||
- `notify-send` | ||
|
||
### Mac OS X | ||
|
||
You'll need to install one of the following: | ||
|
||
- `osascript` | ||
|
||
### Windows | ||
|
||
You'll need to install one of the following: | ||
|
||
- [Snoretoast](https://github.com/KDE/snoretoast) | ||
|
||
## Prior works | ||
|
||
- Node.js | ||
|
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,27 @@ | ||
import { SubprocessNotifier } from "./subprocess.ts"; | ||
import type { Notification } from "./notifier.ts"; | ||
|
||
export interface SnoretoastNotifierOptions { | ||
executable?: string; | ||
} | ||
|
||
const defaultExecutable = "snoretoast.exe"; | ||
|
||
/** | ||
* @see https://github.com/KDE/snoretoast | ||
*/ | ||
export class SnoretoastNotifier extends SubprocessNotifier { | ||
#executable: string; | ||
constructor( | ||
options: SnoretoastNotifierOptions = { executable: defaultExecutable }, | ||
) { | ||
super(); | ||
const { executable } = options; | ||
this.#executable = executable ?? defaultExecutable; | ||
} | ||
|
||
buildCmd(notification: Notification): string[] { | ||
const { title, message } = notification; | ||
return [this.#executable, "-t", title, "-m", message]; | ||
} | ||
} |
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,13 @@ | ||
import { SnoretoastNotifier } from "./snoretoast.ts"; | ||
import { assertEquals } from "../test_deps.ts"; | ||
|
||
Deno.test("SnoretoastNotifier#buildCmd", () => { | ||
const notifier = new SnoretoastNotifier(); | ||
const notification = Object.freeze({ | ||
title: "Hello", | ||
message: "World", | ||
}); | ||
const actual = notifier.buildCmd(notification); | ||
const expected = ["snoretoast.exe", "-t", "Hello", "-m", "World"]; | ||
assertEquals(actual, expected); | ||
}); |