diff --git a/README.md b/README.md index f2c1a5b..16f58d4 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ Once installed, the plugin will automatically send desktop notifications for: - Install on Ubuntu/Debian: `sudo apt-get install libnotify-bin` - Install on Fedora: `sudo dnf install libnotify` +### WSL2 (Windows) +- Requires [wsl-notify-send](https://github.com/stuartleeks/wsl-notify-send) +- Adding it to $PATH + ## Configuration The plugin works out of the box with sensible defaults: diff --git a/notificator.js b/notificator.js index 3b0f27a..1e78393 100644 --- a/notificator.js +++ b/notificator.js @@ -1,10 +1,14 @@ import { fileURLToPath } from 'url' import { dirname, join } from 'path' import { readFileSync, readdirSync } from 'fs' +import { execFile } from 'node:child_process' +import { promisify } from 'node:util' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) +const execFileAsync = promisify(execFile) + function stripJsonComments(str) { return str .replace(/\/\/.*$/gm, '') // Remove single-line comments @@ -54,6 +58,14 @@ function pickSoundFile(projectPath, seed) { return soundFiles[index] } +function getPlatform() { + const platform = process.platform + if (process.env.WSL_DISTRO_NAME) return 'wsl' + if (platform === 'darwin') return 'darwin' + if (platform === 'linux') return 'linux' + return 'unknown' +} + let currentSessionID = null export const NotificationPlugin = async ({ project, client, $, directory, worktree }) => { @@ -97,7 +109,7 @@ export const NotificationPlugin = async ({ project, client, $, directory, worktr const sendNotification = async (title, message) => { if (!enabled || !desktopNotificationEnabled) return - const platform = process.platform + const platform = getPlatform() try { if (platform === "darwin") { @@ -107,6 +119,9 @@ export const NotificationPlugin = async ({ project, client, $, directory, worktr } else if (platform === "linux") { await $`notify-send ${title} ${message}` } + else if (platform === "wsl") { + await execFileAsync("wsl-notify-send.exe", ['--category', title, message]) + } } catch (err) { console.error('Failed to send notification:', err.message) }