diff --git a/deps.ts b/deps.ts index b690aa8..8948b87 100644 --- a/deps.ts +++ b/deps.ts @@ -1,3 +1,2 @@ -export { readAll } from "https://deno.land/std@0.178.0/streams/read_all.ts"; export { deferred } from "https://deno.land/std@0.178.0/async/deferred.ts"; export type { Deferred } from "https://deno.land/std@0.178.0/async/deferred.ts"; diff --git a/notifiers/subprocess.ts b/notifiers/subprocess.ts index f67323b..a55a53d 100644 --- a/notifiers/subprocess.ts +++ b/notifiers/subprocess.ts @@ -1,8 +1,9 @@ import type { Notification, Notifier } from "./notifier.ts"; import { normalizeNotification } from "./util.ts"; -import { readAll } from "../deps.ts"; export abstract class SubprocessNotifier implements Notifier { + #decoder = new TextDecoder(); + notify(title: string, message: string): Promise; notify(notification: Notification): Promise; async notify( @@ -14,20 +15,19 @@ export abstract class SubprocessNotifier implements Notifier { maybeMessage, ); const cmd = this.buildCmd(notification); - const process = Deno.run({ - cmd, + const [executable, ...args] = cmd; + if (executable == null) { + throw new Error( + "`buildCmd()` should return an array with at least one element", + ); + } + + const status = await new Deno.Command(executable, { + args, stderr: "piped", - }); - try { - const status = await process.status(); - if (!status.success) { - const output = await readAll(process.stderr); - const decoder = new TextDecoder(); - throw new Error(decoder.decode(output)); - } - } finally { - process.stderr.close(); - process.close(); + }).output(); + if (!status.success) { + throw new Error(this.#decoder.decode(status.stderr)); } }