Skip to content

Commit

Permalink
feat(windows): Experimental support for Snoretoast (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Jul 4, 2021
1 parent f0e39b7 commit 3793df8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 27 additions & 0 deletions notifiers/snoretoast.ts
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];
}
}
13 changes: 13 additions & 0 deletions notifiers/snoretoast_test.ts
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);
});

0 comments on commit 3793df8

Please sign in to comment.