From e5ba4a87fe612994af68af554a181171d5c71a79 Mon Sep 17 00:00:00 2001 From: Cardin Lee <553816+cardin@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:55:52 +0800 Subject: [PATCH 1/2] fix(wsl): restore snoreToast +x so toasts work after a fresh install --- CHANGELOG.md | 4 +++ README.md | 4 ++- src/notify.ts | 3 ++ src/snoretoast.test.ts | 48 ++++++++++++++++++++++++++++++ src/snoretoast.ts | 67 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/snoretoast.test.ts create mode 100644 src/snoretoast.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d7b38..df8cad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +- On WSL, a fresh install or update no longer needs a manual `chmod +x` on node-notifier's bundled snoreToast executable. The plugin restores the execute bit when it loads, so toast notifications work immediately. + ## [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.test.ts b/src/snoretoast.test.ts new file mode 100644 index 0000000..6d8ae0f --- /dev/null +++ b/src/snoretoast.test.ts @@ -0,0 +1,48 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { chmodSync, mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { isExecutable, makeExecutable, snoreToastPath } from "./snoretoast" + +const tempDirs: string[] = [] + +function tempFile(mode: number): string { + const dir = mkdtempSync(join(tmpdir(), "notifier-snoretoast-")) + tempDirs.push(dir) + const file = join(dir, "snoretoast-x64.exe") + writeFileSync(file, "") + chmodSync(file, mode) + return file +} + +afterEach(() => { + for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true }) +}) + +describe("makeExecutable", () => { + test("restores the execute bit on a file published as 0644", () => { + const file = tempFile(0o644) + expect(isExecutable(file)).toBe(false) + + expect(makeExecutable(file)).toBe(true) + expect(statSync(file).mode & 0o777).toBe(0o755) + }) + + test("leaves an already executable file alone", () => { + const file = tempFile(0o755) + + expect(makeExecutable(file)).toBe(true) + expect(statSync(file).mode & 0o777).toBe(0o755) + }) + + test("returns false for a missing file instead of throwing", () => { + expect(makeExecutable(join(tmpdir(), "notifier-missing-snoretoast.exe"))).toBe(false) + }) +}) + +describe("snoreToastPath", () => { + test("selects the binary matching the architecture", () => { + expect(snoreToastPath("x64")).toEndWith(join("vendor", "snoreToast", "snoretoast-x64.exe")) + expect(snoreToastPath("arm64")).toEndWith(join("vendor", "snoreToast", "snoretoast-x86.exe")) + }) +}) diff --git a/src/snoretoast.ts b/src/snoretoast.ts new file mode 100644 index 0000000..34fa931 --- /dev/null +++ b/src/snoretoast.ts @@ -0,0 +1,67 @@ +import { accessSync, chmodSync, constants } from "node:fs" +import { createRequire } from "node:module" +import { dirname, join } from "node:path" + +const PACKAGE = "node-notifier" +const VENDOR_DIR = join("vendor", "snoreToast") + +function debug(message: string): void { + if (process.env.OPENCODE_NOTIFIER_DEBUG) { + console.error(`[opencode-notifier] ${message}`) + } +} + +/** + * The snoreToast executable node-notifier uses for this architecture, or null + * when the package cannot be resolved (for example from a bundled layout). + */ +export function snoreToastPath(arch: string = process.arch): string | null { + try { + const require = createRequire(import.meta.url) + const packageRoot = dirname(require.resolve(PACKAGE)) + const binary = `snoretoast-x${arch === "x64" ? "64" : "86"}.exe` + return join(packageRoot, VENDOR_DIR, binary) + } catch { + return null + } +} + +/** True when the file exists and carries an execute bit. */ +export function isExecutable(path: string): boolean { + try { + accessSync(path, constants.X_OK) + return true + } catch { + return false + } +} + +/** Adds +x when needed. Returns true when the file is executable afterwards. */ +export function makeExecutable(path: string): boolean { + if (isExecutable(path)) { + return true + } + try { + chmodSync(path, 0o755) + } catch (error) { + // A read-only install cannot be repaired here; the caller keeps today's behavior. + debug(`snoreToast: chmod failed for ${path}: ${String(error)}`) + return false + } + debug(`snoreToast: restored +x on ${path}`) + return isExecutable(path) +} + +/** + * npm publishes node-notifier with its snoreToast executables at 0644 even + * though the repository stores them 0755. WSL still enforces the Unix execute + * bit for Windows binaries, so every toast spawn fails with EACCES inside + * node-notifier, which reports no error to the plugin. Restore the bit once at + * load so a fresh install delivers notifications without a manual chmod. + * + * Never throws: a read-only install keeps today's behavior. + */ +export function ensureSnoreToastExecutable(arch: string = process.arch): boolean { + const path = snoreToastPath(arch) + return path ? makeExecutable(path) : false +} From 10ded8b6e5872ffe1555310193384b8f05667c2b Mon Sep 17 00:00:00 2001 From: mohak34 Date: Sat, 14 Nov 2026 21:38:18 +0000 Subject: [PATCH 2/2] refactor(wsl): collapse snoreToast fix to one function, keep file mode, fix changelog Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 +++- src/snoretoast.test.ts | 48 ----------------------------- src/snoretoast.ts | 69 +++++++++--------------------------------- 3 files changed, 19 insertions(+), 104 deletions(-) delete mode 100644 src/snoretoast.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index df8cad8..5c49a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ All notable changes to this project will be documented in this file. ### Fixed -- On WSL, a fresh install or update no longer needs a manual `chmod +x` on node-notifier's bundled snoreToast executable. The plugin restores the execute bit when it loads, so toast notifications work immediately. +- 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 diff --git a/src/snoretoast.test.ts b/src/snoretoast.test.ts deleted file mode 100644 index 6d8ae0f..0000000 --- a/src/snoretoast.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { afterEach, describe, expect, test } from "bun:test" -import { chmodSync, mkdtempSync, rmSync, statSync, writeFileSync } from "node:fs" -import { tmpdir } from "node:os" -import { join } from "node:path" -import { isExecutable, makeExecutable, snoreToastPath } from "./snoretoast" - -const tempDirs: string[] = [] - -function tempFile(mode: number): string { - const dir = mkdtempSync(join(tmpdir(), "notifier-snoretoast-")) - tempDirs.push(dir) - const file = join(dir, "snoretoast-x64.exe") - writeFileSync(file, "") - chmodSync(file, mode) - return file -} - -afterEach(() => { - for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true }) -}) - -describe("makeExecutable", () => { - test("restores the execute bit on a file published as 0644", () => { - const file = tempFile(0o644) - expect(isExecutable(file)).toBe(false) - - expect(makeExecutable(file)).toBe(true) - expect(statSync(file).mode & 0o777).toBe(0o755) - }) - - test("leaves an already executable file alone", () => { - const file = tempFile(0o755) - - expect(makeExecutable(file)).toBe(true) - expect(statSync(file).mode & 0o777).toBe(0o755) - }) - - test("returns false for a missing file instead of throwing", () => { - expect(makeExecutable(join(tmpdir(), "notifier-missing-snoretoast.exe"))).toBe(false) - }) -}) - -describe("snoreToastPath", () => { - test("selects the binary matching the architecture", () => { - expect(snoreToastPath("x64")).toEndWith(join("vendor", "snoreToast", "snoretoast-x64.exe")) - expect(snoreToastPath("arm64")).toEndWith(join("vendor", "snoreToast", "snoretoast-x86.exe")) - }) -}) diff --git a/src/snoretoast.ts b/src/snoretoast.ts index 34fa931..dae6fb1 100644 --- a/src/snoretoast.ts +++ b/src/snoretoast.ts @@ -1,67 +1,26 @@ -import { accessSync, chmodSync, constants } from "node:fs" +import { chmodSync, statSync } from "node:fs" import { createRequire } from "node:module" import { dirname, join } from "node:path" -const PACKAGE = "node-notifier" -const VENDOR_DIR = join("vendor", "snoreToast") - function debug(message: string): void { - if (process.env.OPENCODE_NOTIFIER_DEBUG) { - console.error(`[opencode-notifier] ${message}`) - } + if (process.env.OPENCODE_NOTIFIER_DEBUG) console.error(`[opencode-notifier] snoreToast: ${message}`) } /** - * The snoreToast executable node-notifier uses for this architecture, or null - * when the package cannot be resolved (for example from a bundled layout). + * 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 snoreToastPath(arch: string = process.arch): string | null { - try { - const require = createRequire(import.meta.url) - const packageRoot = dirname(require.resolve(PACKAGE)) - const binary = `snoretoast-x${arch === "x64" ? "64" : "86"}.exe` - return join(packageRoot, VENDOR_DIR, binary) - } catch { - return null - } -} - -/** True when the file exists and carries an execute bit. */ -export function isExecutable(path: string): boolean { +export function ensureSnoreToastExecutable(): void { try { - accessSync(path, constants.X_OK) - return true - } catch { - return false - } -} - -/** Adds +x when needed. Returns true when the file is executable afterwards. */ -export function makeExecutable(path: string): boolean { - if (isExecutable(path)) { - return true - } - try { - chmodSync(path, 0o755) + 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) { - // A read-only install cannot be repaired here; the caller keeps today's behavior. - debug(`snoreToast: chmod failed for ${path}: ${String(error)}`) - return false + debug(`could not restore +x: ${String(error)}`) } - debug(`snoreToast: restored +x on ${path}`) - return isExecutable(path) -} - -/** - * npm publishes node-notifier with its snoreToast executables at 0644 even - * though the repository stores them 0755. WSL still enforces the Unix execute - * bit for Windows binaries, so every toast spawn fails with EACCES inside - * node-notifier, which reports no error to the plugin. Restore the bit once at - * load so a fresh install delivers notifications without a manual chmod. - * - * Never throws: a read-only install keeps today's behavior. - */ -export function ensureSnoreToastExecutable(arch: string = process.arch): boolean { - const path = snoreToastPath(arch) - return path ? makeExecutable(path) : false }