superbased 1.4.0 → 1.5.0
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.
- package/SUPERBASED_SKILL.md +91 -32
- package/dist/headless/electron/modules/active-window.js +8 -0
- package/dist/headless/electron/modules/api-server.js +137 -3
- package/dist/headless/electron/modules/azure-speech-realtime.js +187 -54
- package/dist/headless/electron/modules/dictation.js +122 -0
- package/dist/headless/headless/dictation-hotkey.js +212 -47
- package/dist/headless/headless/dictation-overlay.js +218 -0
- package/dist/headless/headless/mic-capture.js +95 -1
- package/dist/headless/headless/platform-headless.js +103 -3
- package/dist/headless/headless/win32-text-injector.js +359 -0
- package/mcp-server/dist/index.js +4 -4
- package/package.json +1 -1
package/SUPERBASED_SKILL.md
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
# SuperBased — AI Screenshot Tool for Developers
|
|
2
2
|
|
|
3
|
-
SuperBased is a desktop screenshot + AI tool. You can control it via MCP tools to capture screenshots, view them inline, run AI analysis, extract text, redact secrets, dictate, record sessions, run visual regression tests, and compress text — all programmatically from your coding environment.
|
|
3
|
+
SuperBased is a desktop screenshot + AI tool. You can control it via MCP tools to capture screenshots, view them inline, run AI analysis, extract text, redact secrets, dictate (file or live mic), record sessions, run visual regression tests, and compress text — all programmatically from your coding environment.
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
7
7
|
### 1. Make sure SuperBased is running
|
|
8
|
-
The desktop app must be running
|
|
8
|
+
The desktop app or headless server must be running. It starts an HTTP API on `http://127.0.0.1:47592` automatically.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
**Desktop**: Launch the app.
|
|
11
|
+
**Headless (CLI)**: Run `superbased mcp` — this starts the API server + MCP stdio bridge in one process. Your MCP config only needs:
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"superbased": {
|
|
16
|
+
"command": "superbased",
|
|
17
|
+
"args": ["mcp"]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
12
22
|
|
|
23
|
+
### 2. Add MCP server (alternative: node path)
|
|
24
|
+
If `superbased` isn't on PATH, use the full node path:
|
|
13
25
|
```json
|
|
14
26
|
{
|
|
15
27
|
"mcpServers": {
|
|
@@ -20,11 +32,10 @@ Create `.mcp.json` in your project root:
|
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
```
|
|
23
|
-
|
|
24
|
-
Check `~/.superbased/superbased-mcp.json` for the correct path after starting SuperBased. Restart Claude Code after creating the file.
|
|
35
|
+
Check `~/.superbased/mcp.json` for the correct path after starting SuperBased. Restart your editor after creating the file.
|
|
25
36
|
|
|
26
37
|
### 3. Verify connection
|
|
27
|
-
Ask: "Check the SuperBased health status" —
|
|
38
|
+
Ask: "Check the SuperBased health status" — the agent should call `superbased_health` and show version, uptime, and features.
|
|
28
39
|
|
|
29
40
|
---
|
|
30
41
|
|
|
@@ -38,7 +49,7 @@ Take a screenshot. Returns capture ID and metadata (no image inline — use `sup
|
|
|
38
49
|
| Parameter | Type | Description |
|
|
39
50
|
|-----------|------|-------------|
|
|
40
51
|
| `mode` | `fullscreen` / `region` / `active_window` | What to capture |
|
|
41
|
-
| `x`, `y`, `width`, `height` | number |
|
|
52
|
+
| `x`, `y`, `width`, `height` | number | Absolute screen pixel coordinates for region mode (0,0 = top-left) |
|
|
42
53
|
| `projectDir` | string | Where to save (default: CWD) |
|
|
43
54
|
|
|
44
55
|
#### superbased_capture_image
|
|
@@ -48,23 +59,34 @@ Capture screen and return the **image inline** so you can see it. Supports resol
|
|
|
48
59
|
|-----------|------|-------------|
|
|
49
60
|
| `mode` | `fullscreen` / `region` / `active_window` | Capture mode (default: fullscreen) |
|
|
50
61
|
| `resolution` | `full` / `high` / `half` / `quarter` / `thumbnail` | Image resolution (default: half — saves ~4x tokens vs full) |
|
|
51
|
-
| `window` | string | Capture a specific window by name substring |
|
|
52
|
-
| `x`, `y`, `width`, `height` | number |
|
|
62
|
+
| `window` | string | Capture a specific window by name substring (case-insensitive). Activates the window (even if minimized), captures, then restores the previous foreground window. Use `superbased_window_list` to find window names. |
|
|
63
|
+
| `x`, `y`, `width`, `height` | number | Absolute screen pixel coordinates for region mode |
|
|
53
64
|
|
|
54
65
|
**Token savings**: A 1920x1080 screenshot at `full` = ~2,765 tokens. At `half` = ~691 tokens. At `quarter` = ~173 tokens.
|
|
55
66
|
|
|
67
|
+
**Window targeting workflow:**
|
|
68
|
+
1. Call `superbased_window_list` to see all windows
|
|
69
|
+
2. Pick the window name (or a unique substring)
|
|
70
|
+
3. Call `superbased_capture_image` with `window="substring"` — SuperBased will activate the window (restore if minimized), capture it, then restore focus to the previous window
|
|
71
|
+
|
|
56
72
|
#### superbased_gallery_image
|
|
57
73
|
Retrieve a saved capture's image inline from the gallery.
|
|
58
74
|
|
|
59
75
|
| Parameter | Type | Description |
|
|
60
76
|
|-----------|------|-------------|
|
|
61
77
|
| `captureId` | number | Gallery capture ID |
|
|
62
|
-
| `resolution` | `full` / `high` / `half` / `quarter` / `thumbnail` | Image resolution (default: half) |
|
|
78
|
+
| `resolution` | `full` / `high` / `half` / `quarter` / `thumbnail` | Image resolution (default: half). Use `quarter` or `thumbnail` when you only need to check layout/presence, not read text. |
|
|
79
|
+
|
|
80
|
+
**Token savings**: Same as `superbased_capture_image` — `half` saves ~4x vs `full`, `quarter` saves ~16x.
|
|
63
81
|
|
|
64
82
|
#### superbased_window_list
|
|
65
|
-
List all visible windows on screen.
|
|
83
|
+
List all visible windows on screen. Returns each window's name, active status, and minimized state. Use window names with `superbased_capture_image` to target specific windows.
|
|
66
84
|
|
|
67
|
-
Returns:
|
|
85
|
+
Returns: `{ windows: [{ id, name, hwnd, minimized, isActive }], activeWindow: { appName, windowTitle } }`
|
|
86
|
+
|
|
87
|
+
- `hwnd` (Windows only): Window handle used internally for activation
|
|
88
|
+
- `minimized`: Whether the window is minimized to taskbar
|
|
89
|
+
- `isActive`: Whether this is the currently focused window
|
|
68
90
|
|
|
69
91
|
### AI & OCR
|
|
70
92
|
|
|
@@ -73,7 +95,7 @@ Send a screenshot to AI for analysis. If no image provided, captures the screen
|
|
|
73
95
|
|
|
74
96
|
| Parameter | Type | Description |
|
|
75
97
|
|-----------|------|-------------|
|
|
76
|
-
| `instruction` | string | What to do.
|
|
98
|
+
| `instruction` | string | What to do. Supports slash commands: `/extract` (get text), `/summarize`, `/code` (extract code), `/explain`, `/translate`, `/table` (extract tabular data), `/edit`, `/reformat` |
|
|
77
99
|
| `captureId` | number | Use an existing capture from gallery |
|
|
78
100
|
| `screenshotPath` | string | Path to an image file |
|
|
79
101
|
| `projectDir` | string | For auto-captures |
|
|
@@ -90,7 +112,7 @@ Extract text from a screenshot using Tesseract OCR (runs locally — no data lea
|
|
|
90
112
|
Check your daily AI quota (used/remaining/limit). Requires sign-in.
|
|
91
113
|
|
|
92
114
|
#### superbased_transcribe
|
|
93
|
-
Transcribe an audio file to text via Whisper.
|
|
115
|
+
Transcribe an audio file to text via Whisper (raw transcription, no cleanup). For voice notes with filler word removal, use `superbased_dictate` instead.
|
|
94
116
|
|
|
95
117
|
| Parameter | Type | Description |
|
|
96
118
|
|-----------|------|-------------|
|
|
@@ -152,28 +174,39 @@ Add programmatic annotations to captures (rectangles, highlights, blur, text lab
|
|
|
152
174
|
| Parameter | Type | Description |
|
|
153
175
|
|-----------|------|-------------|
|
|
154
176
|
| `captureId` | number | Capture to annotate |
|
|
155
|
-
| `annotations` | array | Annotation objects (see below) |
|
|
156
|
-
| `save` | boolean | Save over the original (default: false) |
|
|
177
|
+
| `annotations` | array | Annotation objects (see types below) |
|
|
178
|
+
| `save` | boolean | Save over the original (default: false — returns annotated image without modifying the original) |
|
|
157
179
|
|
|
158
|
-
Annotation types
|
|
159
|
-
- `rectangle`: bounding box outline
|
|
160
|
-
- `highlight`: semi-transparent overlay
|
|
161
|
-
- `blur`: pixelate a region
|
|
162
|
-
- `text`: text label
|
|
163
|
-
- `arrow`: arrow
|
|
180
|
+
**Annotation types:**
|
|
181
|
+
- `rectangle`: bounding box outline — `{type:"rectangle", x, y, width, height, color}`
|
|
182
|
+
- `highlight`: semi-transparent overlay — `{type:"highlight", x, y, width, height, color}`
|
|
183
|
+
- `blur`: pixelate a region — `{type:"blur", x, y, width, height}`
|
|
184
|
+
- `text`: text label — `{type:"text", x, y, text, color, fontSize}`
|
|
185
|
+
- `arrow`: arrow between two points — `{type:"arrow", x, y, toX, toY, color}`
|
|
186
|
+
|
|
187
|
+
**Example:**
|
|
188
|
+
```
|
|
189
|
+
superbased_annotate captureId=42 annotations=[{type:"rectangle",x:100,y:200,width:300,height:50,color:"#ff0000"},{type:"text",x:100,y:190,text:"Bug: misaligned button",color:"#ff0000"}]
|
|
190
|
+
```
|
|
164
191
|
|
|
165
192
|
### Dictation & Voice
|
|
166
193
|
|
|
167
194
|
#### superbased_dictate
|
|
168
|
-
Transcribe audio with text cleanup (filler word removal, deduplication).
|
|
195
|
+
Transcribe audio with text cleanup (filler word removal, deduplication). Supports file input, base64, or **live microphone recording**.
|
|
169
196
|
|
|
170
197
|
| Parameter | Type | Description |
|
|
171
198
|
|-----------|------|-------------|
|
|
172
199
|
| `audioPath` | string | Path to audio file |
|
|
173
200
|
| `audioBase64` | string | Base64-encoded audio |
|
|
201
|
+
| `mic` | boolean | Set to `true` to record from the microphone (requires ffmpeg installed) |
|
|
202
|
+
| `duration` | number | Mic recording duration in seconds (default: 10) |
|
|
174
203
|
| `language` | string | BCP 47 language code |
|
|
175
204
|
| `cleanup` | boolean | Apply filler removal + dedup (default: true) |
|
|
176
205
|
|
|
206
|
+
**When to use `mic`:** The user asks you to "listen", "hear what I'm saying", or wants live voice input. Set `mic=true` and optionally `duration=15` for longer recordings.
|
|
207
|
+
|
|
208
|
+
**`superbased_dictate` vs `superbased_transcribe`:** Dictate adds text cleanup (filler words, deduplication) and supports mic recording. Transcribe is raw Whisper output only.
|
|
209
|
+
|
|
177
210
|
#### superbased_dictation_history
|
|
178
211
|
Query past voice transcriptions.
|
|
179
212
|
|
|
@@ -254,13 +287,14 @@ View or update app settings. API keys are never exposed.
|
|
|
254
287
|
| `value` | string | New value for `set` |
|
|
255
288
|
|
|
256
289
|
#### superbased_presets
|
|
257
|
-
Manage AI instruction presets (saved templates).
|
|
290
|
+
Manage AI instruction presets (saved templates with optional keyboard shortcuts).
|
|
258
291
|
|
|
259
292
|
| Parameter | Type | Description |
|
|
260
293
|
|-----------|------|-------------|
|
|
261
294
|
| `action` | `list` / `create` / `update` / `delete` | What to do |
|
|
262
295
|
| `name` | string | Preset name |
|
|
263
296
|
| `instruction` | string | AI instruction template |
|
|
297
|
+
| `shortcut` | string | Keyboard shortcut (e.g. "Ctrl+Shift+1") |
|
|
264
298
|
| `id` | number | Preset ID (for update/delete) |
|
|
265
299
|
|
|
266
300
|
### Status & Auth
|
|
@@ -282,6 +316,8 @@ Read or write system clipboard.
|
|
|
282
316
|
| `action` | `read` / `write` / `readImage` | Clipboard action |
|
|
283
317
|
| `text` | string | Text to write (for write action) |
|
|
284
318
|
|
|
319
|
+
**Returns:** `read` returns clipboard text. `write` confirms success. `readImage` returns the clipboard image inline (PNG) — useful for reading screenshots copied from other apps.
|
|
320
|
+
|
|
285
321
|
---
|
|
286
322
|
|
|
287
323
|
## Common Workflows
|
|
@@ -291,10 +327,18 @@ Read or write system clipboard.
|
|
|
291
327
|
superbased_capture_image mode=fullscreen resolution=half
|
|
292
328
|
```
|
|
293
329
|
|
|
294
|
-
### Capture a specific window (
|
|
330
|
+
### Capture a specific window (even if minimized)
|
|
331
|
+
```
|
|
332
|
+
1. superbased_window_list -> find the window name
|
|
333
|
+
2. superbased_capture_image window="Notepad" resolution=half
|
|
334
|
+
```
|
|
335
|
+
The window will be activated (restored if minimized), captured, and focus restored to the previous window.
|
|
336
|
+
|
|
337
|
+
### Read text from a specific window
|
|
295
338
|
```
|
|
296
|
-
1. superbased_window_list
|
|
297
|
-
2. superbased_capture_image window="
|
|
339
|
+
1. superbased_window_list -> find window name
|
|
340
|
+
2. superbased_capture_image window="Chrome" resolution=half -> capture + view it
|
|
341
|
+
3. superbased_ocr captureId=<id> -> extract text from capture
|
|
298
342
|
```
|
|
299
343
|
|
|
300
344
|
### Screenshot and extract text
|
|
@@ -314,6 +358,12 @@ superbased_ai instruction="/extract"
|
|
|
314
358
|
2. superbased_redact captureId=<id> secrets=true pii=true
|
|
315
359
|
```
|
|
316
360
|
|
|
361
|
+
### Live mic dictation
|
|
362
|
+
```
|
|
363
|
+
superbased_dictate mic=true duration=15
|
|
364
|
+
```
|
|
365
|
+
Records from the microphone for 15 seconds, transcribes with cleanup.
|
|
366
|
+
|
|
317
367
|
### Visual regression testing
|
|
318
368
|
```
|
|
319
369
|
1. superbased_recording action=start name="Before: login flow" profile=automated_test
|
|
@@ -334,6 +384,12 @@ superbased_ai instruction="/extract"
|
|
|
334
384
|
2. superbased_annotate captureId=<id> annotations=[{type:"rectangle", x:100, y:200, width:300, height:50, color:"#ff0000"}, {type:"text", x:100, y:190, text:"Bug: button is misaligned"}] save=true
|
|
335
385
|
```
|
|
336
386
|
|
|
387
|
+
### Read an image from clipboard
|
|
388
|
+
```
|
|
389
|
+
superbased_clipboard action=readImage
|
|
390
|
+
```
|
|
391
|
+
Returns the clipboard image inline — useful when the user says "look at what I copied."
|
|
392
|
+
|
|
337
393
|
### Compress large text for token savings
|
|
338
394
|
```
|
|
339
395
|
superbased_compress_text text="<large text content>" preset=compact theme=dark
|
|
@@ -342,17 +398,20 @@ superbased_compress_text text="<large text content>" preset=compact theme=dark
|
|
|
342
398
|
## Tips
|
|
343
399
|
|
|
344
400
|
- **Use `resolution=half` or `quarter`** to save tokens when you don't need full detail
|
|
345
|
-
- **Use `window` param** to capture just the window you care about —
|
|
401
|
+
- **Use `window` param** to capture just the window you care about — works even on minimized windows
|
|
346
402
|
- **The `/extract` slash command** is the fastest way to get text from screen
|
|
347
403
|
- **Captures are saved to your project** when `projectDir` is set (automatic in Claude Code)
|
|
348
404
|
- **Gallery persists across sessions** — search for past captures anytime
|
|
349
405
|
- **OCR is local** (Tesseract) — no data leaves your machine for text extraction
|
|
350
406
|
- **Redact before sharing** — use `superbased_redact` to remove API keys and PII
|
|
351
|
-
- **
|
|
407
|
+
- **Mic dictation** — `superbased_dictate mic=true` records live audio, no file needed
|
|
408
|
+
- **Visual QA workflow**: record -> change -> record -> diff -> report
|
|
409
|
+
- **Clipboard image** — `superbased_clipboard action=readImage` shows whatever image the user copied
|
|
352
410
|
|
|
353
411
|
## Troubleshooting
|
|
354
412
|
|
|
355
|
-
- **"Cannot connect to SuperBased"** — Make sure the desktop app is running
|
|
356
|
-
- **"Authentication required"** — Sign in via SuperBased app, or run `
|
|
413
|
+
- **"Cannot connect to SuperBased"** — Make sure the desktop app or `superbased mcp` is running
|
|
414
|
+
- **"Authentication required"** — Sign in via SuperBased app, or run `superbased auth login`
|
|
357
415
|
- **Recording tools return errors** — Enable recording in SuperBased Settings > Recording
|
|
416
|
+
- **Window capture gets wrong window** — Use the exact window name from `superbased_window_list`
|
|
358
417
|
- **Check app status**: Use `superbased_health` or check `~/.superbased/mcp.json`
|
|
@@ -39,8 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.getActiveWindowInfo = getActiveWindowInfo;
|
|
40
40
|
// Detects the currently active window for capture metadata
|
|
41
41
|
const logger_1 = __importDefault(require("../logger"));
|
|
42
|
+
const platform_1 = require("../core/platform");
|
|
42
43
|
let activeWinErrorLogged = false;
|
|
43
44
|
async function getActiveWindowInfo() {
|
|
45
|
+
// active-win is a native module compiled for Electron's Node.js.
|
|
46
|
+
// In headless mode (system Node.js), loading the native binding crashes
|
|
47
|
+
// at the C++ level (NODE_MODULE_VERSION mismatch) which can't be caught
|
|
48
|
+
// by try/catch. Skip it entirely outside Electron.
|
|
49
|
+
if (!(0, platform_1.getPlatform)().isElectron()) {
|
|
50
|
+
return { appName: null, windowTitle: null };
|
|
51
|
+
}
|
|
44
52
|
try {
|
|
45
53
|
// active-win is ESM-only, use dynamic import
|
|
46
54
|
const activeWin = await Promise.resolve().then(() => __importStar(require('active-win')));
|
|
@@ -837,8 +837,9 @@ function registerExpandedRoutes(server) {
|
|
|
837
837
|
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
838
838
|
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
839
839
|
}
|
|
840
|
-
// Window targeting: find matching window
|
|
840
|
+
// Window targeting: find matching window, bring to foreground, then capture
|
|
841
841
|
let windowInfo = null;
|
|
842
|
+
let buffer = null;
|
|
842
843
|
if (body.window) {
|
|
843
844
|
const sources = await (0, platform_1.getPlatform)().listWindows();
|
|
844
845
|
const match = sources.find((s) => s.name.toLowerCase().includes(body.window.toLowerCase()));
|
|
@@ -846,8 +847,139 @@ function registerExpandedRoutes(server) {
|
|
|
846
847
|
return reply.code(404).send({ error: `No window matching "${body.window}"`, availableWindows: sources.map((s) => s.name) });
|
|
847
848
|
}
|
|
848
849
|
windowInfo = { appName: match.name, windowTitle: match.name };
|
|
850
|
+
// Bring target window to foreground, capture, then restore original window.
|
|
851
|
+
// Uses a temp .ps1 script with Win32 P/Invoke to handle minimized windows
|
|
852
|
+
// and bypass SetForegroundWindow restrictions (AttachThreadInput trick).
|
|
853
|
+
const { execSync: execSyncCapture } = require('child_process');
|
|
854
|
+
const osMod = require('os');
|
|
855
|
+
const pathMod = require('path');
|
|
856
|
+
const fsMod = require('fs');
|
|
857
|
+
try {
|
|
858
|
+
if (process.platform === 'win32') {
|
|
859
|
+
const hwnd = match.hwnd;
|
|
860
|
+
let previousHwnd = null;
|
|
861
|
+
if (hwnd) {
|
|
862
|
+
const activateScript = pathMod.join(osMod.tmpdir(), 'superbased-activate.ps1');
|
|
863
|
+
fsMod.writeFileSync(activateScript, `
|
|
864
|
+
param([long]$TargetHwnd)
|
|
865
|
+
Add-Type -TypeDefinition @'
|
|
866
|
+
using System; using System.Runtime.InteropServices;
|
|
867
|
+
public class WinActivate {
|
|
868
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
869
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int c);
|
|
870
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
|
871
|
+
[DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr h);
|
|
872
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
|
873
|
+
[DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
|
|
874
|
+
[DllImport("user32.dll")] public static extern bool AttachThreadInput(uint a, uint b, bool attach);
|
|
875
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
|
|
876
|
+
public static IntPtr Activate(IntPtr target) {
|
|
877
|
+
IntPtr prev = GetForegroundWindow();
|
|
878
|
+
uint dummy;
|
|
879
|
+
uint fgThread = GetWindowThreadProcessId(prev, out dummy);
|
|
880
|
+
uint curThread = GetCurrentThreadId();
|
|
881
|
+
AttachThreadInput(curThread, fgThread, true);
|
|
882
|
+
ShowWindow(target, 9);
|
|
883
|
+
keybd_event(0x12, 0, 1, UIntPtr.Zero);
|
|
884
|
+
keybd_event(0x12, 0, 3, UIntPtr.Zero);
|
|
885
|
+
SetForegroundWindow(target);
|
|
886
|
+
BringWindowToTop(target);
|
|
887
|
+
AttachThreadInput(curThread, fgThread, false);
|
|
888
|
+
return prev;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
'@
|
|
892
|
+
$h = [IntPtr]::new($TargetHwnd)
|
|
893
|
+
$prev = [WinActivate]::Activate($h)
|
|
894
|
+
$prev.ToInt64()
|
|
895
|
+
`);
|
|
896
|
+
try {
|
|
897
|
+
previousHwnd = execSyncCapture(`powershell -ExecutionPolicy Bypass -File "${activateScript}" -TargetHwnd ${hwnd}`, { encoding: 'utf-8', timeout: 5000, stdio: 'pipe' }).trim();
|
|
898
|
+
}
|
|
899
|
+
catch { /* ignore */ }
|
|
900
|
+
try {
|
|
901
|
+
fsMod.unlinkSync(activateScript);
|
|
902
|
+
}
|
|
903
|
+
catch { /* cleanup */ }
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
// Fallback: use AppActivate by title
|
|
907
|
+
const escapedTitle = match.name.replace(/'/g, "''");
|
|
908
|
+
execSyncCapture(`powershell -command "(New-Object -ComObject WScript.Shell).AppActivate('${escapedTitle}')"`, { timeout: 3000, stdio: 'pipe' });
|
|
909
|
+
}
|
|
910
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
911
|
+
// Capture while target is in foreground
|
|
912
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
913
|
+
// Restore the original window
|
|
914
|
+
if (previousHwnd && previousHwnd !== '0' && hwnd) {
|
|
915
|
+
const restoreScript = pathMod.join(osMod.tmpdir(), 'superbased-restore.ps1');
|
|
916
|
+
fsMod.writeFileSync(restoreScript, `
|
|
917
|
+
param([long]$Hwnd)
|
|
918
|
+
Add-Type -TypeDefinition @'
|
|
919
|
+
using System; using System.Runtime.InteropServices;
|
|
920
|
+
public class WinRestore {
|
|
921
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
|
922
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
|
|
923
|
+
public static void Restore(IntPtr target) {
|
|
924
|
+
keybd_event(0x12, 0, 1, UIntPtr.Zero);
|
|
925
|
+
keybd_event(0x12, 0, 3, UIntPtr.Zero);
|
|
926
|
+
SetForegroundWindow(target);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
'@
|
|
930
|
+
[WinRestore]::Restore([IntPtr]::new($Hwnd))
|
|
931
|
+
`);
|
|
932
|
+
try {
|
|
933
|
+
execSyncCapture(`powershell -ExecutionPolicy Bypass -File "${restoreScript}" -Hwnd ${previousHwnd}`, { timeout: 3000, stdio: 'pipe' });
|
|
934
|
+
}
|
|
935
|
+
catch { /* ignore */ }
|
|
936
|
+
try {
|
|
937
|
+
fsMod.unlinkSync(restoreScript);
|
|
938
|
+
}
|
|
939
|
+
catch { /* cleanup */ }
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else if (process.platform === 'darwin') {
|
|
943
|
+
// macOS: use AppleScript to get frontmost app, activate target, capture, restore
|
|
944
|
+
let previousApp = null;
|
|
945
|
+
try {
|
|
946
|
+
previousApp = execSyncCapture('osascript -e \'tell application "System Events" to get name of first process whose frontmost is true\'', { encoding: 'utf-8', timeout: 3000, stdio: 'pipe' }).trim();
|
|
947
|
+
}
|
|
948
|
+
catch { /* ignore */ }
|
|
949
|
+
// Extract app name from window title (format: "AppName - WindowTitle")
|
|
950
|
+
const dashIdx = match.name.indexOf(' - ');
|
|
951
|
+
const appName = dashIdx !== -1 ? match.name.substring(0, dashIdx) : match.name;
|
|
952
|
+
const windowTitle = dashIdx !== -1 ? match.name.substring(dashIdx + 3) : '';
|
|
953
|
+
// Activate the target window
|
|
954
|
+
const escapedApp = appName.replace(/"/g, '\\"');
|
|
955
|
+
try {
|
|
956
|
+
if (windowTitle) {
|
|
957
|
+
execSyncCapture(`osascript -e 'tell application "${escapedApp}" to activate' -e 'delay 0.2' -e 'tell application "System Events" to tell process "${escapedApp}" to set frontmost to true'`, { timeout: 3000, stdio: 'pipe' });
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
execSyncCapture(`osascript -e 'tell application "${escapedApp}" to activate'`, { timeout: 3000, stdio: 'pipe' });
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
catch { /* ignore */ }
|
|
964
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
965
|
+
// Capture while target is in foreground
|
|
966
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
967
|
+
// Restore the previous app
|
|
968
|
+
if (previousApp) {
|
|
969
|
+
try {
|
|
970
|
+
const escapedPrev = previousApp.replace(/"/g, '\\"');
|
|
971
|
+
execSyncCapture(`osascript -e 'tell application "${escapedPrev}" to activate'`, { timeout: 3000, stdio: 'pipe' });
|
|
972
|
+
}
|
|
973
|
+
catch { /* ignore */ }
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
catch {
|
|
978
|
+
// Window activation failed — capture will get whatever is on screen
|
|
979
|
+
}
|
|
849
980
|
}
|
|
850
|
-
|
|
981
|
+
if (!buffer)
|
|
982
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
851
983
|
// Auto-redact if enabled
|
|
852
984
|
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
853
985
|
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
@@ -950,7 +1082,9 @@ function registerExpandedRoutes(server) {
|
|
|
950
1082
|
windows: sources.map((s) => ({
|
|
951
1083
|
id: s.id,
|
|
952
1084
|
name: s.name,
|
|
953
|
-
|
|
1085
|
+
hwnd: s.hwnd,
|
|
1086
|
+
minimized: s.minimized,
|
|
1087
|
+
isActive: active.windowTitle ? s.name === active.windowTitle : false,
|
|
954
1088
|
})),
|
|
955
1089
|
activeWindow: active,
|
|
956
1090
|
});
|