@mohak34/opencode-notifier 0.1.30-beta.0 → 0.1.30-beta.1

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 (2) hide show
  1. package/dist/index.js +39 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4258,25 +4258,47 @@ function isMacOSFocused(terminal) {
4258
4258
  return false;
4259
4259
  return terminal.macProcessNames.some((name) => name.toLowerCase() === frontApp.toLowerCase());
4260
4260
  }
4261
- function isPidAncestorOfCurrentProcess(pid) {
4262
- let currentPid = process.pid;
4261
+ function getParentPid(pid) {
4262
+ try {
4263
+ const stat = readFileSync2(`/proc/${pid}/stat`, "utf-8");
4264
+ const closingParen = stat.lastIndexOf(")");
4265
+ if (closingParen === -1)
4266
+ return null;
4267
+ const fields = stat.slice(closingParen + 2).split(" ");
4268
+ const ppid = parseInt(fields[1], 10);
4269
+ return Number.isFinite(ppid) ? ppid : null;
4270
+ } catch {
4271
+ return null;
4272
+ }
4273
+ }
4274
+ function getProcessTreeRoot() {
4275
+ if (process.env.TMUX) {
4276
+ const clientPidStr = execWithTimeout("tmux display-message -p '#{client_pid}'");
4277
+ if (clientPidStr) {
4278
+ const clientPid = parseInt(clientPidStr, 10);
4279
+ if (Number.isFinite(clientPid) && clientPid > 0)
4280
+ return clientPid;
4281
+ }
4282
+ }
4283
+ return process.pid;
4284
+ }
4285
+ function isPidAncestorOfProcess(targetPid, startPid) {
4286
+ let currentPid = startPid;
4263
4287
  for (let depth = 0;depth < 20; depth++) {
4264
- if (currentPid === pid)
4288
+ if (currentPid === targetPid)
4265
4289
  return true;
4266
4290
  if (currentPid <= 1)
4267
4291
  return false;
4268
- try {
4269
- const stat = readFileSync2(`/proc/${currentPid}/stat`, "utf-8");
4270
- const match = stat.match(/^\d+\s+\(.*?\)\s+\S+\s+(\d+)/);
4271
- if (!match)
4272
- return false;
4273
- currentPid = parseInt(match[1], 10);
4274
- } catch {
4292
+ const ppid = getParentPid(currentPid);
4293
+ if (ppid === null)
4275
4294
  return false;
4276
- }
4295
+ currentPid = ppid;
4277
4296
  }
4278
4297
  return false;
4279
4298
  }
4299
+ function isFocusedWindowOurs(windowPid) {
4300
+ return isPidAncestorOfProcess(windowPid, getProcessTreeRoot());
4301
+ }
4280
4302
  function isLinuxX11Focused() {
4281
4303
  const pidStr = execWithTimeout("xdotool getactivewindow getwindowpid");
4282
4304
  if (!pidStr)
@@ -4284,7 +4306,7 @@ function isLinuxX11Focused() {
4284
4306
  const pid = parseInt(pidStr, 10);
4285
4307
  if (!Number.isFinite(pid) || pid <= 0)
4286
4308
  return false;
4287
- return isPidAncestorOfCurrentProcess(pid);
4309
+ return isFocusedWindowOurs(pid);
4288
4310
  }
4289
4311
  function isHyprlandFocused() {
4290
4312
  const output = execWithTimeout("hyprctl activewindow -j");
@@ -4295,7 +4317,7 @@ function isHyprlandFocused() {
4295
4317
  const pid = data?.pid;
4296
4318
  if (typeof pid !== "number" || pid <= 0)
4297
4319
  return false;
4298
- return isPidAncestorOfCurrentProcess(pid);
4320
+ return isFocusedWindowOurs(pid);
4299
4321
  } catch {
4300
4322
  return false;
4301
4323
  }
@@ -4309,7 +4331,7 @@ function isSwayFocused() {
4309
4331
  const pid = findFocusedPid(tree);
4310
4332
  if (pid === null)
4311
4333
  return false;
4312
- return isPidAncestorOfCurrentProcess(pid);
4334
+ return isFocusedWindowOurs(pid);
4313
4335
  } catch {
4314
4336
  return false;
4315
4337
  }
@@ -4344,7 +4366,7 @@ function isKDEWaylandFocused() {
4344
4366
  const pid = parseInt(pidStr, 10);
4345
4367
  if (!Number.isFinite(pid) || pid <= 0)
4346
4368
  return false;
4347
- return isPidAncestorOfCurrentProcess(pid);
4369
+ return isFocusedWindowOurs(pid);
4348
4370
  }
4349
4371
  function isLinuxWaylandFocused() {
4350
4372
  const env = process.env;
@@ -4380,7 +4402,8 @@ Write-Output $pid
4380
4402
  const pid = parseInt(pidStr, 10);
4381
4403
  if (!Number.isFinite(pid) || pid <= 0)
4382
4404
  return false;
4383
- let currentPid = process.pid;
4405
+ const startPid = getProcessTreeRoot();
4406
+ let currentPid = startPid;
4384
4407
  for (let depth = 0;depth < 20; depth++) {
4385
4408
  if (currentPid === pid)
4386
4409
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohak34/opencode-notifier",
3
- "version": "0.1.30-beta.0",
3
+ "version": "0.1.30-beta.1",
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",