Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): Experimental support for Snoretoast #3

Merged
merged 2 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});