ccdeck 4.0.1 → 4.0.3
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 +5 -5
- package/dist/web/assets/AccountBridge-CmB2ClCh.js +1 -0
- package/dist/web/assets/{AccountSection-Cu-96Q00.js → AccountSection-C0_ISsSw.js} +1 -1
- package/dist/web/assets/BrowserWatchModal-C4G5G12x.js +1 -0
- package/dist/web/assets/{FeedbackConversations-BgVk0nkA.js → FeedbackConversations-Bqqn0VaM.js} +1 -1
- package/dist/web/assets/{IntegrationModal-CEj5oJg4.js → IntegrationModal-CKgtTF3f.js} +1 -1
- package/dist/web/assets/{IntegrationSkeleton-DD7YiFgd.js → IntegrationSkeleton-WE6DOfez.js} +1 -1
- package/dist/web/assets/{RadioPanel-BhnzWRCT.js → RadioPanel-j_p9qx4L.js} +1 -1
- package/dist/web/assets/{StageShell-DmJu3dU1.js → StageShell-Bl0ddeiL.js} +3 -3
- package/dist/web/assets/{TrafficRadar-C8-ieIw5.js → TrafficRadar-CTGz345C.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-BThv9Kja.js → UsageHistoryModal-C2IDurbk.js} +1 -1
- package/dist/web/assets/app-82JtqhPe.css +1 -0
- package/dist/web/assets/{app-ZMmmEHxF.js → app-CdRq5GPP.js} +74 -74
- package/dist/web/assets/{index-zSxC5ueJ.js → index-pIus964m.js} +1 -1
- package/dist/web/assets/{inspector-status-pane-BgQG0bQi.js → inspector-status-pane-BY6DHEeo.js} +1 -1
- package/dist/web/assets/{screens-DD0uCtat.js → screens-BMLZR8WS.js} +1 -1
- package/dist/web/assets/{stage-board-J2rKA9Pg.js → stage-board-6RJd7VXM.js} +1 -1
- package/dist/web/assets/{use-account-DvFObI4M.js → use-account-t_qL6ab-.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +6 -6
- package/release-notes.json +34 -0
- package/src/server/command-panel-engine.mjs +2 -2
- package/src/server/command-panel-platform.mjs +2 -2
- package/src/server/engine-package.mjs +2 -1
- package/src/server/pro-engine-install.mjs +2 -1
- package/src/server/pro-engine-terminal.mjs +25 -4
- package/src/server/terminal-js-routes.mjs +16 -3
- package/src/server/terminal-routes.mjs +45 -3
- package/src/server/terminal-sessions.mjs +2 -1
- package/src/server/tmux-download.mjs +21 -1
- package/src/server/tmux.mjs +144 -27
- package/dist/web/assets/AccountBridge-fp-fsMx-.js +0 -1
- package/dist/web/assets/BrowserWatchModal-CvUx07C6.js +0 -1
- package/dist/web/assets/app-DtosBis5.css +0 -1
package/src/server/tmux.mjs
CHANGED
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
// building C on somebody's machine is not something a tool that "installs
|
|
25
25
|
// nothing" gets to do. A machine without tmux is told the one line that
|
|
26
26
|
// installs it for that platform — a fact about the machine, not an error.
|
|
27
|
+
//
|
|
28
|
+
// CCDECK'S OWN BUILD OVER A TMUX OLDER THAN 3.6. The user's tmux is the one
|
|
29
|
+
// they chose, and wins whenever it is 3.6 or newer. One that is 3.2–3.5 works
|
|
30
|
+
// but mis-draws a row with a wide glyph in it, which a reconnecting pane then
|
|
31
|
+
// copies (tmux-download.mjs PREFERRED_TMUX_VERSION), so once ccdeck's own
|
|
32
|
+
// build is in place the deck runs that instead — but never while the deck's
|
|
33
|
+
// own server still runs sessions under the older tmux: they keep it until
|
|
34
|
+
// they end (ownOverOlder). CCDECK_TMUX is never second-guessed.
|
|
27
35
|
import { execFile } from "node:child_process";
|
|
28
36
|
import { existsSync, readFileSync } from "node:fs";
|
|
29
37
|
import { pathLookup } from "./exec-spec.mjs";
|
|
@@ -32,7 +40,7 @@ import { pathLookup } from "./exec-spec.mjs";
|
|
|
32
40
|
// anything here — it daemonises — which is the whole point of using it.
|
|
33
41
|
import { watchChild } from "./exec-children.mjs";
|
|
34
42
|
import { deckDataDir } from "./deck-home.mjs";
|
|
35
|
-
import { managedTmuxPath } from "./tmux-download.mjs";
|
|
43
|
+
import { PREFERRED_TMUX_VERSION, managedTmuxPath } from "./tmux-download.mjs";
|
|
36
44
|
|
|
37
45
|
/** The deck's own tmux server. Every deck-launched session lives here. */
|
|
38
46
|
export const DECK_SOCKET = Object.freeze({ name: "ccdeck" });
|
|
@@ -55,7 +63,10 @@ const KNOWN_PLACES = ["/opt/homebrew/bin/tmux", "/usr/local/bin/tmux", "/usr/bin
|
|
|
55
63
|
/** How long "no usable tmux" is believed. An answer that tmux is present is
|
|
56
64
|
* kept until resetTmuxCache; an answer that it is missing is not, because the
|
|
57
65
|
* panel's own advice is to go and install it — and the click after that
|
|
58
|
-
* install has to see it without a deck restart.
|
|
66
|
+
* install has to see it without a deck restart. A tmux older than 3.6 kept
|
|
67
|
+
* beside ccdeck's own build (ownOverOlder) is believed as long and no
|
|
68
|
+
* longer, so the deck moves to the build soon after the last session that
|
|
69
|
+
* held it back has ended. */
|
|
59
70
|
const MISS_TTL_MS = 10_000;
|
|
60
71
|
|
|
61
72
|
/** The line shown when no install command is known for this machine. */
|
|
@@ -231,51 +242,157 @@ export function resetTmuxCache() {
|
|
|
231
242
|
* works, and saying otherwise would send its owner off to install something
|
|
232
243
|
* they already have.
|
|
233
244
|
*
|
|
245
|
+
* The first usable tmux is the answer, unless it is 3.2–3.5 and ccdeck's own
|
|
246
|
+
* build may take its place (ownOverOlder), which asks the deck's server on
|
|
247
|
+
* `socket` (DECK_SOCKET unless a caller names another) what it runs.
|
|
248
|
+
*
|
|
234
249
|
* A candidate that exists but will not run `-V` is skipped as if absent. Never
|
|
235
250
|
* rejects.
|
|
236
251
|
*
|
|
237
|
-
* Remembered: a usable answer until resetTmuxCache, a missing one
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* case
|
|
252
|
+
* Remembered: a usable answer until resetTmuxCache, a missing one — or an
|
|
253
|
+
* older tmux kept beside the own build — for ten seconds (see MISS_TTL_MS),
|
|
254
|
+
* and concurrent callers share one probe. The memory is keyed on the inputs
|
|
255
|
+
* that decide the answer — platform, CCDECK_TMUX, PATH, where the own build
|
|
256
|
+
* lives and the socket — and on the very `run`, `exists` and `readFile` it was
|
|
257
|
+
* found with, so a case in the suite that injects fakes is never answered from
|
|
258
|
+
* another case's.
|
|
243
259
|
*
|
|
244
|
-
* `run(file, args, { env })` resolves `{ code, stdout }`; the real one
|
|
245
|
-
* execFile with a three-second deadline.
|
|
260
|
+
* `run(file, args, { env })` resolves `{ code, stdout, stderr }`; the real one
|
|
261
|
+
* is execFile with a three-second deadline.
|
|
246
262
|
*/
|
|
247
263
|
export function findTmux({
|
|
248
|
-
env = process.env, platform = process.platform,
|
|
264
|
+
env = process.env, platform = process.platform, socket = DECK_SOCKET,
|
|
249
265
|
run = runVersion, exists = existsSync, readFile = readText, now = Date.now,
|
|
250
266
|
} = {}) {
|
|
251
|
-
const key = [
|
|
267
|
+
const key = [
|
|
268
|
+
platform, env[TMUX_ENV] ?? "", env.PATH ?? env.Path ?? "", managedTmuxPath(deckDataDir(platform, env)),
|
|
269
|
+
socket?.name ?? "", socket?.path ?? "",
|
|
270
|
+
].join("\0");
|
|
252
271
|
const same = cached && cached.key === key && cached.run === run && cached.exists === exists && cached.readFile === readFile;
|
|
253
|
-
if (same && (cached.
|
|
254
|
-
const
|
|
255
|
-
const
|
|
272
|
+
if (same && (cached.lasting || now() - cached.at < MISS_TTL_MS)) return cached.promise;
|
|
273
|
+
const probe = probeTmux({ env, platform, run, exists, readFile, socket });
|
|
274
|
+
const promise = probe.then(p => p.found);
|
|
275
|
+
const entry = { key, run, exists, readFile, at: now(), lasting: false, promise };
|
|
256
276
|
cached = entry;
|
|
257
|
-
|
|
277
|
+
probe.then(p => { entry.lasting = p.found.ok && p.lasting; });
|
|
258
278
|
return promise;
|
|
259
279
|
}
|
|
260
280
|
|
|
261
281
|
const runVersion = (file, args, { env } = {}) => execTmux(file, args, { timeoutMs: 3000, env: tmuxEnv(env) });
|
|
262
282
|
const readText = (p) => readFileSync(p, "utf8");
|
|
263
283
|
|
|
264
|
-
|
|
265
|
-
|
|
284
|
+
/** findTmux's answer as `{ found, lasting }`: `lasting` false for an older
|
|
285
|
+
* tmux kept beside ccdeck's own build, which is asked again soon. */
|
|
286
|
+
async function probeTmux({ env, platform, run, exists, readFile, socket }) {
|
|
287
|
+
if (platform === "win32") return { found: Object.freeze({ ok: false, reason: "unsupported-platform" }), lasting: true };
|
|
288
|
+
const managed = managedTmuxPath(deckDataDir(platform, env));
|
|
289
|
+
const candidates = tmuxCandidates({ env, platform, exists, managed });
|
|
266
290
|
let tooOld = null;
|
|
267
|
-
for (const path of
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
291
|
+
for (const path of candidates) {
|
|
292
|
+
const said = await askVersion(run, path, env);
|
|
293
|
+
if (!said) continue;
|
|
294
|
+
const { raw, version } = said;
|
|
295
|
+
if (!version) return { found: Object.freeze({ ok: true, path, version: null, raw, warning: "unknown-version" }), lasting: true };
|
|
296
|
+
if (atLeast(version, MIN_TMUX_VERSION)) {
|
|
297
|
+
const found = Object.freeze({ ok: true, path, version: Object.freeze(version), raw });
|
|
298
|
+
if (atLeast(version, PREFERRED_TMUX_VERSION)) return { found, lasting: true };
|
|
299
|
+
return ownOverOlder(found, { candidates, managed, env, run, socket });
|
|
300
|
+
}
|
|
275
301
|
tooOld ??= { ok: false, reason: "too-old", path, version: Object.freeze(version), raw };
|
|
276
302
|
}
|
|
277
303
|
const install = tmuxInstallLine(platform, platform === "linux" ? osReleaseText(readFile) : "");
|
|
278
|
-
return Object.freeze(tooOld ? { ...tooOld, install } : { ok: false, reason: "missing", install });
|
|
304
|
+
return { found: Object.freeze(tooOld ? { ...tooOld, install } : { ok: false, reason: "missing", install }), lasting: true };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** What `path -V` says, as `{ raw, version }` (version null when unreadable),
|
|
308
|
+
* or null for a tmux that would not run it. */
|
|
309
|
+
async function askVersion(run, path, env) {
|
|
310
|
+
let r;
|
|
311
|
+
try { r = await run(path, ["-V"], { env }); } catch { return null; }
|
|
312
|
+
if (!r || r.code !== 0) return null;
|
|
313
|
+
const raw = String(r.stdout ?? "").trim();
|
|
314
|
+
return { raw, version: parseTmuxVersion(raw) };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* `older`, the first usable tmux and one 3.2–3.5, or ccdeck's own build in its
|
|
319
|
+
* place — as `{ found, lasting }`.
|
|
320
|
+
*
|
|
321
|
+
* The build takes it over only when all of this holds:
|
|
322
|
+
* - it is one of the candidates: fetched, and CCDECK_TMUX not set (that
|
|
323
|
+
* names the only candidate, and is never second-guessed);
|
|
324
|
+
* - it says it is PREFERRED_TMUX_VERSION or newer;
|
|
325
|
+
* - the deck's server runs no session under an older tmux. Asked of the
|
|
326
|
+
* build itself, `list-sessions -F '#{version}'` on `socket`, because only
|
|
327
|
+
* that direction works: measured with Ubuntu 24.04's tmux 3.4 and
|
|
328
|
+
* ccdeck's 3.8, a 3.8 client lists, reads and starts sessions on a 3.4
|
|
329
|
+
* server, while a 3.4 client gets "server exited unexpectedly" from a 3.8
|
|
330
|
+
* one. `#{version}` is the server's own, in every tmux since 2.4.
|
|
331
|
+
*
|
|
332
|
+
* Otherwise the older tmux stays, and nothing is moved, restarted or killed:
|
|
333
|
+
* sessions started under it keep the server they are in. Without the build
|
|
334
|
+
* that is the whole answer, kept until resetTmuxCache — the status route
|
|
335
|
+
* fetches the build behind it (ownTmuxWanted), and forgets this answer once it
|
|
336
|
+
* lands. Beside the build it is believed for MISS_TTL_MS only: the server
|
|
337
|
+
* empties when its last session ends, and the next ask after that moves to
|
|
338
|
+
* the build. An answer the build or the server would not give (a timeout, a
|
|
339
|
+
* failure it does not explain) keeps the older tmux too, and is asked again
|
|
340
|
+
* as soon.
|
|
341
|
+
*/
|
|
342
|
+
async function ownOverOlder(older, { candidates, managed, env, run, socket }) {
|
|
343
|
+
if (!managed || older.path === managed || !candidates.includes(managed)) return { found: older, lasting: true };
|
|
344
|
+
const own = await askVersion(run, managed, env);
|
|
345
|
+
if (!own?.version || !atLeast(own.version, PREFERRED_TMUX_VERSION)) return { found: older, lasting: false };
|
|
346
|
+
let listing = null;
|
|
347
|
+
try {
|
|
348
|
+
listing = await run(managed, tmuxCommand(managed, socket, ["list-sessions", "-F", "#{version}"]).slice(1), { env });
|
|
349
|
+
} catch { /* unanswered: the older tmux stays */ }
|
|
350
|
+
if (deckServerHoldsOlder(listing)) return { found: older, lasting: false };
|
|
351
|
+
return { found: Object.freeze({ ok: true, path: managed, version: Object.freeze(own.version), raw: own.raw }), lasting: true };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** A failed listing that only says there is no server to answer it: a
|
|
355
|
+
* socket nobody answers on, none at all, or a server with no session. Not
|
|
356
|
+
* "server exited unexpectedly", which a tmux client also says of a server it
|
|
357
|
+
* cannot speak to. */
|
|
358
|
+
const NO_DECK_SERVER = /no server running|error connecting to|^no sessions/im;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Whether the deck's server, as ccdeck's own build answered `list-sessions -F
|
|
362
|
+
* '#{version}'` on it (`{ code, stdout, stderr }`, or null for no answer), may
|
|
363
|
+
* run a session under a tmux older than PREFERRED_TMUX_VERSION.
|
|
364
|
+
*
|
|
365
|
+
* No only when that is known: an answer each of whose lines is a version that
|
|
366
|
+
* new or newer (an empty one is a server with no session), or a failure that
|
|
367
|
+
* says there is no server at all. Everything else — an older version, one it
|
|
368
|
+
* cannot read, a timeout, an error it does not explain — is yes, which keeps
|
|
369
|
+
* the older tmux. Pure.
|
|
370
|
+
*/
|
|
371
|
+
export function deckServerHoldsOlder(listing) {
|
|
372
|
+
if (!listing || typeof listing !== "object") return true;
|
|
373
|
+
if (listing.code !== 0) return !NO_DECK_SERVER.test(String(listing.stderr ?? ""));
|
|
374
|
+
return String(listing.stdout ?? "").split("\n").map(l => l.trim()).filter(Boolean).some((l) => {
|
|
375
|
+
const v = parseTmuxVersion(`tmux ${l}`);
|
|
376
|
+
return !v || !atLeast(v, PREFERRED_TMUX_VERSION);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Whether ccdeck's own build is worth fetching although `found` (findTmux's
|
|
382
|
+
* answer) works: a tmux 3.2–3.5 the deck chose by itself — CCDECK_TMUX unset
|
|
383
|
+
* — on Linux or macOS, while the build is not at `managed`. Once it is there,
|
|
384
|
+
* findTmux runs it instead (ownOverOlder). The status route starts the same
|
|
385
|
+
* download a machine with no tmux gets, behind its answer. `env`, `platform`,
|
|
386
|
+
* `exists` and `managed` as for tmuxCandidates. Never throws.
|
|
387
|
+
*/
|
|
388
|
+
export function ownTmuxWanted(found, {
|
|
389
|
+
env = process.env, platform = process.platform, exists = existsSync,
|
|
390
|
+
managed = managedTmuxPath(deckDataDir(platform, env)),
|
|
391
|
+
} = {}) {
|
|
392
|
+
if (platform === "win32" || found?.ok !== true || !Array.isArray(found.version)) return false;
|
|
393
|
+
if (!atLeast(found.version, MIN_TMUX_VERSION) || atLeast(found.version, PREFERRED_TMUX_VERSION)) return false;
|
|
394
|
+
if (String(env?.[TMUX_ENV] ?? "").trim() || !managed) return false;
|
|
395
|
+
try { return !exists(managed); } catch { return false; }
|
|
279
396
|
}
|
|
280
397
|
|
|
281
398
|
/** /etc/os-release, or the copy systemd keeps when /etc has none. */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,p as t}from"./app-ZMmmEHxF.js";import{u as o,a as s,f as n}from"./use-account-DvFObI4M.js";function r({appliers:u}){o(u);const{view:c}=s();return e.useEffect(()=>{t(n(c))},[c]),e.useEffect(()=>()=>t(null),[]),null}export{r as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as P,j as e,r as h,ak as Z,al as ee,g as V,t as I,am as se,h as te,an as ne,y as ae,ao as ie,s as re,ap as U,o as H,G as le,J as ce,Q as oe,R as de,k as he,aq as we}from"./app-ZMmmEHxF.js";function be({snap:s}){const a=P();return e.jsxs("section",{className:"bw-feed",children:[e.jsxs("h4",{className:"bw-sec-head bw-head-row",children:[a("settings.bw.feed"),e.jsx("span",{className:"bw-feed-count",children:a("settings.bw.feed.count",{count:s.log.length})})]}),e.jsx("p",{className:"bw-since bw-feed-note",children:a("settings.bw.feed.note")}),e.jsx("div",{className:"bw-log","aria-live":"polite","aria-relevant":"additions",children:s.log.length===0?e.jsx("p",{className:"bw-note",children:a("settings.bw.feed.empty")}):s.log.map(t=>e.jsxs("div",{className:`bw-log-line ${t.level}${t.parts?"":" sys"}`,children:[e.jsx("span",{className:"bw-log-time",children:new Date(t.atMs).toLocaleTimeString("en-GB",{hour12:!1})}),t.parts?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"bw-log-browser",children:t.parts.browser}),e.jsx("span",{className:"bw-log-profile",title:t.parts.profile,children:t.parts.profile}),e.jsxs("span",{className:"bw-log-value",children:[t.parts.value,t.parts.flagged>0&&e.jsx("span",{className:"bw-log-flag",children:a("settings.bw.feed.flagged",{count:t.parts.flagged})})]})]}):e.jsx("span",{className:"bw-log-sys",children:t.text})]},`${t.atMs}-${t.level}-${t.text}`))})]})}const D=s=>`${s.host}-${s.startMs}`;function ue(s){const a=t=>new Date(t).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1});return s.count===1||s.endMs-s.startMs<6e4?a(s.startMs):`${a(s.startMs)} → ${a(s.endMs)}`}function ge(s){return new Date(s).toLocaleDateString(V(),{weekday:"short",day:"numeric",month:"short"})}function _(s,a){const t=Math.round((s.endMs-s.startMs)/6e4);return t<1?"":a("settings.bw.findings.minutes",{n:t})}function me({snap:s,dismiss:a,refreshRef:t}){const i=P(),[l,d]=h.useState(null),o=h.useRef(new Map),n=h.useRef(null);h.useEffect(()=>{var c,u;const b=n.current;!b||s.episodes.some(g=>D(g)===b.id)||(n.current=null,Z(((c=document.activeElement)==null?void 0:c.tagName)??null)&&((u=(b.next?o.current.get(b.next):void 0)??t.current)==null||u.focus()))},[s]);const r=b=>{n.current={id:D(b),next:ee(s.episodes.map(D),D(b))},a(b)},w=h.useMemo(()=>{const b=[];for(const c of s.episodes){const u=ge(c.startMs),g=b[b.length-1];g&&g.label===u?g.episodes.push(c):b.push({label:u,episodes:[c]})}return b},[s]);return e.jsxs("section",{className:"bw-findings",children:[e.jsxs("h4",{className:"bw-sec-head bw-head-row",children:[i("settings.bw.findings"),s.episodes.length>0&&e.jsx("span",{className:"bw-feed-count",children:i("settings.bw.findings.count",{count:s.episodes.length})})]}),e.jsx("div",{className:"bw-eps",children:w.length===0?e.jsxs("div",{className:"bw-empty",children:[e.jsx("p",{className:"bw-empty-head",children:i("settings.bw.findings.none")}),e.jsx("p",{className:"bw-empty-note",children:i("settings.bw.findings.noneNote",{count:s.settings.quietMinutes})}),!s.settings.enabled&&e.jsx("p",{className:"bw-empty-note",children:i("settings.bw.findings.offNote")})]}):w.map(b=>e.jsxs("div",{className:"bw-day",children:[e.jsx("h4",{className:"bw-sec-head",children:b.label}),b.episodes.map(c=>{const u=D(c),g=l===u;return e.jsxs("div",{className:`bw-ep${g?" open":""}`,children:[e.jsxs("div",{className:"bw-ep-row",children:[e.jsxs("button",{className:"bw-ep-head",ref:p=>{p?o.current.set(u,p):o.current.delete(u)},onClick:()=>d(g?null:u),"aria-expanded":g,children:[e.jsx("span",{className:"bw-chev","aria-hidden":!0,children:g?"▾":"▸"}),e.jsx("span",{className:"bw-ep-host",children:c.host}),e.jsxs("span",{className:"bw-ep-meta",children:[ue(c),_(c,i)&&e.jsxs(e.Fragment,{children:[" · ",_(c,i)]}),c.provisional&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{title:i("settings.bw.findings.provisionalTip"),children:i("settings.bw.findings.provisional")})]})]}),e.jsx("span",{className:"bw-ep-count",children:i("settings.bw.findings.pages",{count:c.count})})]}),e.jsx("button",{className:"glyph-btn bw-ep-x",onClick:()=>r(c),"aria-label":i("settings.bw.findings.dismissHost",{host:c.host}),title:i("settings.bw.findings.dismissTip"),children:"×"})]}),g&&e.jsx("ul",{className:"bw-urls",children:c.urls.map((p,f)=>e.jsxs("li",{children:[e.jsx("span",{className:"bw-url-time",children:new Date(p.timeMs).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1})}),e.jsx("span",{className:"bw-url",children:p.url})]},`${p.url}-${p.timeMs}-${f}`))})]},u)})]},b.label))})]})}function fe(s){const a=/^#?([0-9a-f]{6})$/i.exec((s??"").trim());if(!a)return!1;const t=parseInt(a[1],16),i=[t>>16&255,t>>8&255,t&255].map(l=>{const d=l/255;return d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4)});return .2126*i[0]+.7152*i[1]+.0722*i[2]>.5}const z=1e4,xe=12e3;function pe({browsers:s,findings:a,watching:t,palette:i}){const l=P(),d=h.useRef(null),o=h.useRef(null);return o.current={browsers:s,findings:a,watching:t},h.useEffect(()=>{var g;const n=d.current;if(!n)return;const r=n.getContext("2d");if(!r)return;const w=((g=window.matchMedia)==null?void 0:g.call(window,"(prefers-reduced-motion: reduce)").matches)??!1;let b=0,c=!1;const u=()=>{var J;if(c)return;const p=o.current;if(!p)return;const{browsers:f,findings:W,watching:T}=p,m=i["--accent"]||"#7dd3fc",y=i["--line"]||"#1f2229",B=i["--text-dim"]||"#6e727c",k=fe(i["--bg"]),v=k?42:26,F=k?.85:.65,R=Date.now(),C=Math.min(window.devicePixelRatio||1,2),S=n.clientWidth,$=n.clientHeight;(n.width!==S*C||n.height!==$*C)&&(n.width=S*C,n.height=$*C),r.setTransform(C,0,0,C,0,0),r.clearRect(0,0,S,$);const x=S/2,N=$/2,M=Math.min(S,$)/2-6;r.strokeStyle=y,r.lineWidth=1,r.globalAlpha=k?1:.9;for(const j of[.4,.7,1])r.beginPath(),r.arc(x,N,M*j,0,Math.PI*2),r.stroke();r.beginPath(),r.moveTo(x-M,N),r.lineTo(x+M,N),r.moveTo(x,N-M),r.lineTo(x,N+M),r.stroke(),r.globalAlpha=1;const A=(T&&!w?R%z/z:0)*Math.PI*2-Math.PI/2;if(T){const j=(J=r.createConicGradient)==null?void 0:J.call(r,A-.85,x,N);j&&(j.addColorStop(0,"transparent"),j.addColorStop(.85/(Math.PI*2),`color-mix(in srgb, ${m} ${v}%, transparent)`),j.addColorStop(1,"transparent"),r.fillStyle=j,r.beginPath(),r.moveTo(x,N),r.arc(x,N,M,A-.85,A),r.closePath(),r.fill()),r.strokeStyle=m,r.globalAlpha=F,r.beginPath(),r.moveTo(x,N),r.lineTo(x+Math.cos(A)*M,N+Math.sin(A)*M),r.stroke(),r.globalAlpha=1}f.forEach((j,E)=>{const O=E/Math.max(f.length,1)*Math.PI*2-Math.PI/2,q=j.lastReadMs===null?1:Math.min(1,(R-j.lastReadMs)/12e4),L=M*(.42+q*.5),G=x+Math.cos(O)*L,K=N+Math.sin(O)*L,Y=Math.abs((A-O+Math.PI*3)%(Math.PI*2)-Math.PI),Q=T?Math.max(0,1-Y/.55):0;r.beginPath(),r.arc(G,K,3+Q*1.6,0,Math.PI*2),r.fillStyle=j.running?m:B,r.globalAlpha=j.running?.55+Q*.45:.35,r.fill(),r.globalAlpha=1});for(const j of W){const E=(R-j.atMs)/xe;if(E<0||E>1)continue;const q=Math.max(0,f.findIndex(K=>K.key===j.browser))/Math.max(f.length,1)*Math.PI*2-Math.PI/2,L=x+Math.cos(q)*M*.6,G=N+Math.sin(q)*M*.6;r.beginPath(),r.arc(L,G,4+E*22,0,Math.PI*2),r.strokeStyle=m,r.globalAlpha=(1-E)*.8,r.lineWidth=1.5,r.stroke(),r.globalAlpha=1}b=requestAnimationFrame(u)};return u(),()=>{c=!0,cancelAnimationFrame(b)}},[i]),e.jsx("canvas",{ref:d,className:"bw-radar",role:"img","aria-label":t?l("radar.watch.watching",{count:s.length}):l("radar.watch.idle")})}function je(s,a,t){if(s===null)return null;const i=s+a-t;return i>0?i:null}function Ne(s){const a=Math.ceil(s/1e3),t=Math.floor(a/60),i=a%60;return t>0?`${t}m ${i}s`:`${i}s`}function X(s){return(s??[]).filter(a=>a.installed&&a.profiles>0)}function ve(s,a=I){return!Number.isFinite(s)||s<=0?a("settings.bw.logEmpty"):se(s)}function ye(s,a){return s.map(t=>({key:t.key,name:t.name,running:t.running,visits:a.filter(i=>i.browser===t.key).reduce((i,l)=>i+l.programVisits,0)}))}function ke(s,a,t=I){if(s===null)return null;const i=Math.max(0,Math.round((a-s)/1e3));if(i<5)return t("settings.bw.ago.now");if(i<60)return t("settings.bw.ago.sec",{n:i});const l=Math.round(i/60);return l<60?t("settings.bw.ago.min",{n:l}):t("settings.bw.ago.hr",{n:Math.round(l/60)})}function Me(s,a=I){const t=s.profiles.filter(l=>l.degraded);if(t.length>0){const l=t[0],d=t.length-1;return{kind:"unreadable",text:a(d>0?"settings.bw.trouble.unreadableMore":"settings.bw.trouble.unreadable",{browser:l.name,profile:l.profile,reason:l.reason??a("settings.bw.trouble.noReason"),more:d})}}const i=X(s.browsers);return i.length===0?{kind:"no-profiles",text:a("settings.bw.trouble.noProfiles")}:i.some(l=>l.running)?null:{kind:"none-running",text:a("settings.bw.trouble.noneRunning")}}function Se({snap:s,watching:a,palette:t}){const i=P(),[l,d]=h.useState(!1),[o,n]=h.useState(()=>Date.now());h.useEffect(()=>{const w=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(w)},[]);const r=je(s.coverage.lastHumanMs,s.coverage.quietMs,o);return e.jsxs("section",{className:"bw-sec",children:[e.jsxs("h4",{className:"bw-sec-head",children:[i("settings.bw.overview"),e.jsx("button",{className:"bw-help",onClick:()=>d(w=>!w),"aria-expanded":l,"aria-label":i("settings.bw.overview.help"),children:"?"})]}),e.jsxs("div",{className:"bw-glance",children:[e.jsx(pe,{browsers:a.map(w=>{var b;return{key:w.key,name:w.name,running:w.running,lastReadMs:((b=s.profiles.find(c=>c.browser===w.key))==null?void 0:b.lastWrittenMs)??null}}),findings:s.episodes.slice(0,6).map(w=>({browser:w.browser??null,atMs:w.endMs})),watching:s.settings.enabled,palette:t}),e.jsx("ul",{className:"bw-counts",children:ye(a,s.profiles).map(w=>e.jsxs("li",{children:[e.jsx("span",{className:"bw-count-n",children:te(w.visits,0)}),e.jsx("span",{className:"bw-count-of",children:w.name})]},w.key))})]}),e.jsx("p",{className:"bw-since",children:i("settings.bw.overview.since")}),s.coverage.checkedMs>0&&e.jsxs("p",{className:"bw-since",children:[i("settings.bw.overview.checked",{ago:ke(s.coverage.checkedMs,o,i)??""}),s.coverage.checks>0&&e.jsxs(e.Fragment,{children:[" · ",i("settings.bw.overview.checks",{count:s.coverage.checks})]})]}),r!==null&&e.jsx("p",{className:"bw-gate",children:i("settings.bw.overview.gate",{time:Ne(r)})}),l&&e.jsxs("dl",{className:"bw-key",children:[e.jsx("dt",{children:i("settings.bw.key.sweep")}),e.jsx("dd",{children:i("settings.bw.key.sweepText")}),e.jsx("dt",{children:i("settings.bw.key.dot")}),e.jsx("dd",{children:i("settings.bw.key.dotText")}),e.jsx("dt",{children:i("settings.bw.key.ring")}),e.jsx("dd",{children:i("settings.bw.key.ringText")})]})]})}function Pe({watching:s,rest:a}){const t=P(),[i,l]=h.useState(!1),[d,o]=h.useState(!1);return e.jsxs("section",{className:"bw-sec",children:[e.jsxs("h4",{className:"bw-sec-head",children:[t("settings.bw.profiles"),e.jsx("button",{className:"bw-help",onClick:()=>l(n=>!n),"aria-expanded":i,"aria-label":t("settings.bw.profiles.help"),children:"?"})]}),i&&e.jsxs("dl",{className:"bw-key",children:[e.jsx("dt",{children:t("settings.bw.key.running")}),e.jsx("dd",{children:t("settings.bw.key.runningText")}),e.jsx("dt",{children:t("settings.bw.key.connected")}),e.jsx("dd",{children:t("settings.bw.key.connectedText")})]}),e.jsx("ul",{className:"bw-profiles",children:s.map(n=>e.jsxs("li",{children:[e.jsx("span",{className:`bw-prof-dot${n.running?" on":""}`,"aria-hidden":!0}),e.jsx("span",{className:"bw-prof-name",children:n.name}),e.jsx("span",{className:"bw-prof-state",children:n.running?t("settings.bw.running"):t("settings.bw.idle")}),n.running&&n.relay.state==="live"&&e.jsx("span",{className:"bw-relay",children:t("settings.bw.relay")})]},n.key))}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"bw-why bw-rest-head",onClick:()=>o(n=>!n),"aria-expanded":d,children:[e.jsx("span",{className:"bw-chev","aria-hidden":!0,children:d?"▾":"▸"})," ",t("settings.bw.notWatched",{count:a.length})]}),d&&e.jsx("p",{className:"bw-rest",children:t("settings.bw.notWatchedText",{names:a.map(n=>n.name).join(", ")})})]})]})}function Te({snap:s,quiet:a,setQuiet:t,save:i,access:l,setAccess:d}){const o=P();return e.jsxs("div",{className:"bw-settings",children:[e.jsxs("label",{title:o("settings.bw.quiet.tip"),children:[e.jsx("span",{children:o("settings.bw.quiet.label")}),e.jsx("select",{value:a??s.settings.quietMinutes,onChange:n=>{t(Number(n.target.value)),i({quietMinutes:Number(n.target.value)})},children:[1,5,15,30,60].map(n=>e.jsx("option",{value:n,children:o("settings.bw.minutes",{n})},n))})]}),e.jsxs("label",{children:[e.jsx("span",{children:o("settings.bw.reaction.label")}),e.jsx("select",{value:s.settings.reaction,onChange:n=>void i({reaction:n.target.value}),disabled:!s.settings.enabled,title:s.settings.enabled?o("settings.bw.reaction.hintOn"):o("settings.bw.reaction.hintOff"),children:(s.reactions??["notify"]).map(n=>e.jsx("option",{value:n,children:o(n==="notify"?"settings.bw.reaction.notify":n==="close-tab"?"settings.bw.reaction.closeTab":"settings.bw.reaction.quit")},n))})]}),e.jsxs("div",{className:"bw-settings-note",children:[e.jsxs("p",{children:[o("settings.bw.note.chrome")," ",e.jsx("strong",{children:o("settings.bw.note.usually")})]}),e.jsxs("button",{className:"bw-why",onClick:()=>d(n=>!n),"aria-expanded":l,children:[e.jsx("span",{className:"bw-chev","aria-hidden":!0,children:l?"▾":"▸"})," ",o("settings.bw.access.toggle")]}),l&&e.jsxs("dl",{className:"bw-access",children:[e.jsx("dt",{children:o("settings.bw.access.reads")}),e.jsx("dd",{children:o("settings.bw.access.readsText",{when:new Date(s.coverage.startedMs).toLocaleString(V())})}),e.jsx("dt",{children:o("settings.bw.access.keeps")}),e.jsx("dd",{children:ne(o("settings.bw.access.keepsText",{path:"{path}",size:typeof s.coverage.logBytes=="number"?` (${ve(s.coverage.logBytes)})`:""}),{path:e.jsx("code",{className:"bw-path",children:s.coverage.logPath})})}),e.jsx("dt",{children:o("settings.bw.access.sends")}),e.jsx("dd",{children:o("settings.bw.access.sendsText")}),e.jsx("dt",{children:o("settings.bw.access.never")}),e.jsx("dd",{children:o("settings.bw.access.neverText")})]})]})]})}function Ce(s,a,t){return a?{kind:"saving",word:t("settings.bw.mode.saving")}:s.settings.enabled?{kind:"on",word:t("settings.bw.mode.watching")}:{kind:"off",word:t("settings.bw.mode.paused")}}function Re({snap:s,saving:a,save:t,why:i,setWhy:l}){const d=P(),o=Ce(s,a,d);return e.jsxs("footer",{className:"bw-status",children:[e.jsx("span",{className:`bw-mode-dot${s.settings.enabled?" on":""}`,"aria-hidden":!0}),e.jsx("span",{className:"bw-mode-word",children:o.word},o.kind),e.jsx("span",{className:"bw-status-text",children:s.coverage.archived===0?s.settings.enabled?d("settings.bw.disk.none"):d("settings.bw.disk.noneOff"):d("settings.bw.disk.some",{count:s.coverage.archived})}),e.jsx("button",{className:`glyph-btn bw-gear${i?" on":""}`,onClick:()=>l(n=>!n),"aria-expanded":i,"aria-label":d("settings.bw.settings"),title:d("settings.bw.settings"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3","aria-hidden":!0,children:[e.jsx("circle",{cx:"7",cy:"7",r:"2.1"}),e.jsx("path",{d:"M7 1.2v1.6M7 11.2v1.6M1.2 7h1.6M11.2 7h1.6M2.9 2.9l1.1 1.1M10 10l1.1 1.1M11.1 2.9L10 4M4 10l-1.1 1.1"})]})}),e.jsxs("label",{className:"bw-switch",htmlFor:"bw-enabled",children:[e.jsx("span",{className:"bw-switch-label",id:"bw-enabled-label",children:d("settings.bw.switch")}),e.jsx("button",{id:"bw-enabled",type:"button",role:"switch","aria-checked":s.settings.enabled,"aria-labelledby":"bw-enabled-label",className:"switch",onClick:()=>void t({enabled:!s.settings.enabled}),title:s.settings.enabled?d("settings.bw.switch.on"):d("settings.bw.switch.off"),children:e.jsx("span",{className:"switch-knob"})})]})]})}function $e({relay:s}){const a=P(),[t,i]=h.useState(!1),[l,d]=h.useState(!1),o=s.killswitch.blocked?"unblock":"block",n=s.command[o],r=h.useCallback(async()=>{await ae(n.command)&&(d(!0),window.setTimeout(()=>d(!1),1600))},[n.command]),w=s.profiles.filter(c=>{var u;return(u=c.report)==null?void 0:u.present}),b=s.profiles.filter(c=>c.report===null);return e.jsxs("section",{className:"bw-sec",children:[e.jsx("h4",{className:"bw-sec-head",children:a("shell.remote.title")}),e.jsx("p",{className:`bw-rc-verdict ${s.verdict}`,role:"status",children:s.verdict==="exposed"?a("shell.remote.exposed"):s.verdict==="protected"?a("shell.remote.protected",{path:s.hostsPath}):a("shell.remote.nothing")}),s.killswitch.foreign.length>0&&e.jsxs("p",{className:"bw-rc-foreign",children:[a("shell.remote.foreign",{path:s.hostsPath}),s.killswitch.foreign.map(c=>e.jsx("code",{className:"bw-path",children:c},c))]}),e.jsxs("button",{className:"bw-why",onClick:()=>i(c=>!c),"aria-expanded":t,children:[e.jsx("span",{className:"bw-chev","aria-hidden":!0,children:t?"▾":"▸"})," ",s.verdict==="protected"?a("shell.remote.undo"):a("shell.remote.reach")]}),t&&e.jsxs("div",{className:"bw-rc-body",children:[w.length>0&&e.jsx("dl",{className:"bw-key",children:w.map(c=>e.jsxs(h.Fragment,{children:[e.jsxs("dt",{children:[c.name,c.profile==="Default"?"":` · ${c.profile}`]}),e.jsxs("dd",{children:[a("shell.remote.detail",{state:c.report.enabled?a("shell.remote.enabled"):a("shell.remote.switchedOff"),scope:c.report.allUrls?a("shell.remote.allSites"):a("shell.remote.limited")}),c.report.sensitiveApis.length>0&&e.jsxs(e.Fragment,{children:[" — ",c.report.sensitiveApis.join(", ")]})]})]},`${c.browser}/${c.profile}`))}),b.length>0&&e.jsx("p",{className:"bw-rc-note",children:a("shell.remote.unreadable",{names:b.map(c=>c.name).join(", ")})}),!s.hostsRead&&e.jsx("p",{className:"bw-rc-note",children:a("shell.remote.hostsUnread",{path:s.hostsPath})}),w.some(c=>c.report.allUrls)&&e.jsx("p",{className:"bw-rc-note",children:ie(a("shell.remote.narrow"),"code",e.jsx("code",{className:"bw-path",children:"chrome://extensions"}))}),e.jsxs("div",{className:"bw-rc-cmd",children:[e.jsx("code",{children:n.command}),e.jsx("button",{className:"btn bw-rc-copy",onClick:r,children:a(l?"shell.copied":"shell.copy")})]}),e.jsx("p",{className:"bw-rc-note",children:n.note})]})]})}function Ie(s){const[a,t]=h.useState(null),[i,l]=h.useState(null),[d,o]=h.useState(null),[n,r]=h.useState(!1),w=h.useRef(!1),[b,c]=h.useState(null),[u,g]=h.useState(!1),p=h.useRef(!1),f=h.useCallback(async m=>{var y,B;if(!(m&&!re(w.current))){m&&(w.current=!0,r(!0));try{const k=await fetch(`/api/browser-watch${m?"?refresh=1":""}`);if(!k.ok)throw new U(I("settings.bw.deckAnswered",{status:k.status}));const v=await k.json();t(v),p.current||c(((y=v==null?void 0:v.settings)==null?void 0:y.quietMinutes)??15),s(((B=v==null?void 0:v.settings)==null?void 0:B.enabled)===!0),l(null)}catch(k){l(H(k,I("settings.bw.noAnswer")))}finally{m&&(w.current=!1,r(!1))}}},[s]);h.useEffect(()=>{f(!1)},[f]),h.useEffect(()=>{const m=setInterval(()=>{f(!1)},1e4);return()=>clearInterval(m)},[f]);const W=h.useCallback(async m=>{try{await fetch("/api/browser-watch/dismiss",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({host:m.host,startMs:m.startMs})})}finally{await f(!1)}},[f]),T=h.useCallback(async m=>{p.current=!0,g(!0);try{const y=await fetch("/api/browser-watch",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(m)});if(!y.ok)throw new U(I("settings.bw.deckAnswered",{status:y.status}));await f(!1),o(null)}catch(y){o(H(y,I("settings.bw.noAnswer")))}finally{p.current=!1,g(!1)}},[f]);return{snap:a,error:i,writeError:d,setWriteError:o,busy:n,quiet:b,setQuiet:c,saving:u,load:f,dismiss:W,save:T}}function Ee({onClose:s,onSeen:a,onWatching:t,palette:i}){const l=P(),d=le(s),o=ce(s),{snap:n,error:r,writeError:w,setWriteError:b,busy:c,quiet:u,setQuiet:g,saving:p,load:f,dismiss:W,save:T}=Ie(t),[m,y]=h.useState(!1),[B,k]=h.useState(!1),v=h.useRef(null),F=h.useRef(a);F.current=a,h.useEffect(()=>()=>F.current(Date.now()),[]);const R=X(n==null?void 0:n.browsers),C=((n==null?void 0:n.browsers)??[]).filter(x=>!(x.installed&&x.profiles>0)),S=n?Me(n,l):null,$=R.reduce((x,N)=>x+N.profiles,0);return e.jsxs(oe,{scrim:o,dialogRef:d,className:"bw-modal",labelledBy:"bw-title",children:[e.jsxs("header",{className:"modal-head",children:[e.jsxs("div",{className:"modal-title",children:[e.jsx("span",{className:"modal-tool-name",id:"bw-title",children:l("settings.bw.title")}),e.jsx("span",{className:"modal-tool-id",children:n?l("settings.bw.scope.profiles",{count:$}):l("settings.bw.scope.localOnly")})]}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{ref:v,className:"glyph-btn",onClick:()=>void f(!0),...he(c),"aria-label":l("settings.bw.reread"),title:l("settings.bw.reread"),children:e.jsx(de,{})}),e.jsx(we,{onClick:s,label:l("settings.bw.close")})]})]}),e.jsxs("div",{className:"modal-body bw-body",children:[!n&&!r&&e.jsxs("div",{className:"bw-loading",children:[e.jsx("span",{className:"bw-loading-bar","aria-hidden":!0}),e.jsx("p",{children:l("settings.bw.loading")})]}),r&&e.jsx("div",{className:"bw-state",children:e.jsxs("div",{className:"bw-row err",children:[e.jsx("span",{className:"bw-dot","aria-hidden":!0}),e.jsx("span",{className:"bw-row-label",children:l("settings.bw.readFail")}),e.jsx("span",{className:"bw-row-detail",children:r})]})}),n&&S&&e.jsx("p",{className:`bw-trouble ${S.kind}`,role:"status",children:S.text}),n&&e.jsxs("div",{className:"bw-work",children:[e.jsxs("aside",{className:"bw-side",children:[e.jsx(Se,{snap:n,watching:R,palette:i}),e.jsx(Pe,{watching:R,rest:C}),n.relay&&e.jsx($e,{relay:n.relay})]}),e.jsxs("div",{className:"bw-main",children:[e.jsx(me,{snap:n,dismiss:W,refreshRef:v}),e.jsx(be,{snap:n})]})]}),n&&m&&e.jsx(Te,{snap:n,quiet:u,setQuiet:g,save:T,access:B,setAccess:k}),w&&e.jsx("div",{className:"bw-state bw-write-err",role:"alert",children:e.jsxs("div",{className:"bw-row err",children:[e.jsx("span",{className:"bw-dot","aria-hidden":!0}),e.jsx("span",{className:"bw-row-label",children:l("settings.bw.saveFail")}),e.jsx("span",{className:"bw-row-detail",children:l("settings.bw.saveFailDetail",{error:w})}),e.jsx("button",{className:"glyph-btn bw-write-err-x",onClick:()=>b(null),"aria-label":l("settings.bw.dismiss"),title:l("settings.bw.dismiss"),children:"×"})]})}),n&&e.jsx(Re,{snap:n,saving:p,save:T,why:m,setWhy:y})]})]})}export{Ee as default};
|