@slack/radar-mcp 1.14.0 → 1.17.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.
- package/README.md +15 -3
- package/dist/mcp/db-tools.js +23 -0
- package/dist/mcp/dispatch.d.ts +4 -0
- package/dist/mcp/dispatch.js +26 -0
- package/dist/mcp/index.js +105 -37
- package/dist/mcp/platform-detect.d.ts +110 -0
- package/dist/mcp/platform-detect.js +246 -0
- package/dist/mcp/prefs-tools.d.ts +4 -3
- package/dist/mcp/prefs-tools.js +26 -3
- package/dist/mcp/session-enable.js +19 -1
- package/dist/mcp/snapshot.js +4 -1
- package/dist/mcp/sources-gate.js +6 -3
- package/dist/mcp/tools.d.ts +11 -0
- package/dist/mcp/tools.js +38 -0
- package/dist/mcp/web-child-env.d.ts +1 -0
- package/dist/mcp/web-child-env.js +32 -0
- package/dist/shared/android.d.ts +89 -1
- package/dist/shared/android.js +352 -78
- package/dist/shared/constants.d.ts +25 -1
- package/dist/shared/constants.js +27 -1
- package/dist/shared/db.js +11 -2
- package/dist/shared/debug-log.js +6 -1
- package/dist/shared/enable-diagnosis.d.ts +28 -0
- package/dist/shared/enable-diagnosis.js +41 -0
- package/dist/shared/prefs.d.ts +0 -5
- package/dist/shared/prefs.js +6 -2
- package/dist/shared/screen.d.ts +46 -9
- package/dist/shared/screen.js +74 -11
- package/dist/shared/transport.d.ts +62 -5
- package/dist/shared/webapp.d.ts +50 -0
- package/dist/shared/webapp.js +65 -0
- package/dist/web/bin.js +5 -1
- package/dist/web/install-app.d.ts +87 -0
- package/dist/web/install-app.js +703 -0
- package/dist/web/macapp/RadarApp.swift +466 -0
- package/dist/web/public/icons/radar-1024.png +0 -0
- package/dist/web/public/icons/radar.svg +40 -0
- package/dist/web/public/index.html +41 -1
- package/dist/web/public/next/app.js +19 -4
- package/dist/web/public/next/db.js +145 -5
- package/dist/web/public/next/feed.js +18 -0
- package/dist/web/public/next/hooks.js +10 -1
- package/dist/web/public/next/registry.js +18 -10
- package/dist/web/public/next/screen.js +147 -43
- package/dist/web/public/next/store.js +393 -51
- package/dist/web/public/next/toast.js +134 -0
- package/dist/web/server.d.ts +26 -1
- package/dist/web/server.js +341 -113
- package/package.json +2 -2
|
@@ -14,6 +14,34 @@ import { useLatestRef, useGlobalKeydown } from "./hooks.js";
|
|
|
14
14
|
function profileLabel(u) {
|
|
15
15
|
return u === "" || u == null ? "device" : u === "0" ? "personal (user 0)" : "secondary (user " + u + ")";
|
|
16
16
|
}
|
|
17
|
+
// A cell holds JSON only if it is a string that parses to an object or array. We keep our own
|
|
18
|
+
// tiny parser rather than import parseBody from inspector.ts: that module pulls in the
|
|
19
|
+
// streaming store, and the DB tab must never start the SSE engine (see the file header).
|
|
20
|
+
function asJson(v) {
|
|
21
|
+
if (typeof v !== "string")
|
|
22
|
+
return null;
|
|
23
|
+
const s = v.trim();
|
|
24
|
+
if (!s || (s[0] !== "{" && s[0] !== "["))
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(s);
|
|
28
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Copy `text` to the clipboard, then flip the clicked control's label to a confirmation for a
|
|
35
|
+
// beat. Same affordance as inspector.ts's copy(), inlined here to avoid the store import.
|
|
36
|
+
function copyText(text, e) {
|
|
37
|
+
navigator.clipboard?.writeText(text);
|
|
38
|
+
const btn = e.currentTarget;
|
|
39
|
+
if (!btn)
|
|
40
|
+
return;
|
|
41
|
+
const prev = btn.textContent;
|
|
42
|
+
btn.textContent = "copied ✓";
|
|
43
|
+
setTimeout(() => (btn.textContent = prev), 1200);
|
|
44
|
+
}
|
|
17
45
|
export function DbBrowser({ spec }) {
|
|
18
46
|
const [user, setUser] = useState(null);
|
|
19
47
|
const [dbs, setDbs] = useState(null); // null = loading
|
|
@@ -22,6 +50,9 @@ export function DbBrowser({ spec }) {
|
|
|
22
50
|
const [sql, setSql] = useState("");
|
|
23
51
|
const [out, setOut] = useState({ msg: "pick a database, then a table" });
|
|
24
52
|
const [meta, setMeta] = useState("");
|
|
53
|
+
// The result row whose full detail is open in the side panel (null = panel closed). Cleared
|
|
54
|
+
// whenever a new query runs, since a stale row index would point into the old result set.
|
|
55
|
+
const [selectedRow, setSelectedRow] = useState(null);
|
|
25
56
|
// keyboard nav: which pane has focus ("db" list or "tbl" list) + the highlighted index in
|
|
26
57
|
// each. j/k and Up/Down move the highlight within a pane, Enter drills in, Esc backs out of
|
|
27
58
|
// the tables pane, Tab toggles panes. Arrow keys are consumed here (preventDefault) so list
|
|
@@ -56,6 +87,7 @@ export function DbBrowser({ spec }) {
|
|
|
56
87
|
const pickDb = useCallback(async (name, refresh) => {
|
|
57
88
|
setDb(name);
|
|
58
89
|
setSql("");
|
|
90
|
+
setSelectedRow(null); // resetting the output invalidates any open row panel
|
|
59
91
|
setOut({ msg: "pick a table or write a query" });
|
|
60
92
|
setTables(null);
|
|
61
93
|
try {
|
|
@@ -76,6 +108,7 @@ export function DbBrowser({ spec }) {
|
|
|
76
108
|
const theSql = q ?? sql;
|
|
77
109
|
if (!db || !theSql)
|
|
78
110
|
return;
|
|
111
|
+
setSelectedRow(null); // a new result set invalidates the open row
|
|
79
112
|
setOut({ msg: "running…" });
|
|
80
113
|
try {
|
|
81
114
|
const r = await (
|
|
@@ -260,20 +293,27 @@ export function DbBrowser({ spec }) {
|
|
|
260
293
|
${db ? html `<button class="dbrefresh" onClick=${() => pickDb(db, true)}>↻ refresh</button>` : null}
|
|
261
294
|
</div>
|
|
262
295
|
<div class="dbmeta">${meta}</div>
|
|
263
|
-
<div class
|
|
264
|
-
|
|
296
|
+
<div class=${"dbsplit" + (selectedRow ? " open" : "")}>
|
|
297
|
+
<div class="dbout">
|
|
298
|
+
${out.msg
|
|
265
299
|
? html `<div class="msg">${out.msg}</div>`
|
|
266
300
|
: out.error
|
|
267
301
|
? html `<div class="msg err">${out.error}</div>`
|
|
268
302
|
: !out.rows || !out.rows.length
|
|
269
303
|
? html `<div class="msg">0 rows</div>`
|
|
270
|
-
: html `<${Grid}
|
|
304
|
+
: html `<${Grid}
|
|
305
|
+
rows=${out.rows}
|
|
306
|
+
selectedIndex=${selectedRow ? selectedRow.index : -1}
|
|
307
|
+
onSelect=${(row, index) => setSelectedRow((cur) => (cur && cur.index === index ? null : { row, index }))}
|
|
308
|
+
/>`}
|
|
309
|
+
</div>
|
|
310
|
+
${selectedRow ? html `<${RowInspector} row=${selectedRow.row} onClose=${() => setSelectedRow(null)} />` : null}
|
|
271
311
|
</div>
|
|
272
312
|
</div>
|
|
273
313
|
</div>
|
|
274
314
|
`;
|
|
275
315
|
}
|
|
276
|
-
function Grid({ rows }) {
|
|
316
|
+
function Grid({ rows, selectedIndex, onSelect, }) {
|
|
277
317
|
const cols = Object.keys(rows[0]);
|
|
278
318
|
return html `
|
|
279
319
|
<table>
|
|
@@ -283,10 +323,110 @@ function Grid({ rows }) {
|
|
|
283
323
|
</tr>
|
|
284
324
|
</thead>
|
|
285
325
|
<tbody>
|
|
286
|
-
${rows.map((row) => html `<tr>
|
|
326
|
+
${rows.map((row, i) => html `<tr class=${i === selectedIndex ? "rowsel" : ""} onClick=${() => onSelect(row, i)}>
|
|
287
327
|
${cols.map((c) => html `<td title=${String(row[c] ?? "")}>${String(row[c] ?? "")}</td>`)}
|
|
288
328
|
</tr>`)}
|
|
289
329
|
</tbody>
|
|
290
330
|
</table>
|
|
291
331
|
`;
|
|
292
332
|
}
|
|
333
|
+
// The syntax-highlight class for a JSON leaf value, matching the --j-* token colors the
|
|
334
|
+
// inspector uses. Objects/arrays are handled by JsonNode, so this only sees primitives.
|
|
335
|
+
function leafClass(v) {
|
|
336
|
+
if (v === null)
|
|
337
|
+
return "j-null";
|
|
338
|
+
const t = typeof v;
|
|
339
|
+
if (t === "number")
|
|
340
|
+
return "j-num";
|
|
341
|
+
if (t === "boolean")
|
|
342
|
+
return "j-bool";
|
|
343
|
+
return "j-str";
|
|
344
|
+
}
|
|
345
|
+
function leafText(v) {
|
|
346
|
+
if (v === null)
|
|
347
|
+
return "null";
|
|
348
|
+
if (typeof v === "string")
|
|
349
|
+
return '"' + v + '"';
|
|
350
|
+
return String(v);
|
|
351
|
+
}
|
|
352
|
+
// One node of the collapsible JSON tree. Objects and arrays get a caret that toggles just this
|
|
353
|
+
// node; primitives render as a single highlighted line. All text goes through normal Preact
|
|
354
|
+
// interpolation (auto-escaped) -- never dangerouslySetInnerHTML -- so a hostile cell value can
|
|
355
|
+
// never inject markup (the DOM-XSS contract the db-browser tests lock).
|
|
356
|
+
function JsonNode({ k, value, depth }) {
|
|
357
|
+
const isArr = Array.isArray(value);
|
|
358
|
+
const isObj = !isArr && value !== null && typeof value === "object";
|
|
359
|
+
// Top-level node open, everything nested starts collapsed (Flipper-like).
|
|
360
|
+
const [open, setOpen] = useState(depth === 0);
|
|
361
|
+
const keyLabel = k != null ? html `<span class="j-key">"${k}"</span><span class="j-punc">: </span>` : null;
|
|
362
|
+
if (!isArr && !isObj) {
|
|
363
|
+
return html `<div class="jrow jleaf" style=${{ paddingLeft: depth * 14 + "px" }}>
|
|
364
|
+
${keyLabel}<span class=${leafClass(value)}>${leafText(value)}</span>
|
|
365
|
+
</div>`;
|
|
366
|
+
}
|
|
367
|
+
const entries = isArr
|
|
368
|
+
? value.map((v, i) => [String(i), v])
|
|
369
|
+
: Object.entries(value);
|
|
370
|
+
const summary = isArr ? "[…] " + entries.length + (entries.length === 1 ? " item" : " items") : "{…} " + entries.length + (entries.length === 1 ? " key" : " keys");
|
|
371
|
+
return html `<div class="jnode">
|
|
372
|
+
<div class="jrow" style=${{ paddingLeft: depth * 14 + "px" }} onClick=${() => setOpen((o) => !o)}>
|
|
373
|
+
<span class="jcaret">${open ? "▾" : "▸"}</span>
|
|
374
|
+
${keyLabel}
|
|
375
|
+
<span class="jsummary">${open ? (isArr ? "[" : "{") : summary}</span>
|
|
376
|
+
<span
|
|
377
|
+
class="jtree-copy"
|
|
378
|
+
title="Copy this value as JSON"
|
|
379
|
+
onClick=${(e) => {
|
|
380
|
+
e.stopPropagation();
|
|
381
|
+
copyText(JSON.stringify(value, null, 2), e);
|
|
382
|
+
}}
|
|
383
|
+
>copy</span
|
|
384
|
+
>
|
|
385
|
+
</div>
|
|
386
|
+
${open
|
|
387
|
+
? html `<div class="jchildren">
|
|
388
|
+
${entries.map(([ck, cv]) => html `<${JsonNode} k=${ck} value=${cv} depth=${depth + 1} />`)}
|
|
389
|
+
<div class="jrow jclose" style=${{ paddingLeft: depth * 14 + "px" }}>${isArr ? "]" : "}"}</div>
|
|
390
|
+
</div>`
|
|
391
|
+
: null}
|
|
392
|
+
</div>`;
|
|
393
|
+
}
|
|
394
|
+
function JsonTree({ value }) {
|
|
395
|
+
return html `<div class="jtree"><${JsonNode} value=${value} depth=${0} /></div>`;
|
|
396
|
+
}
|
|
397
|
+
// The row detail panel: docked right of the grid, lists every column's FULL value (not the
|
|
398
|
+
// grid's clipped one line). A JSON-valued column renders as a collapsible tree; anything else
|
|
399
|
+
// renders as wrapped text. Each field, and the row as a whole, can be copied to the clipboard.
|
|
400
|
+
function RowInspector({ row, onClose }) {
|
|
401
|
+
const cols = Object.keys(row);
|
|
402
|
+
const title = String(row.id ?? row[cols[0]] ?? "row");
|
|
403
|
+
return html `
|
|
404
|
+
<div class="rowinspector">
|
|
405
|
+
<div class="inspector-hd">
|
|
406
|
+
<span class="ttl">${title}</span>
|
|
407
|
+
<span class="x" onClick=${onClose} title="close">✕</span>
|
|
408
|
+
</div>
|
|
409
|
+
<div class="copybar">
|
|
410
|
+
<button class="copybtn" onClick=${(e) => copyText(JSON.stringify(row, null, 2), e)}>Copy row (JSON)</button>
|
|
411
|
+
</div>
|
|
412
|
+
${cols.map((c) => {
|
|
413
|
+
const raw = row[c];
|
|
414
|
+
const json = asJson(raw);
|
|
415
|
+
return html `<div class="rowfield">
|
|
416
|
+
<div class="rowfield-hd">
|
|
417
|
+
<span class="rowfield-k">${c}</span>
|
|
418
|
+
<span
|
|
419
|
+
class="jtree-copy"
|
|
420
|
+
title="Copy this field"
|
|
421
|
+
onClick=${(e) => copyText(json ? JSON.stringify(json, null, 2) : String(raw ?? ""), e)}
|
|
422
|
+
>copy</span
|
|
423
|
+
>
|
|
424
|
+
</div>
|
|
425
|
+
${json
|
|
426
|
+
? html `<${JsonTree} value=${json} />`
|
|
427
|
+
: html `<div class="rowfield-v">${raw == null ? html `<span class="j-null">null</span>` : String(raw)}</div>`}
|
|
428
|
+
</div>`;
|
|
429
|
+
})}
|
|
430
|
+
</div>
|
|
431
|
+
`;
|
|
432
|
+
}
|
|
@@ -475,6 +475,22 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
475
475
|
const lines = store.viewFrames().filter((r) => r.id != null && sel.has(r.id)).map(rawLine);
|
|
476
476
|
navigator.clipboard?.writeText(lines.join("\n"));
|
|
477
477
|
}, [sel]);
|
|
478
|
+
// Empty the feed: drop the store's records, then reset this component's own view state.
|
|
479
|
+
// forceSnap is required, not redundant -- store.clearView emits "feed", but that handler is
|
|
480
|
+
// incremental and diffs against store.cache.length, which does not necessarily drop to 0 (other
|
|
481
|
+
// tabs' records survive a scoped clear), so it would leave the stale snapshot rendered.
|
|
482
|
+
// Selection and highlight are dropped because they reference ids that no longer exist, and
|
|
483
|
+
// newCount is zeroed so the "↑ newest" pill does not advertise rows that were just discarded.
|
|
484
|
+
// Follow state is left alone: clear does not change whether the user is tailing.
|
|
485
|
+
const clearView = useCallback(() => {
|
|
486
|
+
store.clearView();
|
|
487
|
+
setSel(new Set());
|
|
488
|
+
anchorRef.current = null;
|
|
489
|
+
highlightRef.current = null;
|
|
490
|
+
setNewCount(0);
|
|
491
|
+
onInspect && onInspect(null);
|
|
492
|
+
forceSnap();
|
|
493
|
+
}, [forceSnap, onInspect]);
|
|
478
494
|
const scrollIntoView = useCallback((idx) => {
|
|
479
495
|
const el = vpRef.current;
|
|
480
496
|
if (!el)
|
|
@@ -858,6 +874,8 @@ export function Feed({ spec, onInspect, selectedId }) {
|
|
|
858
874
|
${isLogish ? html `<label class="fsortlbl">app <select onChange=${(e) => changePkg(e.currentTarget.value)}><option value="__all__" selected=${curPkg === "__all__"}>all apps</option>${pkgOptions.map((p) => html `<option value=${p} selected=${p === curPkg}>${shortPkg(p)}</option>`)}</select></label>` : null}
|
|
859
875
|
<label class="fsortlbl">sort <select value=${sort} onChange=${(e) => setSort(e.currentTarget.value)}>${sortOpts.map((o) => html `<option value=${o.key}>${o.label}</option>`)}</select></label>
|
|
860
876
|
<button class=${"fbtn" + (paused ? " paused" : "")} title="pause / resume the live feed" onClick=${() => setPaused((p) => !p)}>${paused ? "▶ resume" : "⏸ pause"}</button>
|
|
877
|
+
<button class="fbtn" disabled=${!total} onClick=${clearView}
|
|
878
|
+
title="empty this dashboard's view. The device keeps its own buffers, so reconnecting or switching source backfills recent records again. To wipe the device too, ask Claude Code for clear_buffers.">Clear</button>
|
|
861
879
|
<button class="fbtn" disabled=${!sel.size} onClick=${copySel}>Copy ${sel.size || ""}</button>
|
|
862
880
|
${sel.size ? html `<button class="fbtn" onClick=${clearSel}>Clear sel</button>` : null}
|
|
863
881
|
<span class=${"fstatus " + (paused ? "st-paused" : following ? "st-live" : "st-locked")}>${paused ? "⏸ paused" : following ? "● live" : "⏸ locked"}</span>
|
|
@@ -39,7 +39,16 @@ export function useGlobalKeydown(handler) {
|
|
|
39
39
|
export function useStoreValue(emitter, event, read) {
|
|
40
40
|
const readRef = useLatestRef(read);
|
|
41
41
|
const [v, setV] = useState(read);
|
|
42
|
-
useEffect(() =>
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
// Re-read once on mount, before subscribing. useState's initializer ran during render,
|
|
44
|
+
// which can land before an async change that fires between render and this effect actually
|
|
45
|
+
// committing (network response beats effect scheduling under real-world timing). Without
|
|
46
|
+
// this, a change in that gap is lost for good: nothing guarantees a LATER emit corrects it,
|
|
47
|
+
// since a caller like the spec poll dedupes on an unchanged value and stops emitting once
|
|
48
|
+
// it already matches.
|
|
49
|
+
setV(readRef.current());
|
|
50
|
+
return emitter.on(event, () => setV(readRef.current()));
|
|
51
|
+
}, [emitter, event, readRef]);
|
|
43
52
|
return v;
|
|
44
53
|
}
|
|
45
54
|
// Force a re-render of this subtree whenever ANY of the named emitter events fire, without
|
|
@@ -34,21 +34,29 @@ export const FIELD_VALUES = {
|
|
|
34
34
|
// SOURCE registry: one row per source. `kind` routes the view (streaming feed vs the
|
|
35
35
|
// point-in-time state browser) without a hardcoded source check.
|
|
36
36
|
export const SOURCES = {
|
|
37
|
-
network: { label: "Network", kind: "stream", hasDetailEndpoint: true, eagerCapture: true, ringSize: 400, detailNoun: "the full request/response body" },
|
|
38
|
-
rtm: { label: "RTM", kind: "stream", hasDetailEndpoint: true, eagerCapture: true, ringSize: 2000, detailNoun: "the full payload" },
|
|
39
|
-
clog: { label: "Clogs", kind: "stream", hasDetailEndpoint: true, eagerCapture: true, ringSize: 1000, detailNoun: "the full payload" },
|
|
40
|
-
trace: { label: "Traces", kind: "stream", hasDetailEndpoint: true, ringSize: 2000, detailNoun: "the span timing and tag detail" },
|
|
41
|
-
log: { label: "Logs", kind: "stream", hasDetailEndpoint: false },
|
|
42
|
-
all: { label: "Live", kind: "stream" },
|
|
43
|
-
db: { label: "Database", kind: "state" },
|
|
44
|
-
prefs: { label: "Preferences", kind: "state" },
|
|
37
|
+
network: { label: "Network", kind: "stream", origin: "device", hasDetailEndpoint: true, eagerCapture: true, ringSize: 400, detailNoun: "the full request/response body" },
|
|
38
|
+
rtm: { label: "RTM", kind: "stream", origin: "device", hasDetailEndpoint: true, eagerCapture: true, ringSize: 2000, detailNoun: "the full payload" },
|
|
39
|
+
clog: { label: "Clogs", kind: "stream", origin: "device", hasDetailEndpoint: true, eagerCapture: true, ringSize: 1000, detailNoun: "the full payload" },
|
|
40
|
+
trace: { label: "Traces", kind: "stream", origin: "device", hasDetailEndpoint: true, ringSize: 2000, detailNoun: "the span timing and tag detail" },
|
|
41
|
+
log: { label: "Logs", kind: "stream", origin: "host", hasDetailEndpoint: false },
|
|
42
|
+
all: { label: "Live", kind: "stream", origin: "alias" },
|
|
43
|
+
db: { label: "Database", kind: "state", origin: "device" },
|
|
44
|
+
prefs: { label: "Preferences", kind: "state", origin: "device" },
|
|
45
45
|
// Feature flags: a point-in-time snapshot like db/prefs (own container, no SSE feed).
|
|
46
|
-
flags: { label: "Feature Flags", kind: "state" },
|
|
46
|
+
flags: { label: "Feature Flags", kind: "state", origin: "device" },
|
|
47
47
|
};
|
|
48
48
|
// The set of streaming source kinds the store admits off the SSE stream (derived from SOURCES,
|
|
49
49
|
// excluding the non-stream db + the unified "all" alias).
|
|
50
50
|
export const STREAM_KINDS = Object.entries(SOURCES)
|
|
51
|
-
.filter(([
|
|
51
|
+
.filter(([, v]) => v.kind === "stream" && v.origin !== "alias")
|
|
52
|
+
.map(([k]) => k);
|
|
53
|
+
// The streaming kinds that come FROM THE DEVICE, so one arriving is proof the device-side Radar
|
|
54
|
+
// server is alive and answering. Selected by asking for "device" rather than by excluding the
|
|
55
|
+
// host-side ones, so there is no default to point the wrong way: a new source without an origin does
|
|
56
|
+
// not compile, and one added as "host" or "alias" stays out of the evidence set without anyone having
|
|
57
|
+
// to remember. The registry test still pins this set exactly, as a second line rather than the only one.
|
|
58
|
+
export const DEVICE_STREAM_KINDS = Object.entries(SOURCES)
|
|
59
|
+
.filter(([, v]) => v.kind === "stream" && v.origin === "device")
|
|
52
60
|
.map(([k]) => k);
|
|
53
61
|
// The kinds that have a /detail endpoint (inspector click-fetch). Derived from
|
|
54
62
|
// hasDetailEndpoint so adding a detailable source is one SOURCES edit.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// over the feed / db / blank views alike.
|
|
6
6
|
import { html } from "./html.js";
|
|
7
7
|
import { useState, useEffect, useRef, useCallback } from "preact/hooks";
|
|
8
|
+
import { showToast, showSaveToast, onDownloadFinished, revealInFinder, isCaptureDownloadMatch, } from "./toast.js";
|
|
8
9
|
// The MJPEG live stream runs at 20fps (measured sweet spot: 20 beats 12 on both frame
|
|
9
10
|
// rate and jitter; 30/60 add no frames and worsen jitter). The cache-buster ?t pins a
|
|
10
11
|
// fresh connection each time the <img> is (re)wired so a stale frame is never reused.
|
|
@@ -17,35 +18,124 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
17
18
|
const [consent, setConsent] = useState(false);
|
|
18
19
|
const [recording, setRecording] = useState(false);
|
|
19
20
|
const [hint, setHint] = useState("");
|
|
21
|
+
// Set once the native side (packaged dock app only) confirms a download actually finished and
|
|
22
|
+
// reports its real on-disk path -- the requested filename can differ from the final one on a
|
|
23
|
+
// collision, so this can only be known after the fact, not guessed at request time.
|
|
24
|
+
const [revealPath, setRevealPath] = useState(null);
|
|
25
|
+
// The capture this hint is waiting on, set from the moment a save is requested and cleared
|
|
26
|
+
// once some unrelated hint takes the line over.
|
|
27
|
+
// The native side reports a finished download hundreds of ms after the request (it can only
|
|
28
|
+
// name the real on-disk path once the write completes), and by then the hint may belong to
|
|
29
|
+
// something else entirely -- the live-cast effect's 3.5s "live." message is the one that
|
|
30
|
+
// shows up in practice. Accepting the path regardless left that unrelated line underlined
|
|
31
|
+
// and revealing a PNG. Gating acceptance is what closes it; clearing afterwards cannot,
|
|
32
|
+
// because the overwrite has already happened by the time the path arrives.
|
|
33
|
+
// It holds the FILE, not just a flag: two captures a download-latency apart would otherwise
|
|
34
|
+
// leave the hint naming the second save while a click revealed the first one's file.
|
|
35
|
+
const awaitedFile = useRef(null);
|
|
36
|
+
useEffect(() => onDownloadFinished((path) => {
|
|
37
|
+
const want = awaitedFile.current;
|
|
38
|
+
if (!want || !isCaptureDownloadMatch(path, want))
|
|
39
|
+
return;
|
|
40
|
+
setRevealPath(path);
|
|
41
|
+
}), []);
|
|
20
42
|
const imgRef = useRef(null);
|
|
43
|
+
// One capture at a time. The download frame is a singleton, so a second click while a
|
|
44
|
+
// request is still open repoints it and cancels the first.
|
|
45
|
+
const [saving, setSaving] = useState(false);
|
|
21
46
|
// The overlay is a permanent sibling in App (it returns null when closed but never
|
|
22
47
|
// unmounts), so an unmount-cleanup never fires to stop a recording on close. Track the
|
|
23
48
|
// live recording flag in a ref so the open-keyed effect below reads the CURRENT value
|
|
24
49
|
// (not a stale closure) when it tears down.
|
|
25
50
|
const recordingRef = useRef(false);
|
|
26
51
|
recordingRef.current = recording;
|
|
52
|
+
// Trigger a download by navigating a hidden iframe at the endpoint, never the visible page.
|
|
53
|
+
// The server already sends Content-Disposition: attachment on these routes, and a browser (or
|
|
54
|
+
// WKWebView) treats that the same in a subframe as in the main frame: it hands the response to
|
|
55
|
+
// the download machinery instead of rendering it, so the iframe itself just stays blank. That
|
|
56
|
+
// containment is the point. A top-level <a> click here means ANY unexpected response --a 404,
|
|
57
|
+
// a slow ffmpeg finalize, a future server error-- replaces the whole dashboard with raw text,
|
|
58
|
+
// which is exactly the class of bug that stranded the packaged dock app before (see the
|
|
59
|
+
// navigationResponse handling in RadarApp.swift). Routing through a frame nobody sees makes
|
|
60
|
+
// that failure mode impossible regardless of what the server answers with.
|
|
61
|
+
function getDownloadFrame() {
|
|
62
|
+
let frame = document.getElementById("scdlframe");
|
|
63
|
+
if (!frame) {
|
|
64
|
+
frame = document.createElement("iframe");
|
|
65
|
+
frame.id = "scdlframe";
|
|
66
|
+
frame.style.display = "none";
|
|
67
|
+
document.body.appendChild(frame);
|
|
68
|
+
}
|
|
69
|
+
return frame;
|
|
70
|
+
}
|
|
71
|
+
const triggerDownload = (url) => {
|
|
72
|
+
getDownloadFrame().src = url;
|
|
73
|
+
};
|
|
27
74
|
// Download whatever /screen/record/stop returns, then unset recording. Shared by the
|
|
28
75
|
// explicit stop button and the close-while-recording teardown so both behave identically.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
// Always leaves a confirmation behind, both the inline hint AND the floating toast: a silent
|
|
77
|
+
// success looks identical to a silent failure, and closing the panel to trigger this (the
|
|
78
|
+
// auto-save path right below) unmounts the inline hint before anyone can read it -- the toast
|
|
79
|
+
// is what actually survives that.
|
|
80
|
+
// Report a completed save the same way for a screenshot and a recording: the inline hint AND
|
|
81
|
+
// the floating toast, and the reveal gate opened for THIS save's file, so a native
|
|
82
|
+
// download-finished path is accepted only when it is the one this message names.
|
|
83
|
+
// A save whose file the server did not name still gets announced, it just cannot offer reveal:
|
|
84
|
+
// with no name there is nothing to match a late download path against, and matching nothing is
|
|
85
|
+
// how the wrong file got revealed in the first place.
|
|
86
|
+
const announceSave = useCallback((msg, file) => {
|
|
87
|
+
awaitedFile.current = file;
|
|
88
|
+
setHint(msg);
|
|
89
|
+
if (file)
|
|
90
|
+
showSaveToast(msg, file);
|
|
91
|
+
else
|
|
92
|
+
showToast(msg);
|
|
93
|
+
}, []);
|
|
94
|
+
// Say what actually happened, with the reveal gate shut: there is no file to reveal, so a
|
|
95
|
+
// late path from an earlier save must not attach itself to this line.
|
|
96
|
+
const announceFailure = useCallback((msg) => {
|
|
97
|
+
awaitedFile.current = null;
|
|
98
|
+
setRevealPath(null);
|
|
99
|
+
setHint(msg);
|
|
100
|
+
showToast(msg);
|
|
101
|
+
}, []);
|
|
102
|
+
// Ask the server to save, and only claim success once it says it did. Both capture routes are
|
|
103
|
+
// two-phase for the same reason: the download itself is a Content-Disposition response the
|
|
104
|
+
// page cannot observe, so the JSON reply is the only place an error can be seen.
|
|
105
|
+
const requestSave = useCallback(async (url, subject, emptyMessage) => {
|
|
106
|
+
let r;
|
|
34
107
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const a = document.createElement("a");
|
|
38
|
-
a.href = u;
|
|
39
|
-
a.download = r.file || "radar-screen.mp4";
|
|
40
|
-
document.body.appendChild(a);
|
|
41
|
-
a.click();
|
|
42
|
-
a.remove();
|
|
43
|
-
setTimeout(() => URL.revokeObjectURL(u), 10000);
|
|
108
|
+
const res = await fetch(url, { method: "POST", headers: { "X-Radar-Dashboard": "1" } });
|
|
109
|
+
r = (await res.json());
|
|
44
110
|
}
|
|
45
111
|
catch {
|
|
46
|
-
|
|
112
|
+
// A rejected fetch or unparseable body is a dead dashboard server, which is exactly the
|
|
113
|
+
// one failure the old single-phase screenshot could not report either.
|
|
114
|
+
announceFailure(subject + " failed (dashboard server not responding)");
|
|
115
|
+
return;
|
|
47
116
|
}
|
|
48
|
-
|
|
117
|
+
if (r.error) {
|
|
118
|
+
announceFailure(subject + " failed: " + r.error);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!r.download) {
|
|
122
|
+
announceFailure(emptyMessage);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// Reveal belongs to THIS save from here on, so clear the previous one before the
|
|
126
|
+
// native side answers with a path.
|
|
127
|
+
setRevealPath(null);
|
|
128
|
+
const sizeKb = r.sizeBytes ? Math.max(1, Math.round(r.sizeBytes / 1024)) : null;
|
|
129
|
+
// Announce (which arms the reveal gate for this file) before starting the download, so the
|
|
130
|
+
// gate is never shut at the moment the native side reports the path. The file is already on
|
|
131
|
+
// disk server-side by now, so the message is true either way.
|
|
132
|
+
announceSave("saved " + (r.file || subject) + (sizeKb ? " (" + sizeKb + " KB)" : ""), r.file ?? null);
|
|
133
|
+
triggerDownload(r.download);
|
|
134
|
+
}, [announceFailure, announceSave]);
|
|
135
|
+
const stopAndSave = useCallback(async () => {
|
|
136
|
+
setRecording(false);
|
|
137
|
+
await requestSave("/screen/record/stop", "recording", "nothing to save (recording was too short or never started)");
|
|
138
|
+
}, [requestSave]);
|
|
49
139
|
// Stop + save a running recording when the panel closes. Without this, closing the panel
|
|
50
140
|
// (or toggling ▣ Screen) mid-recording unmounts the <img> and drops the live viewer, but
|
|
51
141
|
// the server keeps screenrecord + ffmpeg + a growing mp4 alive (removeViewer only cleans
|
|
@@ -69,17 +159,30 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
69
159
|
if (open)
|
|
70
160
|
loadCaps();
|
|
71
161
|
}, [open, loadCaps]);
|
|
162
|
+
// Sets an ordinary status hint and clears any reveal link along with it. Plain setHint alone
|
|
163
|
+
// is wrong for every hint EXCEPT the two save confirmations below: without clearing revealPath,
|
|
164
|
+
// an unrelated status line (the live-stream message, a consent error, a re-detect result) would
|
|
165
|
+
// stay underlined and clickable pointing at whatever file a PREVIOUS screenshot or recording
|
|
166
|
+
// saved, which is exactly the bug seen live -- the "live. Screen again to close." status line
|
|
167
|
+
// rendered as if it were a save confirmation, left over from an earlier reveal.
|
|
168
|
+
const setPlainHint = useCallback((msg) => {
|
|
169
|
+
// Also shuts the reveal gate: once an unrelated line owns the hint, a save's late
|
|
170
|
+
// download-finished path has nothing left to attach to and must be ignored.
|
|
171
|
+
awaitedFile.current = null;
|
|
172
|
+
setRevealPath(null);
|
|
173
|
+
setHint(msg);
|
|
174
|
+
}, []);
|
|
72
175
|
// wire the live <img> once consent + ffmpeg are present
|
|
73
176
|
useEffect(() => {
|
|
74
177
|
if (!open || !consent)
|
|
75
178
|
return;
|
|
76
179
|
if (caps && caps.liveCast && imgRef.current) {
|
|
77
180
|
imgRef.current.src = streamSrc();
|
|
78
|
-
|
|
79
|
-
const id = setTimeout(() =>
|
|
181
|
+
setPlainHint("capturing first frame (~3s on a foldable)…");
|
|
182
|
+
const id = setTimeout(() => setPlainHint("live. ▣ Screen again to close."), 3500);
|
|
80
183
|
return () => clearTimeout(id);
|
|
81
184
|
}
|
|
82
|
-
}, [open, consent, caps]);
|
|
185
|
+
}, [open, consent, caps, setPlainHint]);
|
|
83
186
|
const accept = useCallback(async () => {
|
|
84
187
|
try {
|
|
85
188
|
// X-Radar-Dashboard marks this as coming from our own client. Without it the server refuses
|
|
@@ -88,32 +191,28 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
88
191
|
setConsent(true);
|
|
89
192
|
}
|
|
90
193
|
catch {
|
|
91
|
-
|
|
194
|
+
setPlainHint("consent failed");
|
|
92
195
|
}
|
|
93
|
-
}, []);
|
|
196
|
+
}, [setPlainHint]);
|
|
94
197
|
const shot = useCallback(async () => {
|
|
95
198
|
if (!consent) {
|
|
96
|
-
|
|
199
|
+
setPlainHint("accept the notice first");
|
|
97
200
|
return;
|
|
98
201
|
}
|
|
202
|
+
if (saving)
|
|
203
|
+
return;
|
|
204
|
+
setSaving(true);
|
|
205
|
+
setPlainHint("taking a screenshot…");
|
|
99
206
|
try {
|
|
100
|
-
|
|
101
|
-
const u = URL.createObjectURL(blob);
|
|
102
|
-
const a = document.createElement("a");
|
|
103
|
-
a.href = u;
|
|
104
|
-
a.download = "radar-screen-" + Date.now() + ".png";
|
|
105
|
-
document.body.appendChild(a);
|
|
106
|
-
a.click();
|
|
107
|
-
a.remove();
|
|
108
|
-
setTimeout(() => URL.revokeObjectURL(u), 10000);
|
|
207
|
+
await requestSave("/screen/shot/save", "screenshot", "nothing to save");
|
|
109
208
|
}
|
|
110
|
-
|
|
111
|
-
|
|
209
|
+
finally {
|
|
210
|
+
setSaving(false);
|
|
112
211
|
}
|
|
113
|
-
}, [consent]);
|
|
212
|
+
}, [consent, saving, requestSave, setPlainHint]);
|
|
114
213
|
const rec = useCallback(async () => {
|
|
115
214
|
if (!consent || !(caps && caps.liveCast)) {
|
|
116
|
-
|
|
215
|
+
setPlainHint("recording needs ffmpeg + consent");
|
|
117
216
|
return;
|
|
118
217
|
}
|
|
119
218
|
if (!recording) {
|
|
@@ -127,9 +226,9 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
127
226
|
if (imgRef.current)
|
|
128
227
|
imgRef.current.src = streamSrc();
|
|
129
228
|
}
|
|
130
|
-
}, [consent, caps, recording, stopAndSave]);
|
|
229
|
+
}, [consent, caps, recording, stopAndSave, setPlainHint]);
|
|
131
230
|
const redetect = useCallback(async () => {
|
|
132
|
-
|
|
231
|
+
setPlainHint("re-detecting active panel…");
|
|
133
232
|
// Authored: redetect tears down the live cast and deletes finished recordings, so the server
|
|
134
233
|
// refuses it without proof this is our own client.
|
|
135
234
|
const r = await (await fetch("/screen/redetect", { headers: { "X-Radar-Dashboard": "1" } }))
|
|
@@ -137,8 +236,8 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
137
236
|
.catch(() => ({}));
|
|
138
237
|
if (consent && caps && caps.liveCast && imgRef.current)
|
|
139
238
|
imgRef.current.src = streamSrc();
|
|
140
|
-
|
|
141
|
-
}, [consent, caps]);
|
|
239
|
+
setPlainHint("display: " + (r.display || "default"));
|
|
240
|
+
}, [consent, caps, setPlainHint]);
|
|
142
241
|
if (!open)
|
|
143
242
|
return null;
|
|
144
243
|
let body;
|
|
@@ -155,7 +254,7 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
155
254
|
`;
|
|
156
255
|
}
|
|
157
256
|
else if (caps && caps.liveCast) {
|
|
158
|
-
body = html `<img id="screenimg" ref=${imgRef} alt="device screen" onError=${() =>
|
|
257
|
+
body = html `<img id="screenimg" ref=${imgRef} alt="device screen" onError=${() => setPlainHint("stream dropped (device disconnected?). ⟳ to retry.")} />`;
|
|
159
258
|
}
|
|
160
259
|
else {
|
|
161
260
|
const cmd = caps && caps.installHint;
|
|
@@ -174,13 +273,18 @@ export function ScreenOverlay({ open, onClose }) {
|
|
|
174
273
|
<div id="screenpanel" class="on">
|
|
175
274
|
<div class="schead">
|
|
176
275
|
<span class="sctitle">Device screen</span>
|
|
177
|
-
<button class="scbtn" onClick=${shot} title="Full-resolution screenshot">📷</button>
|
|
178
|
-
<button class=${"scbtn" + (recording ? " rec" : "")} onClick=${rec} title="Record to mp4">${recording ? "■ stop" : "● rec"}</button>
|
|
276
|
+
<button class="scbtn" onClick=${shot} disabled=${saving} title="Full-resolution screenshot">📷</button>
|
|
277
|
+
<button class=${"scbtn" + (recording ? " rec" : "")} onClick=${rec} disabled=${saving} title="Record to mp4">${recording ? "■ stop" : "● rec"}</button>
|
|
179
278
|
<button class="scbtn" onClick=${redetect} title="Re-detect the active display">⟳</button>
|
|
180
279
|
<button class="scbtn" onClick=${onClose} title="Close">✕</button>
|
|
181
280
|
</div>
|
|
281
|
+
<div
|
|
282
|
+
id="schint"
|
|
283
|
+
style=${revealPath ? { cursor: "pointer", textDecoration: "underline" } : undefined}
|
|
284
|
+
title=${revealPath ? "Click to show in Finder" : undefined}
|
|
285
|
+
onClick=${revealPath ? () => revealInFinder(revealPath) : undefined}
|
|
286
|
+
>${hint}</div>
|
|
182
287
|
<div id="screenbody">${body}</div>
|
|
183
|
-
<div id="schint">${hint}</div>
|
|
184
288
|
</div>
|
|
185
289
|
`;
|
|
186
290
|
}
|