Skip to content
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion notificator.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
}
Expand Down