diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d7b38..5c49a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +- On WSL, toasts now work right after a fresh install or update, without a manual `chmod +x` on node-notifier's snoreToast executable (#152; issue #151). + +### Contributors + +- Thanks to @cardin for reporting and fixing the WSL toast issue in #152. + ## [1.1.2] - 2026-11-01 ### Fixed diff --git a/README.md b/README.md index 507c080..3d5bf0e 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ For sounds, you need one of: `paplay`, `aplay`, `mpv`, or `ffplay` **WSL**: Set `customIconPath` to a file on the Windows filesystem to avoid icon-path translation issues. You can copy an icon from this repository's `logos` folder. The path is passed to `snoretoast-*.exe`. +The plugin also restores the execute bit on node-notifier's bundled snoreToast executable when it loads, so a fresh install or update does not need a manual `chmod +x`. + In `opencode-notifier.json` config: ```json @@ -83,7 +85,7 @@ In `opencode-notifier.json` config: } ``` -- If notifications are not showing up, check out: [missing WSL notification](https://github.com/mikaelbr/node-notifier?tab=readme-ov-file#windows-and-wsl2) +- If notifications are still not showing up, check out: [missing WSL notification](https://github.com/mikaelbr/node-notifier?tab=readme-ov-file#windows-and-wsl2) ## Config file diff --git a/src/notify.ts b/src/notify.ts index 5e0039f..dae0f97 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -4,6 +4,7 @@ import { getLinuxNotificationID, rememberLinuxNotificationID, sendLinuxActionNot export { disposeLinuxNotifications } from "./notify-linux" import notifier from "node-notifier" import isWsl from "is-wsl" +import { ensureSnoreToastExecutable } from "./snoretoast" const DEBOUNCE_MS = 1000 @@ -13,6 +14,8 @@ let platformNotifier: { notify(notification: notifier.Notification, callback: no if (platform === "Windows_NT" || isWsl) { const { WindowsToaster } = notifier + // npm ships the snoreToast executable without +x, which WSL needs to launch it. + if (isWsl) ensureSnoreToastExecutable() platformNotifier = new WindowsToaster({ withFallback: false }) } else if (platform === "Linux" || platform.match(/BSD$/)) { const { NotifySend } = notifier diff --git a/src/snoretoast.ts b/src/snoretoast.ts new file mode 100644 index 0000000..dae6fb1 --- /dev/null +++ b/src/snoretoast.ts @@ -0,0 +1,26 @@ +import { chmodSync, statSync } from "node:fs" +import { createRequire } from "node:module" +import { dirname, join } from "node:path" + +function debug(message: string): void { + if (process.env.OPENCODE_NOTIFIER_DEBUG) console.error(`[opencode-notifier] snoreToast: ${message}`) +} + +/** + * Called once at load on WSL. npm publishes node-notifier's snoreToast binaries + * without +x, WSL needs it to launch them, and node-notifier swallows the + * EACCES, so toasts fail silently. Adds +x like a manual `chmod +x` would. + * The x64/x86 pick mirrors node-notifier's notifiers/toaster.js. Never throws. + */ +export function ensureSnoreToastExecutable(): void { + try { + const root = dirname(createRequire(import.meta.url).resolve("node-notifier")) + const path = join(root, "vendor", "snoreToast", `snoretoast-x${process.arch === "x64" ? "64" : "86"}.exe`) + const { mode } = statSync(path) + if (mode & 0o100) return + chmodSync(path, mode | 0o111) + debug(`restored +x on ${path}`) + } catch (error) { + debug(`could not restore +x: ${String(error)}`) + } +}