|
1 | 1 | import { NOTIFY_FILE_DEFAULT, SEEN_FILE_DEFAULT, QUEUE_PATH_DEFAULT } from '../common/constants.mjs'; |
2 | 2 | import { enrichEvent } from './enrichment.mjs'; |
| 3 | +import { nudgeTmux, nudgeCommand } from './common/notify.mjs'; |
3 | 4 | // SPDX-License-Identifier: AGPL-3.0-only |
4 | | - |
5 | 5 | import { execSync } from 'node:child_process'; |
6 | 6 | import { readFileSync, writeFileSync, appendFileSync, existsSync, unlinkSync } from 'node:fs'; |
7 | 7 | import { randomUUID } from 'node:crypto'; |
@@ -39,21 +39,7 @@ function saveSeenIds(path, ids) { |
39 | 39 | writeFileSync(path, arr.join('\n') + '\n'); |
40 | 40 | } |
41 | 41 |
|
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 | + |
57 | 43 |
|
58 | 44 | async function fetchRoomMessages(room, apiKey, limit = 10) { |
59 | 45 | 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 |
170 | 156 | // Primary: write to notification file (always works) |
171 | 157 | appendFileSync(notifyFile, newMessages.join('\n') + '\n'); |
172 | 158 |
|
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}`); |
176 | 171 | } |
177 | 172 | } |
178 | 173 |
|
|
0 commit comments