@mohak34/opencode-notifier 0.1.33 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/dist/index.js +18 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -55,6 +55,7 @@ Create `~/.config/opencode/opencode-notifier.json` with the defaults:
55
55
  "showSessionTitle": false,
56
56
  "showIcon": true,
57
57
  "suppressWhenFocused": true,
58
+ "enableOnDesktop": false,
58
59
  "notificationSystem": "osascript",
59
60
  "linux": {
60
61
  "grouping": false
@@ -112,6 +113,8 @@ Create `~/.config/opencode/opencode-notifier.json` with the defaults:
112
113
  "showProjectName": true,
113
114
  "showSessionTitle": false,
114
115
  "showIcon": true,
116
+ "suppressWhenFocused": true,
117
+ "enableOnDesktop": false,
115
118
  "notificationSystem": "osascript"
116
119
  }
117
120
  ```
@@ -123,6 +126,7 @@ Create `~/.config/opencode/opencode-notifier.json` with the defaults:
123
126
  - `showSessionTitle` - Include the session title in notification messages via `{sessionTitle}` placeholder (default: true)
124
127
  - `showIcon` - Show OpenCode icon, Windows/Linux only (default: true)
125
128
  - `suppressWhenFocused` - Skip notifications and sounds when the terminal is the active window (default: true). See [Focus detection](#focus-detection) for platform details
129
+ - `enableOnDesktop` - Run the plugin on Desktop and Web clients (default: false). When false, the plugin only runs on CLI. Set to true if you want notifications/sounds/commands on Desktop/Web — useful if you want custom commands (Telegram, webhooks) but don't care about built-in notifications
126
130
  - `notificationSystem` - macOS only: `"osascript"`, `"node-notifier"`, or `"ghostty"` (default: "osascript"). Use `"ghostty"` if you're running Ghostty terminal for native OSC 9 notifications
127
131
  - `linux.grouping` - Linux only: replace notifications in-place instead of stacking (default: false). Requires `notify-send` 0.8+
128
132
 
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var DEFAULT_CONFIG = {
20
20
  showSessionTitle: false,
21
21
  showIcon: true,
22
22
  suppressWhenFocused: true,
23
+ enableOnDesktop: false,
23
24
  notificationSystem: "osascript",
24
25
  linux: {
25
26
  grouping: false
@@ -131,6 +132,7 @@ function loadConfig() {
131
132
  showSessionTitle: userConfig.showSessionTitle ?? DEFAULT_CONFIG.showSessionTitle,
132
133
  showIcon: userConfig.showIcon ?? DEFAULT_CONFIG.showIcon,
133
134
  suppressWhenFocused: userConfig.suppressWhenFocused ?? DEFAULT_CONFIG.suppressWhenFocused,
135
+ enableOnDesktop: typeof userConfig.enableOnDesktop === "boolean" ? userConfig.enableOnDesktop : DEFAULT_CONFIG.enableOnDesktop,
134
136
  notificationSystem: userConfig.notificationSystem === "node-notifier" ? "node-notifier" : userConfig.notificationSystem === "ghostty" ? "ghostty" : "osascript",
135
137
  linux: {
136
138
  grouping: typeof userConfig.linux?.grouping === "boolean" ? userConfig.linux.grouping : DEFAULT_CONFIG.linux.grouping
@@ -502,7 +504,7 @@ function runCommand2(config, event, message, sessionTitle, projectName, timestam
502
504
  }
503
505
 
504
506
  // src/focus.ts
505
- import { execSync } from "child_process";
507
+ import { execFileSync, execSync } from "child_process";
506
508
  function execWithTimeout(command, timeoutMs = 500) {
507
509
  try {
508
510
  return execSync(command, { timeout: timeoutMs, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
@@ -510,6 +512,13 @@ function execWithTimeout(command, timeoutMs = 500) {
510
512
  return null;
511
513
  }
512
514
  }
515
+ function execFileWithTimeout(command, args, timeoutMs = 500) {
516
+ try {
517
+ return execFileSync(command, args, { timeout: timeoutMs, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
518
+ } catch {
519
+ return null;
520
+ }
521
+ }
513
522
  function getHyprlandActiveWindowId() {
514
523
  const output = execWithTimeout("hyprctl activewindow -j");
515
524
  if (!output)
@@ -563,18 +572,11 @@ function getLinuxWaylandActiveWindowId() {
563
572
  return null;
564
573
  }
565
574
  function getWindowsActiveWindowId() {
566
- const script = `
567
- Add-Type @"
568
- using System;
569
- using System.Runtime.InteropServices;
570
- public class FocusHelper {
571
- [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
572
- }
573
- "@
574
- $hwnd = [FocusHelper]::GetForegroundWindow()
575
- Write-Output $hwnd
576
- `.trim().replace(/\n/g, "; ");
577
- return execWithTimeout(`powershell -NoProfile -Command "${script}"`, 1000);
575
+ const script = `$type=Add-Type -Name FocusHelper -Namespace OpenCodeNotifier -MemberDefinition '[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();' -PassThru; $type::GetForegroundWindow()`;
576
+ let windowId = execFileWithTimeout("powershell", ["-NoProfile", "-NonInteractive", "-Command", script], 1000);
577
+ if (!windowId)
578
+ windowId = execFileWithTimeout("pwsh", ["-NoProfile", "-NonInteractive", "-Command", script], 1000);
579
+ return windowId;
578
580
  }
579
581
  function getMacOSActiveWindowId() {
580
582
  return execWithTimeout(`osascript -e 'tell application "System Events" to return id of window 1 of (first application process whose frontmost is true)'`);
@@ -847,7 +849,9 @@ async function handleEventWithElapsedTime(client, config, eventType, projectName
847
849
  var NotifierPlugin = async ({ client, directory }) => {
848
850
  const clientEnv = process.env.OPENCODE_CLIENT;
849
851
  if (clientEnv && clientEnv !== "cli") {
850
- return {};
852
+ const config = loadConfig();
853
+ if (!config.enableOnDesktop)
854
+ return {};
851
855
  }
852
856
  const getConfig = () => loadConfig();
853
857
  const projectName = directory ? basename(directory) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohak34/opencode-notifier",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "OpenCode plugin that sends system notifications and plays sounds when permission is needed, generation completes, or errors occur",
5
5
  "author": "mohak34",
6
6
  "license": "MIT",