Skip to content

Commit 094bea8

Browse files
Petrus PennanenPetrus Pennanen
authored andcommitted
fix(notify): restore missing GUI nudgeCommand functionality for desktop clients
1 parent f0e9017 commit 094bea8

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

‎src/team-relay/common/notify.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ export function nudgeTmux(session, text) {
2424
}
2525
}
2626

27+
export function nudgeCommand(command, { text = 'check rooms', session = '' } = {}) {
28+
if (!command || typeof command !== 'string') return false;
29+
try {
30+
execSync(command, {
31+
stdio: 'ignore',
32+
env: {
33+
...process.env,
34+
IAK_NUDGE_TEXT: text,
35+
IAK_TMUX_SESSION: session
36+
}
37+
});
38+
return true;
39+
} catch {
40+
return false;
41+
}
42+
}
43+
2744
export function writeNotification(notifyFile, lines) {
2845
if (lines.length === 0) return;
2946
appendFileSync(notifyFile, lines.join('\n') + '\n');

‎src/team-relay/room-poller.mjs‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NOTIFY_FILE_DEFAULT, SEEN_FILE_DEFAULT, QUEUE_PATH_DEFAULT } from '../common/constants.mjs';
22
import { enrichEvent } from './enrichment.mjs';
3+
import { nudgeTmux, nudgeCommand } from './common/notify.mjs';
34
// SPDX-License-Identifier: AGPL-3.0-only
4-
55
import { execSync } from 'node:child_process';
66
import { readFileSync, writeFileSync, appendFileSync, existsSync, unlinkSync } from 'node:fs';
77
import { randomUUID } from 'node:crypto';
@@ -39,21 +39,7 @@ function saveSeenIds(path, ids) {
3939
writeFileSync(path, arr.join('\n') + '\n');
4040
}
4141

42-
function nudgeTmux(session, text) {
43-
try {
44-
execSync(`tmux has-session -t ${JSON.stringify(session)} 2>/dev/null`);
45-
} catch {
46-
return false;
47-
}
48-
try {
49-
execSync(`tmux send-keys -t ${JSON.stringify(session)} -l ${JSON.stringify(text)}`);
50-
execSync('sleep 0.3');
51-
execSync(`tmux send-keys -t ${JSON.stringify(session)} Enter`);
52-
return true;
53-
} catch {
54-
return false;
55-
}
56-
}
42+
5743

5844
async function fetchRoomMessages(room, apiKey, limit = 10) {
5945
const url = `https://groupmind.one/api/v1/rooms/${room}/messages?limit=${limit}`;
@@ -170,9 +156,18 @@ export async function startRoomPoller({ rooms, apiKey, handle, interval, config
170156
// Primary: write to notification file (always works)
171157
appendFileSync(notifyFile, newMessages.join('\n') + '\n');
172158

173-
// Secondary: try tmux nudge (bonus if IDE is in tmux)
174-
const nudged = nudgeTmux(session, nudgeText);
175-
console.log(` ${newCount} new message(s) → notified${nudged ? ' + tmux nudge' : ''}`);
159+
// Secondary: try command nudge (GUI) or fallback to tmux nudge
160+
const nudgeCmd = config?.tmux?.nudge_command;
161+
let nudged = false;
162+
let nudgeType = '';
163+
if (nudgeCmd) {
164+
nudged = nudgeCommand(nudgeCmd, { text: nudgeText, session });
165+
if (nudged) nudgeType = ' + gui nudge';
166+
} else {
167+
nudged = nudgeTmux(session, nudgeText);
168+
if (nudged) nudgeType = ' + tmux nudge';
169+
}
170+
console.log(` ${newCount} new message(s) → notified${nudgeType}`);
176171
}
177172
}
178173

0 commit comments

Comments
 (0)