dsh-builtin-browser 0.5.6 → 0.5.8
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/CHANGELOG.md +148 -0
- package/README.en.md +75 -81
- package/README.md +75 -82
- package/client.js +831 -384
- package/desktop-bridge/install-and-start.cmd +4 -5
- package/desktop-bridge/install.mjs +322 -141
- package/desktop-bridge/maintenance-progress.ps1 +166 -0
- package/desktop-bridge/plugin-browser-bridge.js +157 -19
- package/desktop-bridge/request-desktop-quit.ps1 +170 -0
- package/docs/tool-reference.md +20 -1
- package/docs/user-guide.md +28 -4
- package/lib/browser/runtime.d.ts +3 -1
- package/lib/browser/runtime.js +9 -0
- package/lib/browser/types.d.ts +42 -0
- package/lib/browser-electron/authenticated-route.d.ts +27 -0
- package/lib/browser-electron/authenticated-route.js +39 -0
- package/lib/browser-electron/automatic-maintenance.d.ts +41 -0
- package/lib/browser-electron/automatic-maintenance.js +426 -0
- package/lib/browser-electron/bridge-auto.d.ts +93 -0
- package/lib/browser-electron/bridge-auto.js +113 -0
- package/lib/browser-electron/bridge-connection.d.ts +0 -2
- package/lib/browser-electron/bridge-connection.js +2 -4
- package/lib/browser-electron/bridge-endpoint.js +8 -19
- package/lib/browser-electron/bridge-install.d.ts +85 -0
- package/lib/browser-electron/bridge-install.js +211 -0
- package/lib/browser-electron/bridge-maintenance.d.ts +24 -0
- package/lib/browser-electron/bridge-maintenance.js +125 -0
- package/lib/browser-electron/bridge-status.d.ts +10 -3
- package/lib/browser-electron/bridge-status.js +74 -24
- package/lib/browser-electron/desktop-bridge-host.d.ts +11 -5
- package/lib/browser-electron/desktop-bridge-host.js +67 -25
- package/lib/browser-electron/desktop-identity.js +21 -9
- package/lib/browser-electron/electron-provision.d.ts +1 -1
- package/lib/browser-electron/electron-provision.js +36 -13
- package/lib/browser-electron/entry.js +173 -67
- package/lib/browser-electron/ephemeral-profile.js +67 -26
- package/lib/browser-electron/history-store.js +2 -2
- package/lib/browser-electron/host-main.js +48 -38
- package/lib/browser-electron/http-body.d.ts +24 -0
- package/lib/browser-electron/http-body.js +33 -0
- package/lib/browser-electron/json-reply.d.ts +13 -1
- package/lib/browser-electron/json-reply.js +16 -2
- package/lib/browser-electron/maintenance-broker.d.ts +35 -0
- package/lib/browser-electron/maintenance-broker.js +114 -0
- package/lib/browser-electron/maintenance-lifecycle.d.ts +32 -0
- package/lib/browser-electron/maintenance-lifecycle.js +67 -0
- package/lib/browser-electron/maintenance-route.d.ts +18 -0
- package/lib/browser-electron/maintenance-route.js +75 -0
- package/lib/browser-electron/paths.d.ts +4 -0
- package/lib/browser-electron/paths.js +19 -0
- package/lib/browser-electron/process.d.ts +14 -0
- package/lib/browser-electron/process.js +24 -0
- package/lib/browser-electron/provider.d.ts +16 -9
- package/lib/browser-electron/provider.js +87 -18
- package/lib/browser-electron/remote-host.js +22 -20
- package/lib/browser-electron/runtime-route.d.ts +3 -5
- package/lib/browser-electron/runtime-status.d.ts +27 -13
- package/lib/browser-electron/runtime-status.js +28 -6
- package/lib/browser-electron/settings-route.d.ts +5 -18
- package/lib/browser-electron/settings-route.js +4 -14
- package/lib/browser-electron/settings-store.d.ts +28 -0
- package/lib/browser-electron/settings-store.js +32 -2
- package/lib/browser-electron/sidebar-only-host.d.ts +36 -0
- package/lib/browser-electron/sidebar-only-host.js +192 -0
- package/lib/browser-electron/system-browser.d.ts +6 -11
- package/lib/browser-electron/system-browser.js +29 -24
- package/lib/browser-electron/timing.d.ts +8 -0
- package/lib/browser-electron/timing.js +13 -0
- package/lib/browser-electron/windows-system.d.ts +3 -0
- package/lib/browser-electron/windows-system.js +19 -0
- package/lib/tool-browser/index.js +1045 -7
- package/lib/tool-browser/page-probe.d.ts +86 -0
- package/lib/tool-browser/page-probe.js +460 -0
- package/package.json +5 -3
- package/scripts/run-tests.mjs +32 -0
- package/scripts/verify-preview-route.mjs +19 -1
- package/scripts/verify-runtime-status.mjs +14 -0
- package/skills/dsh-builtin-browser/SKILL.md +64 -0
- package/skills/dsh-builtin-browser/references/batch.md +23 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- package/src/browser/runtime.ts +11 -0
- package/src/browser/types.ts +19 -0
- package/src/browser-electron/authenticated-route.ts +56 -0
- package/src/browser-electron/automatic-maintenance.ts +414 -0
- package/src/browser-electron/bridge-auto.ts +158 -0
- package/src/browser-electron/bridge-connection.ts +2 -4
- package/src/browser-electron/bridge-endpoint.ts +8 -18
- package/src/browser-electron/bridge-install.ts +253 -0
- package/src/browser-electron/bridge-maintenance.ts +161 -0
- package/src/browser-electron/bridge-status.ts +76 -26
- package/src/browser-electron/desktop-bridge-host.ts +60 -26
- package/src/browser-electron/desktop-identity.ts +18 -9
- package/src/browser-electron/electron-provision.ts +35 -14
- package/src/browser-electron/entry.ts +152 -62
- package/src/browser-electron/ephemeral-profile.ts +65 -28
- package/src/browser-electron/history-store.ts +2 -2
- package/src/browser-electron/host-main.ts +40 -34
- package/src/browser-electron/http-body.ts +42 -0
- package/src/browser-electron/json-reply.ts +18 -3
- package/src/browser-electron/maintenance-broker.ts +142 -0
- package/src/browser-electron/maintenance-lifecycle.ts +86 -0
- package/src/browser-electron/maintenance-route.ts +64 -0
- package/src/browser-electron/paths.ts +21 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/provider.ts +106 -22
- package/src/browser-electron/remote-host.ts +23 -23
- package/src/browser-electron/runtime-route.ts +3 -5
- package/src/browser-electron/runtime-status.ts +56 -19
- package/src/browser-electron/settings-route.ts +9 -32
- package/src/browser-electron/settings-store.ts +59 -3
- package/src/browser-electron/sidebar-only-host.ts +199 -0
- package/src/browser-electron/system-browser.ts +26 -23
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/windows-system.ts +23 -0
- package/src/tool-browser/index.ts +995 -10
- package/src/tool-browser/page-probe.ts +474 -0
package/client.js
CHANGED
|
@@ -26,6 +26,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
26
26
|
const NS = "settings.dsh-builtin-browser"
|
|
27
27
|
const ROUTE = "/dsh-builtin-browser/settings"
|
|
28
28
|
let translate = (key) => key
|
|
29
|
+
let currentLocale = "zh"
|
|
30
|
+
function updateCurrentLocale(locale) {
|
|
31
|
+
let active
|
|
32
|
+
try { active = locale.getSnapshot?.().active ?? locale.getLocale?.().active } catch { /* Older hosts may only expose bind. */ }
|
|
33
|
+
const language = typeof active === "string" ? active : typeof document === "undefined" ? "" : document.documentElement?.lang
|
|
34
|
+
currentLocale = typeof language === "string" && /^en(?:-|$)/i.test(language) ? "en" : "zh"
|
|
35
|
+
}
|
|
29
36
|
/**
|
|
30
37
|
* Re-evaluate the floating watch entry.
|
|
31
38
|
*
|
|
@@ -46,6 +53,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
46
53
|
nav: "浏览器",
|
|
47
54
|
"watch.open": "观看浏览器",
|
|
48
55
|
"watch.title": "实时画面",
|
|
56
|
+
"watch.session": "选择会话",
|
|
49
57
|
"watch.readOnly": "只读,不转发点击与输入",
|
|
50
58
|
"watch.stop": "停止",
|
|
51
59
|
"watch.live": "直播",
|
|
@@ -57,76 +65,82 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
57
65
|
"watch.noPage": "该任务尚未打开浏览器",
|
|
58
66
|
"watch.bridgeStale": "桌面端升级后 bridge 已失效,请重跑安装:",
|
|
59
67
|
"watch.bridgeMissing": "桌面 bridge 未安装,侧栏载体不可用。安装命令:",
|
|
60
|
-
title: "浏览器
|
|
61
|
-
|
|
68
|
+
title: "浏览器",
|
|
69
|
+
"settings.advanced": "高级设置",
|
|
70
|
+
"settings.saving": "正在保存…",
|
|
71
|
+
"settings.details": "配置文件",
|
|
72
|
+
"browser.profile": "保留登录状态",
|
|
73
|
+
"browser.profile.hint": "重启 DSH 后生效",
|
|
74
|
+
"browser.headless": "窗口模式",
|
|
75
|
+
"browser.headless.hint": "重启 DSH 后生效",
|
|
76
|
+
"browser.headless.auto": "自动检测显示环境",
|
|
77
|
+
"browser.headless.windowed": "显示窗口",
|
|
78
|
+
"browser.headless.headless": "无头运行",
|
|
79
|
+
"delivery.save": "保存交付设置",
|
|
80
|
+
"delivery.invalid": "检查工具名、参数模板和站点规则。参数必须是字符串值的 JSON 对象,站点规则每行填写一个 host=工具名。",
|
|
62
81
|
loading: "读取设置…",
|
|
63
82
|
failed: "读取设置失败:",
|
|
64
83
|
retry: "重试",
|
|
65
84
|
saved: "已保存",
|
|
66
|
-
path: "设置文件",
|
|
67
|
-
"history.title": "浏览历史",
|
|
68
85
|
"history.enabled": "保留浏览历史",
|
|
69
|
-
"history.hint": "记录访问过的页面;关闭浏览器后仍可查询并重新打开,关闭此开关后不再记录新访问。",
|
|
70
|
-
"cookies.title": "登录状态",
|
|
71
|
-
"cookies.persist": "保留 cookies",
|
|
72
|
-
"cookies.hint": "仅控制本机 Chrome / Edge 的独立 profile:关闭后下次启动使用临时 profile;需重新选择载体或重启 DSH。内置 Electron 与桌面侧栏的登录态由各自载体保存。",
|
|
73
86
|
"ui.title": "展示",
|
|
74
87
|
"ui.autoExpandOnce": "侧栏自动展开(每轮一次)",
|
|
75
|
-
"ui.autoExpandOnce.hint": "Agent 首次操作时自动展开;你手动收起后,本轮不再打扰。",
|
|
76
88
|
"ui.closeWithSession": "会话结束时关闭浏览器",
|
|
77
|
-
"ui.
|
|
78
|
-
"ui.virtualCursor": "显示可视化鼠标",
|
|
79
|
-
"ui.virtualCursor.hint": "让 Agent 正在操作的位置可见(出现即代表它在接管该标签页)。",
|
|
89
|
+
"ui.virtualCursor": "显示 Agent 光标",
|
|
80
90
|
"ui.quiet": "安静模式",
|
|
81
|
-
"ui.quiet.hint": "
|
|
82
|
-
"vision.
|
|
83
|
-
"vision.
|
|
84
|
-
"vision.
|
|
85
|
-
"vision.nonVisual": "纯非视觉(拒绝坐标点击,只用 DOM / 无障碍树定位)",
|
|
86
|
-
"vision.hint": "纯非视觉下,坐标点击会被明确拒绝并提示改用语义定位,避免靠猜坐标点错。两种策略下 DOM、无障碍树、文本提取与结构化抓取的能力完全一致 —— 不需要图像输入也能完整操作页面。",
|
|
87
|
-
"credentials.title": "凭据",
|
|
91
|
+
"ui.quiet.hint": "保留当前窗口和标签。新启动的 Chrome / Edge 在后台运行。",
|
|
92
|
+
"vision.strategy": "坐标点击与拖拽",
|
|
93
|
+
"vision.auto": "允许",
|
|
94
|
+
"vision.nonVisual": "禁止",
|
|
88
95
|
"credentials.allowRead": "允许 Agent 读取 cookies / 导出登录状态",
|
|
89
|
-
"browser.
|
|
90
|
-
"browser.
|
|
91
|
-
"browser.
|
|
92
|
-
"browser.bundled": "内置 Electron(随插件提供,无需安装)",
|
|
96
|
+
"browser.channel": "默认浏览器",
|
|
97
|
+
"browser.sidebar": "DSH 侧栏",
|
|
98
|
+
"browser.bundled": "内置浏览器",
|
|
93
99
|
"browser.chrome": "本机 Chrome",
|
|
94
100
|
"browser.edge": "本机 Edge",
|
|
95
|
-
"browser.auto": "自动
|
|
96
|
-
"
|
|
97
|
-
"credentials.hint": "关闭后 dsh_browser_auth 的导出会被拒绝,报 BROWSER_AUTH_DISABLED —— 导出读的是整台机器共享的 cookie 罐(按当前页所属站点收敛)。它只管**读**:写入登录状态(restore)归下面「Agent 能做什么」里的写入开关。桌面端请注意:Agent 驱动的是侧栏里那一个页面(人机同页),因此它与该页面共用同一个 partition —— 这也正是它能读到登录态的原因,属于有意接受的沙箱边界变化;关闭本项即拒绝读取。",
|
|
98
|
-
"actions.title": "Agent 能做什么",
|
|
99
|
-
"actions.lead": "与 dsh_browser_restrict 不同:那一层是模型自己设的软护栏,它随时可以解除;这里的三项由你在设置里决定,模型手里的工具改不了它们。",
|
|
101
|
+
"browser.auto": "自动",
|
|
102
|
+
"actions.title": "Agent 权限",
|
|
100
103
|
"actions.allowExecute": "允许在页面里执行脚本",
|
|
101
|
-
"actions.allowExecute.hint": "dsh_browser_execute 能在当前页面里运行任意 JavaScript —— 它的能力上限就是这个页面能做的事。关闭后该工具一律被拒(BROWSER_EXECUTE_DISABLED),模型手里的工具没有一个能改这项设置。但也别把它当成锁:设置文档由本机 HTTP 端点读写,同源页面可以写它 —— 这不是凭据系统。",
|
|
102
104
|
"actions.allowDownload": "允许下载文件到磁盘",
|
|
103
|
-
"actions.allowDownload.hint": "dsh_browser_download 会把 URL 下载到 downloadDir 内(带登录态;仍需通过目录准入,不覆盖已有文件)。关闭后一律被拒(BROWSER_DOWNLOAD_DISABLED)。截图另存走的是同一套目录准入,不受此项影响。",
|
|
104
105
|
"actions.allowCredentialWrite": "允许写入登录状态",
|
|
105
|
-
"actions.allowCredentialWrite.hint": "
|
|
106
|
-
"remoteView.
|
|
107
|
-
"remoteView.enabled": "
|
|
108
|
-
"
|
|
109
|
-
"readiness.title": "就绪状态",
|
|
110
|
-
"readiness.lead": "「装好就能用」的自检:内置浏览器首次使用前要在后台下载一次运行时,桌面侧栏需要装进桌面端的 bridge,本机 Chrome / Edge 需要已经安装。",
|
|
106
|
+
"actions.allowCredentialWrite.hint": "可向任意域写入 cookies。",
|
|
107
|
+
"remoteView.enabled": "允许远程观看",
|
|
108
|
+
"remoteView.enabled.hint": "共享只读画面,可能包含敏感信息。",
|
|
109
|
+
"readiness.title": "环境检查",
|
|
111
110
|
"readiness.loading": "检测中…",
|
|
112
111
|
"readiness.failed": "读取就绪状态失败:",
|
|
113
|
-
"readiness.channel": "
|
|
112
|
+
"readiness.channel": "配置的载体",
|
|
113
|
+
"readiness.resolvedCarrier": "当前载体",
|
|
114
|
+
"readiness.system": "本机浏览器",
|
|
115
|
+
"readiness.details": "诊断",
|
|
114
116
|
"readiness.electron": "内置浏览器运行时",
|
|
115
117
|
"readiness.bridge": "桌面侧栏 bridge",
|
|
116
118
|
"readiness.recheck": "重新检测",
|
|
117
119
|
"readiness.prepare": "准备内置浏览器",
|
|
118
120
|
"readiness.preparing": "正在准备…",
|
|
119
|
-
"readiness.fix": "
|
|
121
|
+
"readiness.fix": "外部终端命令",
|
|
120
122
|
"readiness.carrier.sidebar": "桌面侧栏",
|
|
121
123
|
"readiness.carrier.bundled": "内置 Electron",
|
|
122
124
|
"readiness.carrier.system": "本机 Chrome / Edge",
|
|
123
125
|
"readiness.carrier.auto": "自动",
|
|
124
126
|
"readiness.state.ready": "可用",
|
|
125
127
|
"readiness.state.blocked": "尚不可用",
|
|
126
|
-
"readiness.
|
|
127
|
-
"readiness.
|
|
128
|
-
"readiness.
|
|
129
|
-
"readiness.
|
|
128
|
+
"readiness.status.checkPending": "等待环境检测",
|
|
129
|
+
"readiness.status.systemReady": "已找到 {browser}",
|
|
130
|
+
"readiness.status.systemMissing": "未找到 {browser}",
|
|
131
|
+
"readiness.status.bundledReady": "内置运行环境可用",
|
|
132
|
+
"readiness.status.bundledMissing": "内置运行环境待安装",
|
|
133
|
+
"readiness.status.bundledPreparing": "正在下载内置运行环境",
|
|
134
|
+
"readiness.status.bundledFailed": "内置运行环境准备失败",
|
|
135
|
+
"readiness.status.bridgeReady": "侧栏桥可用",
|
|
136
|
+
"readiness.status.bridgeMissing": "侧栏桥待安装",
|
|
137
|
+
"readiness.status.bridgeStale": "侧栏桥待修复",
|
|
138
|
+
"readiness.status.bridgeStopped": "等待桌面端启动",
|
|
139
|
+
"readiness.status.bridgeInstalled": "侧栏桥已安装",
|
|
140
|
+
"readiness.status.desktopMissing": "未检测到桌面端",
|
|
141
|
+
"readiness.electron.present": "已就绪",
|
|
142
|
+
"readiness.electron.ready": "已就绪",
|
|
143
|
+
"readiness.electron.preparing": "正在下载",
|
|
130
144
|
"readiness.electron.idle": "尚未开始准备",
|
|
131
145
|
"readiness.electron.skipped": "已跳过(设置了 ELECTRON_SKIP_BINARY_DOWNLOAD)",
|
|
132
146
|
"readiness.electron.failed": "准备失败",
|
|
@@ -136,16 +150,42 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
136
150
|
"readiness.bridge.missing": "未安装",
|
|
137
151
|
"readiness.bridge.stale": "已失效(桌面端升级后需重装)",
|
|
138
152
|
"readiness.bridge.absent": "本机没有桌面端",
|
|
139
|
-
"readiness.
|
|
140
|
-
"readiness.
|
|
141
|
-
"readiness.
|
|
142
|
-
"readiness.
|
|
153
|
+
"readiness.bridge.install": "安装并重启",
|
|
154
|
+
"readiness.bridge.repair": "修复并重启",
|
|
155
|
+
"readiness.bridge.reinstall": "重装并重启",
|
|
156
|
+
"readiness.bridge.uninstall": "卸载并重启",
|
|
157
|
+
"readiness.bridge.working": "正在准备维护…",
|
|
158
|
+
"readiness.bridge.inProgress": "维护进行中…",
|
|
159
|
+
"readiness.bridge.maintenanceHint": "点击后将正常退出并重启 DSH。",
|
|
160
|
+
"readiness.bridge.progressHint": "维护期间将显示独立进度,完成后自动启动 DSH。",
|
|
161
|
+
"readiness.bridge.localOnly": "请在本机 DSH 桌面的设置中操作。",
|
|
162
|
+
"readiness.bridge.unsupported": "请更新并重启 DSH 后重试。",
|
|
163
|
+
"readiness.bridge.phase.armed": "正在准备退出 DSH…",
|
|
164
|
+
"readiness.bridge.phase.closing": "正在正常退出 DSH…",
|
|
165
|
+
"readiness.bridge.phase.installing": "正在安装桥接…",
|
|
166
|
+
"readiness.bridge.phase.uninstalling": "正在卸载桥接…",
|
|
167
|
+
"readiness.bridge.phase.restarting": "正在重启 DSH…",
|
|
168
|
+
"readiness.bridge.phase.verifying": "正在确认桥接状态…",
|
|
169
|
+
"readiness.bridge.failed": "桥接维护失败,请查看诊断后重试。",
|
|
170
|
+
"readiness.bridge.cancelled": "桥接维护已取消,可重试。",
|
|
171
|
+
"readiness.bridge.installedDone": "桥接安装完成",
|
|
172
|
+
"readiness.bridge.uninstalledDone": "桥接已卸载",
|
|
173
|
+
"readiness.bridge.actionFailed": "桥接维护未能开始,请查看诊断后重试。",
|
|
174
|
+
"delivery.title": "交付",
|
|
175
|
+
"delivery.tool": "接手下载的工具(MCP 工具名,留空=只存本地)",
|
|
176
|
+
"delivery.args": "参数模板(JSON)",
|
|
177
|
+
"delivery.args.hint": "占位 {path} {name} {size}。",
|
|
178
|
+
"delivery.onFail": "远程失败时",
|
|
179
|
+
"delivery.onFail.keep": "保留本地文件并报告两边结果",
|
|
180
|
+
"delivery.onFail.stop": "按失败处理",
|
|
181
|
+
"delivery.sites": "按站点覆盖(每行 host=工具名)",
|
|
143
182
|
}
|
|
144
183
|
|
|
145
184
|
const en = {
|
|
146
185
|
nav: "Browser",
|
|
147
186
|
"watch.open": "Watch browser",
|
|
148
187
|
"watch.title": "Live view",
|
|
188
|
+
"watch.session": "Session",
|
|
149
189
|
"watch.readOnly": "Read-only; clicks and typing are not forwarded",
|
|
150
190
|
"watch.stop": "Stop",
|
|
151
191
|
"watch.live": "Live",
|
|
@@ -157,76 +197,82 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
157
197
|
"watch.noPage": "This task has not opened a browser",
|
|
158
198
|
"watch.bridgeStale": "A desktop update invalidated the bridge; re-run:",
|
|
159
199
|
"watch.bridgeMissing": "The desktop bridge is not installed, so the sidebar carrier cannot work:",
|
|
160
|
-
title: "Browser
|
|
161
|
-
|
|
200
|
+
title: "Browser",
|
|
201
|
+
"settings.advanced": "Advanced settings",
|
|
202
|
+
"settings.saving": "Saving…",
|
|
203
|
+
"settings.details": "Configuration file",
|
|
204
|
+
"browser.profile": "Keep sign-ins",
|
|
205
|
+
"browser.profile.hint": "Requires restarting DSH",
|
|
206
|
+
"browser.headless": "Window mode",
|
|
207
|
+
"browser.headless.hint": "Requires restarting DSH",
|
|
208
|
+
"browser.headless.auto": "Detect display automatically",
|
|
209
|
+
"browser.headless.windowed": "Show a window",
|
|
210
|
+
"browser.headless.headless": "Run headless",
|
|
211
|
+
"delivery.save": "Save delivery settings",
|
|
212
|
+
"delivery.invalid": "Check tool names, the argument template, and site rules. Use a JSON object with string values and one host=tool rule per line.",
|
|
162
213
|
loading: "Loading settings…",
|
|
163
214
|
failed: "Could not load settings:",
|
|
164
215
|
retry: "Retry",
|
|
165
216
|
saved: "Saved",
|
|
166
|
-
path: "Settings file",
|
|
167
|
-
"history.title": "Browsing history",
|
|
168
217
|
"history.enabled": "Keep browsing history",
|
|
169
|
-
"history.hint": "Records visited pages so they can be found and reopened after the browser is closed; off means no new visits are recorded.",
|
|
170
|
-
"cookies.title": "Login state",
|
|
171
|
-
"cookies.persist": "Keep cookies",
|
|
172
|
-
"cookies.hint": "Controls only the separate Chrome / Edge profile: off uses a temporary profile on the next launch. Reselect the carrier or restart DSH. Bundled Electron and the desktop sidebar retain login state through their own carrier.",
|
|
173
218
|
"ui.title": "Presentation",
|
|
174
219
|
"ui.autoExpandOnce": "Auto-expand the side panel (once per task)",
|
|
175
|
-
"ui.autoExpandOnce.hint": "Expands when the agent first operates; after you collapse it, this task stays quiet.",
|
|
176
220
|
"ui.closeWithSession": "Close the browser when the session ends",
|
|
177
|
-
"ui.
|
|
178
|
-
"ui.virtualCursor": "Show the synthetic cursor",
|
|
179
|
-
"ui.virtualCursor.hint": "Makes the agent's operating position visible (its presence means the agent has taken over that tab).",
|
|
221
|
+
"ui.virtualCursor": "Show agent cursor",
|
|
180
222
|
"ui.quiet": "Quiet mode",
|
|
181
|
-
"ui.quiet.hint": "
|
|
182
|
-
"vision.
|
|
183
|
-
"vision.
|
|
184
|
-
"vision.
|
|
185
|
-
"vision.nonVisual": "Non-visual only (coordinate clicks refused; locate via DOM / a11y tree)",
|
|
186
|
-
"vision.hint": "Under non-visual, a coordinate click is refused outright and the error says to use a semantic target — so nothing is clicked on a guessed position. DOM lookup, the accessibility tree, text extraction and structured scraping behave identically in both strategies: the whole page stays operable without image input.",
|
|
187
|
-
"credentials.title": "Credentials",
|
|
223
|
+
"ui.quiet.hint": "Keeps your current window and tab. New Chrome / Edge instances run in the background.",
|
|
224
|
+
"vision.strategy": "Coordinate clicks and drags",
|
|
225
|
+
"vision.auto": "Allowed",
|
|
226
|
+
"vision.nonVisual": "Blocked",
|
|
188
227
|
"credentials.allowRead": "Allow the agent to read cookies / export login state",
|
|
189
|
-
"browser.
|
|
190
|
-
"browser.
|
|
191
|
-
|
|
192
|
-
"browser.bundled": "Bundled Electron (ships with the plugin, nothing to install)",
|
|
228
|
+
"browser.channel": "Default browser",
|
|
229
|
+
"browser.sidebar": "DSH sidebar",
|
|
230
|
+
"browser.bundled": "Bundled browser",
|
|
193
231
|
"browser.chrome": "Installed Chrome",
|
|
194
232
|
"browser.edge": "Installed Edge",
|
|
195
|
-
"browser.auto": "Automatic
|
|
196
|
-
"
|
|
197
|
-
"credentials.hint": "Off makes dsh_browser_auth refuse the export, reporting BROWSER_AUTH_DISABLED — an export reads the machine-wide shared cookie jar (narrowed to the current page's site). It governs READING only: writing login state (restore) answers to the write switch under \"What the agent may do\" below. On the desktop, note that the agent drives the sidebar's own page (one page for both parties), so it shares that page's partition — which is exactly why it can reach the login state. That is a deliberate sandbox-boundary change; this switch is how you refuse it.",
|
|
198
|
-
"actions.title": "What the agent may do",
|
|
199
|
-
"actions.lead": "Unlike dsh_browser_restrict, which is the model's own soft guardrail and can be lifted by the model at any time, these three are yours: the model's own tools cannot change them.",
|
|
233
|
+
"browser.auto": "Automatic",
|
|
234
|
+
"actions.title": "Agent permissions",
|
|
200
235
|
"actions.allowExecute": "Run scripts in the page",
|
|
201
|
-
"actions.allowExecute.hint": "dsh_browser_execute runs arbitrary JavaScript in the active tab — its reach is everything that page can do. Off refuses the tool outright (BROWSER_EXECUTE_DISABLED), and no tool the model holds can change this setting. Do not read that as a lock, though: the document is served over a local HTTP endpoint and a same-origin page can write it. This is not a credential system.",
|
|
202
236
|
"actions.allowDownload": "Download files to disk",
|
|
203
|
-
"actions.allowDownload.hint": "dsh_browser_download fetches a URL into downloadDir (with login state; still subject to the directory admission gate, never overwriting an existing file). Off refuses it outright (BROWSER_DOWNLOAD_DISABLED). Saving a screenshot goes through the same directory gate and is not covered by this switch.",
|
|
204
237
|
"actions.allowCredentialWrite": "Write login state",
|
|
205
|
-
"actions.allowCredentialWrite.hint": "
|
|
206
|
-
"remoteView.
|
|
207
|
-
"remoteView.enabled": "
|
|
208
|
-
"
|
|
209
|
-
"readiness.title": "Readiness",
|
|
210
|
-
"readiness.lead": "The \"it works once you install it\" check: the bundled browser downloads its runtime in the background before its first use, the sidebar needs the bridge installed into the desktop app, and an installed Chrome / Edge has to be installed.",
|
|
238
|
+
"actions.allowCredentialWrite.hint": "Write cookies to any domain.",
|
|
239
|
+
"remoteView.enabled": "Allow remote viewing",
|
|
240
|
+
"remoteView.enabled.hint": "Shares a read-only view that may contain sensitive information.",
|
|
241
|
+
"readiness.title": "Environment check",
|
|
211
242
|
"readiness.loading": "Checking…",
|
|
212
243
|
"readiness.failed": "Could not read readiness:",
|
|
213
|
-
"readiness.channel": "
|
|
244
|
+
"readiness.channel": "Configured carrier",
|
|
245
|
+
"readiness.resolvedCarrier": "Current carrier",
|
|
246
|
+
"readiness.system": "Installed browser",
|
|
247
|
+
"readiness.details": "Diagnostics",
|
|
214
248
|
"readiness.electron": "Bundled browser runtime",
|
|
215
249
|
"readiness.bridge": "Desktop sidebar bridge",
|
|
216
250
|
"readiness.recheck": "Check again",
|
|
217
251
|
"readiness.prepare": "Prepare the bundled browser",
|
|
218
252
|
"readiness.preparing": "Preparing…",
|
|
219
|
-
"readiness.fix": "
|
|
253
|
+
"readiness.fix": "External-terminal command",
|
|
220
254
|
"readiness.carrier.sidebar": "Desktop sidebar",
|
|
221
255
|
"readiness.carrier.bundled": "Bundled Electron",
|
|
222
256
|
"readiness.carrier.system": "Installed Chrome / Edge",
|
|
223
257
|
"readiness.carrier.auto": "Automatic",
|
|
224
258
|
"readiness.state.ready": "Ready",
|
|
225
259
|
"readiness.state.blocked": "Not ready yet",
|
|
226
|
-
"readiness.
|
|
227
|
-
"readiness.
|
|
228
|
-
"readiness.
|
|
229
|
-
"readiness.
|
|
260
|
+
"readiness.status.checkPending": "Waiting for environment check",
|
|
261
|
+
"readiness.status.systemReady": "{browser} found",
|
|
262
|
+
"readiness.status.systemMissing": "{browser} not found",
|
|
263
|
+
"readiness.status.bundledReady": "Bundled runtime available",
|
|
264
|
+
"readiness.status.bundledMissing": "Bundled runtime needs installation",
|
|
265
|
+
"readiness.status.bundledPreparing": "Downloading bundled runtime",
|
|
266
|
+
"readiness.status.bundledFailed": "Bundled runtime preparation failed",
|
|
267
|
+
"readiness.status.bridgeReady": "Sidebar bridge available",
|
|
268
|
+
"readiness.status.bridgeMissing": "Sidebar bridge needs installation",
|
|
269
|
+
"readiness.status.bridgeStale": "Sidebar bridge needs repair",
|
|
270
|
+
"readiness.status.bridgeStopped": "Waiting for DSH Desktop to start",
|
|
271
|
+
"readiness.status.bridgeInstalled": "Sidebar bridge installed",
|
|
272
|
+
"readiness.status.desktopMissing": "DSH Desktop not found",
|
|
273
|
+
"readiness.electron.present": "Ready",
|
|
274
|
+
"readiness.electron.ready": "Ready",
|
|
275
|
+
"readiness.electron.preparing": "Downloading",
|
|
230
276
|
"readiness.electron.idle": "Not prepared yet",
|
|
231
277
|
"readiness.electron.skipped": "Skipped (ELECTRON_SKIP_BINARY_DOWNLOAD is set)",
|
|
232
278
|
"readiness.electron.failed": "Preparation failed",
|
|
@@ -236,10 +282,35 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
236
282
|
"readiness.bridge.missing": "Not installed",
|
|
237
283
|
"readiness.bridge.stale": "Stale (a desktop update needs a reinstall)",
|
|
238
284
|
"readiness.bridge.absent": "No desktop install on this machine",
|
|
239
|
-
"readiness.
|
|
240
|
-
"readiness.
|
|
241
|
-
"readiness.
|
|
242
|
-
"readiness.
|
|
285
|
+
"readiness.bridge.install": "Install and restart",
|
|
286
|
+
"readiness.bridge.repair": "Repair and restart",
|
|
287
|
+
"readiness.bridge.reinstall": "Reinstall and restart",
|
|
288
|
+
"readiness.bridge.uninstall": "Uninstall and restart",
|
|
289
|
+
"readiness.bridge.working": "Preparing maintenance…",
|
|
290
|
+
"readiness.bridge.inProgress": "Maintenance in progress…",
|
|
291
|
+
"readiness.bridge.maintenanceHint": "DSH will exit normally and restart after you click.",
|
|
292
|
+
"readiness.bridge.progressHint": "A separate progress window will appear. DSH starts automatically when maintenance finishes.",
|
|
293
|
+
"readiness.bridge.localOnly": "Use settings in DSH Desktop on this computer.",
|
|
294
|
+
"readiness.bridge.unsupported": "Update and restart DSH, then try again.",
|
|
295
|
+
"readiness.bridge.phase.armed": "Preparing to exit DSH…",
|
|
296
|
+
"readiness.bridge.phase.closing": "Exiting DSH normally…",
|
|
297
|
+
"readiness.bridge.phase.installing": "Installing the bridge…",
|
|
298
|
+
"readiness.bridge.phase.uninstalling": "Uninstalling the bridge…",
|
|
299
|
+
"readiness.bridge.phase.restarting": "Restarting DSH…",
|
|
300
|
+
"readiness.bridge.phase.verifying": "Checking the bridge…",
|
|
301
|
+
"readiness.bridge.failed": "Bridge maintenance failed. Check diagnostics and try again.",
|
|
302
|
+
"readiness.bridge.cancelled": "Bridge maintenance was cancelled. You can try again.",
|
|
303
|
+
"readiness.bridge.installedDone": "Bridge installed",
|
|
304
|
+
"readiness.bridge.uninstalledDone": "Bridge uninstalled",
|
|
305
|
+
"readiness.bridge.actionFailed": "Bridge maintenance could not start. Check diagnostics and try again.",
|
|
306
|
+
"delivery.title": "Delivery",
|
|
307
|
+
"delivery.tool": "Tool that takes the download (MCP tool name; empty = local only)",
|
|
308
|
+
"delivery.args": "Argument template (JSON)",
|
|
309
|
+
"delivery.args.hint": "Placeholders: {path} {name} {size}.",
|
|
310
|
+
"delivery.onFail": "When the remote side fails",
|
|
311
|
+
"delivery.onFail.keep": "Keep the local file and report both outcomes",
|
|
312
|
+
"delivery.onFail.stop": "Treat it as a failure",
|
|
313
|
+
"delivery.sites": "Per-site override (one host=tool per line)",
|
|
243
314
|
}
|
|
244
315
|
|
|
245
316
|
/**
|
|
@@ -277,23 +348,91 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
277
348
|
* under a third-party theme, and an unstyled row is worse than a slightly-off one.
|
|
278
349
|
*/
|
|
279
350
|
const CSS = `
|
|
351
|
+
.dsh-bb-settings .dsh-bb-row {
|
|
352
|
+
min-height: 36px;
|
|
353
|
+
align-items: center;
|
|
354
|
+
justify-content: space-between;
|
|
355
|
+
padding: 8px 0;
|
|
356
|
+
border-bottom: .5px solid var(--dsw-alias-border-l2, GrayText);
|
|
357
|
+
border-radius: 0;
|
|
358
|
+
background: transparent;
|
|
359
|
+
}
|
|
360
|
+
.dsh-bb-settings { font-size: 14px; line-height: 22px; }
|
|
361
|
+
.dsh-bb-settings .dsh-bb-diagnostics { margin-top: 4px; }
|
|
362
|
+
.dsh-bb-diagnostics code { display: block; max-height: 160px; overflow: auto; }
|
|
363
|
+
.dsh-bb-toggle { justify-content: space-between; cursor: pointer; }
|
|
364
|
+
.dsh-bb-toggle:has(:disabled) { cursor: default; }
|
|
365
|
+
.dsh-bb-switch {
|
|
366
|
+
appearance: none;
|
|
367
|
+
position: relative;
|
|
368
|
+
flex: 0 0 36px;
|
|
369
|
+
width: 36px;
|
|
370
|
+
height: 20px;
|
|
371
|
+
margin: 0;
|
|
372
|
+
box-sizing: border-box;
|
|
373
|
+
border: 0;
|
|
374
|
+
border-radius: 999px;
|
|
375
|
+
corner-shape: round;
|
|
376
|
+
background: var(--dsw-alias-border-l3, GrayText);
|
|
377
|
+
color: var(--dsw-alias-switch-thumb, Canvas);
|
|
378
|
+
cursor: inherit;
|
|
379
|
+
}
|
|
380
|
+
.dsh-bb-switch::after {
|
|
381
|
+
content: "";
|
|
382
|
+
position: absolute;
|
|
383
|
+
inset: 2px auto auto 2px;
|
|
384
|
+
width: 16px;
|
|
385
|
+
height: 16px;
|
|
386
|
+
border-radius: 50%;
|
|
387
|
+
corner-shape: round;
|
|
388
|
+
background: currentColor;
|
|
389
|
+
}
|
|
390
|
+
.dsh-bb-switch:checked {
|
|
391
|
+
background: var(--dsw-alias-brand-primary, Highlight);
|
|
392
|
+
color: var(--dsw-alias-label-primary-foreground, HighlightText);
|
|
393
|
+
}
|
|
394
|
+
.dsh-bb-switch:checked::after { transform: translateX(16px); }
|
|
395
|
+
.dsh-bb-switch:disabled { opacity: .6; }
|
|
396
|
+
.dsh-bb-settings :is(button, input, textarea, select, summary):focus-visible {
|
|
397
|
+
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, Highlight);
|
|
398
|
+
outline-offset: 2px;
|
|
399
|
+
}
|
|
400
|
+
.dsh-bb-settings summary { cursor: pointer; padding: 5px 0; }
|
|
401
|
+
.dsh-bb-settings .dsh-bb-dd { flex: 0 1 auto; margin: 0; }
|
|
402
|
+
.dsh-bb-settings .dsh-bb-dd-btn {
|
|
403
|
+
min-height: 36px;
|
|
404
|
+
padding: 0 14px;
|
|
405
|
+
border: 0;
|
|
406
|
+
border-radius: var(--dsw-radius-md, 8px);
|
|
407
|
+
background: var(--dsw-alias-bg-module-platform, ButtonFace);
|
|
408
|
+
}
|
|
409
|
+
.dsh-bb-settings .dsh-bb-dd-list { left: auto; right: 0; }
|
|
410
|
+
.dsh-bb-settings .dsh-bb-input {
|
|
411
|
+
box-sizing: border-box;
|
|
412
|
+
width: 100%;
|
|
413
|
+
min-height: 34px;
|
|
414
|
+
padding: 6px 8px;
|
|
415
|
+
border: 1px solid var(--dsw-alias-border, GrayText);
|
|
416
|
+
border-radius: 7px;
|
|
417
|
+
background: var(--dsw-alias-bg-layer-1, Canvas);
|
|
418
|
+
color: var(--dsw-alias-label-primary, CanvasText);
|
|
419
|
+
font: inherit;
|
|
420
|
+
}
|
|
421
|
+
.dsh-bb-settings fieldset { min-inline-size: 0; }
|
|
422
|
+
.dsh-bb-settings textarea { resize: vertical; }
|
|
280
423
|
.dsh-bb-row {
|
|
281
424
|
border-radius: 8px;
|
|
282
425
|
padding: 7px 9px;
|
|
283
426
|
color: var(--dsw-alias-label-primary, inherit);
|
|
284
427
|
transition: background-color .12s ease;
|
|
285
428
|
}
|
|
286
|
-
/*
|
|
287
|
-
|
|
288
|
-
.dsh-bb-row:hover {
|
|
429
|
+
/* Only the switch rows act as a single control; status and selector rows are plain text. */
|
|
430
|
+
.dsh-bb-toggle:hover:not(:has(:disabled)) {
|
|
289
431
|
background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.15));
|
|
290
432
|
}
|
|
291
|
-
.dsh-bb-
|
|
433
|
+
.dsh-bb-toggle:active:not(:has(:disabled)) {
|
|
292
434
|
background: var(--dsw-alias-interactive-bg-active, rgba(128,128,128,.22));
|
|
293
435
|
}
|
|
294
|
-
.dsh-bb-row:focus-within {
|
|
295
|
-
border-color: var(--dsw-alias-border-l2, rgba(128,128,128,.4));
|
|
296
|
-
}
|
|
297
436
|
/* The dropdown is drawn here rather than by the OS.
|
|
298
437
|
A native <select> paints its popup with system colours on Windows: the highlight overrides
|
|
299
438
|
whatever the option sets (white text on a white bar), and the list carries a border no CSS
|
|
@@ -303,6 +442,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
303
442
|
.dsh-bb-dd {
|
|
304
443
|
position: relative;
|
|
305
444
|
display: inline-block;
|
|
445
|
+
max-width: min(100%, calc(100vw - 32px));
|
|
306
446
|
margin-top: 4px;
|
|
307
447
|
}
|
|
308
448
|
.dsh-bb-dd-btn {
|
|
@@ -323,14 +463,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
323
463
|
background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.18));
|
|
324
464
|
}
|
|
325
465
|
.dsh-bb-dd-btn:disabled { opacity: .55; cursor: default; }
|
|
326
|
-
.dsh-bb-dd-
|
|
466
|
+
.dsh-bb-dd-btn > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
467
|
+
.dsh-bb-dd-caret { flex-shrink: 0; opacity: .6; font-size: 10px; line-height: 1; }
|
|
327
468
|
.dsh-bb-dd-list {
|
|
328
469
|
position: absolute;
|
|
470
|
+
box-sizing: border-box;
|
|
329
471
|
z-index: 20;
|
|
330
472
|
top: calc(100% + 4px);
|
|
331
473
|
left: 0;
|
|
474
|
+
width: max-content;
|
|
332
475
|
min-width: 100%;
|
|
333
|
-
max-width: 340px;
|
|
476
|
+
max-width: min(340px, calc(100vw - 32px));
|
|
334
477
|
padding: 4px;
|
|
335
478
|
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4));
|
|
336
479
|
border-radius: 8px;
|
|
@@ -339,6 +482,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
339
482
|
}
|
|
340
483
|
.dsh-bb-dd-opt {
|
|
341
484
|
display: block;
|
|
485
|
+
box-sizing: border-box;
|
|
342
486
|
width: 100%;
|
|
343
487
|
padding: 6px 9px;
|
|
344
488
|
border: none;
|
|
@@ -347,6 +491,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
347
491
|
color: var(--dsw-alias-label-primary, inherit);
|
|
348
492
|
font: inherit;
|
|
349
493
|
text-align: left;
|
|
494
|
+
white-space: nowrap;
|
|
495
|
+
overflow: hidden;
|
|
496
|
+
text-overflow: ellipsis;
|
|
350
497
|
cursor: pointer;
|
|
351
498
|
}
|
|
352
499
|
/* The same ellipse the rows use, so the panel reads as one surface — and it is ours to draw,
|
|
@@ -391,6 +538,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
391
538
|
.dsh-bw-watch-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; }
|
|
392
539
|
.dsh-bw-watch-title { font-weight: 600; }
|
|
393
540
|
.dsh-bw-watch-state { opacity: .7; margin-left: auto; }
|
|
541
|
+
.dsh-bw-watch-session {
|
|
542
|
+
max-width: 40%; font-size: 11px; color: inherit; background: transparent; cursor: pointer;
|
|
543
|
+
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 5px; padding: 2px 4px;
|
|
544
|
+
}
|
|
545
|
+
.dsh-bw-watch-session[hidden] { display: none; }
|
|
394
546
|
.dsh-bw-watch-close {
|
|
395
547
|
/* A visible control, not a hinted one: the old close was a 16px glyph at 70% opacity with no border
|
|
396
548
|
* or background, in the same colour as the title — reported as 'no way out but a page refresh'
|
|
@@ -433,18 +585,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
433
585
|
}
|
|
434
586
|
|
|
435
587
|
const styles = {
|
|
436
|
-
wrap: { display: "flex", flexDirection: "column", gap: "
|
|
588
|
+
wrap: { display: "flex", flexDirection: "column", gap: "12px" },
|
|
437
589
|
lead: { opacity: 0.75, lineHeight: 1.6, margin: 0 },
|
|
438
|
-
group: {
|
|
439
|
-
groupTitle: { margin: "0 0
|
|
590
|
+
group: { minWidth: 0 },
|
|
591
|
+
groupTitle: { margin: "0 0 2px", fontSize: "14px", fontWeight: 600, color: "var(--dsw-alias-label-primary, inherit)" },
|
|
440
592
|
row: { display: "flex", gap: "10px", alignItems: "flex-start" },
|
|
441
|
-
box: { marginTop: "2px" },
|
|
442
593
|
label: { display: "flex", flexDirection: "column", gap: "2px", cursor: "pointer" },
|
|
443
|
-
hint: {
|
|
594
|
+
hint: { color: "var(--dsw-alias-label-tertiary, inherit)", fontSize: "12px", lineHeight: 1.5 },
|
|
444
595
|
status: { opacity: 0.7, minHeight: "18px" },
|
|
445
|
-
error: { color: "#
|
|
596
|
+
error: { color: "var(--dsw-alias-label-error, #c9342c)" },
|
|
446
597
|
pathLine: { opacity: 0.6, wordBreak: "break-all", lineHeight: 1.5 },
|
|
447
|
-
button: { padding: "
|
|
598
|
+
button: { minHeight: "32px", padding: "5px 12px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.4))", background: "transparent", color: "inherit", font: "inherit", cursor: "pointer" },
|
|
448
599
|
// Readiness: one headline state, three one-line facts, and at most two buttons. The colours are
|
|
449
600
|
// the only place this panel states an opinion, which is why they carry no text of their own —
|
|
450
601
|
// the label next to them is always a locale string.
|
|
@@ -455,7 +606,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
455
606
|
kv: { display: "grid", gridTemplateColumns: "auto 1fr", gap: "3px 12px", margin: "8px 0 0", fontSize: "12px" },
|
|
456
607
|
kvKey: { opacity: 0.68 },
|
|
457
608
|
kvVal: { lineHeight: 1.5 },
|
|
458
|
-
mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "rgba(0,0,0,.22)", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
|
|
609
|
+
mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "var(--dsw-alias-bg-layer-2, rgba(0,0,0,.22))", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
|
|
459
610
|
buttons: { display: "flex", gap: "8px", alignItems: "center", marginTop: "10px", flexWrap: "wrap" },
|
|
460
611
|
}
|
|
461
612
|
|
|
@@ -525,14 +676,18 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
525
676
|
type: "button",
|
|
526
677
|
ref: buttonRef,
|
|
527
678
|
className: "dsh-bb-dd-btn",
|
|
679
|
+
"aria-label": props.label + ": " + (current?.label ?? ""),
|
|
528
680
|
disabled: props.disabled,
|
|
529
681
|
"aria-haspopup": "listbox",
|
|
530
682
|
"aria-expanded": open ? "true" : "false",
|
|
683
|
+
onBlur: event => {
|
|
684
|
+
if (!rootRef.current?.contains(event.relatedTarget)) setOpen(false)
|
|
685
|
+
},
|
|
531
686
|
onClick: () => { setOpen(o => !o); setActive(-1) },
|
|
532
687
|
onKeyDown,
|
|
533
688
|
}, [
|
|
534
689
|
h("span", { key: "v" }, current === undefined ? "" : current.label),
|
|
535
|
-
h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "
|
|
690
|
+
h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "\u25be"),
|
|
536
691
|
]),
|
|
537
692
|
open ? h("div", {
|
|
538
693
|
key: "l",
|
|
@@ -544,7 +699,9 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
544
699
|
type: "button",
|
|
545
700
|
className: "dsh-bb-dd-opt",
|
|
546
701
|
role: "option",
|
|
702
|
+
tabIndex: -1,
|
|
547
703
|
"aria-selected": option.value === props.value ? "true" : "false",
|
|
704
|
+
onMouseDown: event => event.preventDefault(),
|
|
548
705
|
"data-active": index === active ? "true" : "false",
|
|
549
706
|
onMouseEnter: () => setActive(index),
|
|
550
707
|
onClick: () => commit(index),
|
|
@@ -555,19 +712,21 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
555
712
|
/** One boolean switch bound to a settings path. */
|
|
556
713
|
function Toggle(props) {
|
|
557
714
|
const t = translate
|
|
558
|
-
return h("
|
|
715
|
+
return h("label", { style: styles.row, className: "dsh-bb-row dsh-bb-toggle" }, [
|
|
716
|
+
h("span", { key: "l", style: styles.label }, [
|
|
717
|
+
h("span", { key: "t" }, t(props.labelKey)),
|
|
718
|
+
props.hintKey ? h("span", { key: "h", style: styles.hint }, t(props.hintKey)) : null,
|
|
719
|
+
]),
|
|
559
720
|
h("input", {
|
|
560
721
|
key: "i",
|
|
561
722
|
type: "checkbox",
|
|
562
|
-
|
|
723
|
+
className: "dsh-bb-switch",
|
|
724
|
+
role: "switch",
|
|
725
|
+
"aria-label": t(props.labelKey),
|
|
563
726
|
checked: props.checked,
|
|
564
727
|
disabled: props.busy,
|
|
565
728
|
onChange: event => props.onChange(event.target.checked),
|
|
566
729
|
}),
|
|
567
|
-
h("label", { key: "l", style: styles.label, onClick: () => props.onChange(!props.checked) }, [
|
|
568
|
-
h("span", { key: "t" }, t(props.labelKey)),
|
|
569
|
-
h("span", { key: "h", style: styles.hint }, t(props.hintKey)),
|
|
570
|
-
]),
|
|
571
730
|
])
|
|
572
731
|
}
|
|
573
732
|
|
|
@@ -601,13 +760,20 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
601
760
|
* same one background attempt the plugin makes on its own, which is why pressing it is never
|
|
602
761
|
* harmful and never starts a second download.
|
|
603
762
|
*/
|
|
604
|
-
function Readiness() {
|
|
763
|
+
function Readiness({ channel } = {}) {
|
|
605
764
|
useLocaleVersion()
|
|
606
765
|
const t = translate
|
|
607
766
|
const [runtime, setRuntime] = useState(null)
|
|
608
767
|
const [error, setError] = useState("")
|
|
609
768
|
const [unsupported, setUnsupported] = useState(false)
|
|
610
769
|
const [busy, setBusy] = useState(false)
|
|
770
|
+
const [bridgeBusy, setBridgeBusy] = useState(null)
|
|
771
|
+
const [bridgeJob, setBridgeJob] = useState(null)
|
|
772
|
+
const [bridgePollVersion, setBridgePollVersion] = useState(0)
|
|
773
|
+
const [bridgeError, setBridgeError] = useState(null)
|
|
774
|
+
const bridgePending = useRef(false)
|
|
775
|
+
const bridgeSubmitting = useRef(false)
|
|
776
|
+
const bridgeJobId = useRef(null)
|
|
611
777
|
const alive = useRef(true)
|
|
612
778
|
|
|
613
779
|
const read = useCallback(async () => {
|
|
@@ -636,11 +802,35 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
636
802
|
}
|
|
637
803
|
}, [])
|
|
638
804
|
|
|
805
|
+
const bridgeActivePhases = ["armed", "closing", "installing", "restarting", "verifying"]
|
|
806
|
+
const bridgeActive = bridgeJob !== null && bridgeActivePhases.includes(bridgeJob.phase)
|
|
807
|
+
const readBridgeJob = useCallback(async () => {
|
|
808
|
+
try {
|
|
809
|
+
const response = await fetch("/dsh-builtin-browser/bridge-maintenance", { headers: { accept: "application/json" } })
|
|
810
|
+
if (!response.ok) return
|
|
811
|
+
const data = await response.json()
|
|
812
|
+
if (!alive.current || bridgeSubmitting.current || data.ok !== true || data.protocol !== 1 || !data.job || typeof data.job.id !== "string") return
|
|
813
|
+
if (bridgePending.current && bridgeJobId.current !== null && bridgeJobId.current !== data.job.id) return
|
|
814
|
+
bridgeJobId.current = data.job.id
|
|
815
|
+
bridgePending.current = ["armed", "closing", "installing", "restarting", "verifying"].includes(data.job.phase)
|
|
816
|
+
setBridgeJob(data.job)
|
|
817
|
+
if (data.job.phase === "completed") void read()
|
|
818
|
+
} catch { /* The desktop is briefly offline while maintenance restarts it. Keep its job. */ }
|
|
819
|
+
finally { if (alive.current) setBridgePollVersion(version => version + 1) }
|
|
820
|
+
}, [read])
|
|
821
|
+
|
|
639
822
|
useEffect(() => {
|
|
640
823
|
alive.current = true
|
|
641
824
|
void read()
|
|
825
|
+
void readBridgeJob()
|
|
642
826
|
return () => { alive.current = false }
|
|
643
|
-
}, [read])
|
|
827
|
+
}, [read, readBridgeJob, channel])
|
|
828
|
+
|
|
829
|
+
useEffect(() => {
|
|
830
|
+
if (!bridgeActive) return undefined
|
|
831
|
+
const timer = setTimeout(() => { void readBridgeJob() }, 1000)
|
|
832
|
+
return () => clearTimeout(timer)
|
|
833
|
+
}, [bridgeActive, bridgeJob, bridgePollVersion, readBridgeJob])
|
|
644
834
|
|
|
645
835
|
// Poll only while a download is running: that is the one state that changes on its own, and a
|
|
646
836
|
// poll in any other state would be a background request per panel per two seconds forever.
|
|
@@ -670,6 +860,50 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
670
860
|
}
|
|
671
861
|
}
|
|
672
862
|
|
|
863
|
+
const bridgeAction = async action => {
|
|
864
|
+
if (bridgePending.current || busy || bridgeActive) return
|
|
865
|
+
const desktopMenu = () => typeof document.querySelector === "function"
|
|
866
|
+
? document.querySelector("[data-windows-menu]")?.shadowRoot?.querySelector("button") : null
|
|
867
|
+
if (typeof desktopMenu()?.click !== "function") {
|
|
868
|
+
setBridgeError({ key: "readiness.bridge.localOnly" })
|
|
869
|
+
return
|
|
870
|
+
}
|
|
871
|
+
bridgePending.current = true
|
|
872
|
+
bridgeSubmitting.current = true
|
|
873
|
+
setBridgeBusy(action)
|
|
874
|
+
setBridgeJob(null)
|
|
875
|
+
setBridgeError(null)
|
|
876
|
+
let accepted = false
|
|
877
|
+
try {
|
|
878
|
+
const response = await fetch("/dsh-builtin-browser/bridge-maintenance", {
|
|
879
|
+
method: "POST",
|
|
880
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
881
|
+
body: JSON.stringify({ action, locale: currentLocale }),
|
|
882
|
+
})
|
|
883
|
+
const data = await response.json().catch(() => ({}))
|
|
884
|
+
if (response.status === 404) {
|
|
885
|
+
if (alive.current) setBridgeError({ key: "readiness.bridge.unsupported" })
|
|
886
|
+
return
|
|
887
|
+
}
|
|
888
|
+
if (!response.ok || data.ok !== true) throw new Error(data.error || data.output || `HTTP ${response.status}`)
|
|
889
|
+
if (data.protocol !== 1 || data.accepted !== true || typeof data.job?.id !== "string" || data.job.phase !== "armed" || data.job.action !== action) throw new Error("invalid bridge maintenance acknowledgement")
|
|
890
|
+
accepted = true
|
|
891
|
+
bridgeJobId.current = data.job.id
|
|
892
|
+
if (alive.current) setBridgeJob(data.job)
|
|
893
|
+
const menu = desktopMenu()
|
|
894
|
+
if (typeof menu?.click !== "function") throw new Error(t("readiness.bridge.localOnly"))
|
|
895
|
+
// The armed worker selects Exit in this official native menu. This opens that menu only
|
|
896
|
+
// after the new maintenance endpoint has acknowledged the handoff.
|
|
897
|
+
menu.click()
|
|
898
|
+
} catch (failure) {
|
|
899
|
+
if (alive.current) setBridgeError({ key: "readiness.bridge.actionFailed", detail: String(failure && failure.message ? failure.message : failure) })
|
|
900
|
+
} finally {
|
|
901
|
+
bridgeSubmitting.current = false
|
|
902
|
+
if (!accepted) bridgePending.current = false
|
|
903
|
+
if (alive.current) setBridgeBusy(null)
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
673
907
|
if (unsupported) return null
|
|
674
908
|
if (runtime === null) {
|
|
675
909
|
return h("div", { style: styles.wrap }, [
|
|
@@ -694,46 +928,144 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
694
928
|
: runtime.bridge.running === false
|
|
695
929
|
? t("readiness.bridge.installedNotRunning")
|
|
696
930
|
: t("readiness.bridge.installed")
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
931
|
+
const resolvedCarrier = runtime.resolvedCarrier ?? (runtime.carrier === "auto"
|
|
932
|
+
? runtime.bridge.state === "installed" && runtime.bridge.running === true ? "sidebar"
|
|
933
|
+
: runtime.systemBrowser?.present === true ? "system" : "bundled"
|
|
934
|
+
: runtime.carrier)
|
|
935
|
+
const systemName = ({ chrome: "Chrome", edge: "Edge", brave: "Brave" })[runtime.systemBrowser?.kind ?? runtime.channel] ?? t("readiness.system")
|
|
936
|
+
const systemLabel = runtime.systemBrowser?.checked === true
|
|
937
|
+
? t(runtime.systemBrowser.present ? "readiness.status.systemReady" : "readiness.status.systemMissing").replace("{browser}", systemName)
|
|
938
|
+
: t("readiness.status.checkPending")
|
|
939
|
+
const stateLabel = resolvedCarrier === "system" ? systemLabel
|
|
940
|
+
: resolvedCarrier === "sidebar"
|
|
941
|
+
? t(runtime.bridge.state === "installed"
|
|
942
|
+
? runtime.bridge.running === true ? "readiness.status.bridgeReady"
|
|
943
|
+
: runtime.bridge.running === false ? "readiness.status.bridgeStopped" : "readiness.status.bridgeInstalled"
|
|
944
|
+
: runtime.bridge.state === "stale" ? "readiness.status.bridgeStale"
|
|
945
|
+
: runtime.bridge.state === "missing" ? "readiness.status.bridgeMissing" : "readiness.status.desktopMissing")
|
|
946
|
+
: t(runtime.electron.state === "present" || runtime.electron.state === "ready" ? "readiness.status.bundledReady"
|
|
947
|
+
: runtime.electron.state === "preparing" ? "readiness.status.bundledPreparing"
|
|
948
|
+
: runtime.electron.state === "failed" ? "readiness.status.bundledFailed" : "readiness.status.bundledMissing")
|
|
949
|
+
const controlsBusy = busy || bridgeBusy !== null || bridgeActive
|
|
950
|
+
const canManageBridge = runtime.bridge.present === true && runtime.bridge.state !== "absent"
|
|
951
|
+
const installLabel = runtime.bridge.state === "installed" ? "readiness.bridge.reinstall"
|
|
952
|
+
: runtime.bridge.state === "stale" ? "readiness.bridge.repair" : "readiness.bridge.install"
|
|
953
|
+
const bridgeButtonBusy = bridgeBusy !== null || bridgeActive
|
|
954
|
+
const bridgeButtonStyle = controlsBusy || preparing ? { ...styles.button, cursor: "default", opacity: .6 } : styles.button
|
|
955
|
+
const bridgeJobError = typeof bridgeJob?.error === "string" ? bridgeJob.error : ""
|
|
956
|
+
const bridgeJobOutput = typeof bridgeJob?.output === "string" ? bridgeJob.output : ""
|
|
957
|
+
const bridgeJobDiagnostic = bridgeJobOutput !== "" && bridgeJobError.includes(bridgeJobOutput)
|
|
958
|
+
? bridgeJobError : [bridgeJobError, bridgeJobOutput].filter(Boolean).join("\n")
|
|
959
|
+
|
|
960
|
+
return h("div", { style: styles.group }, [
|
|
961
|
+
h("div", { key: "head", className: "dsh-bb-row", style: styles.row }, [
|
|
962
|
+
h("span", { key: "title" }, t("readiness.title")),
|
|
963
|
+
h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, stateLabel),
|
|
707
964
|
]),
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
965
|
+
canManageBridge ? h("div", { key: "bridge-controls" }, [
|
|
966
|
+
h("div", { key: "row", className: "dsh-bb-row", style: styles.row }, [
|
|
967
|
+
h("span", { key: "title" }, t("readiness.bridge")),
|
|
968
|
+
h("button", { key: "install", type: "button", style: bridgeButtonStyle, disabled: controlsBusy || preparing, "aria-busy": bridgeButtonBusy ? "true" : undefined, onClick: () => bridgeAction("install") }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.inProgress" : installLabel)),
|
|
969
|
+
]),
|
|
970
|
+
h("p", { key: "hint", role: bridgeBusy !== null || bridgeActive ? "status" : undefined, style: styles.hint }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.progressHint" : "readiness.bridge.maintenanceHint")),
|
|
971
|
+
]) : null,
|
|
972
|
+
bridgeActive ? h("p", { key: "bridge-progress", role: "status", style: styles.hint }, t(`readiness.bridge.phase.${bridgeJob.phase === "installing" && bridgeJob.action === "uninstall" ? "uninstalling" : bridgeJob.phase}`)) : null,
|
|
973
|
+
bridgeJob?.phase === "completed" ? h("p", { key: "bridge-result", role: "status", style: styles.hint }, t(bridgeJob.action === "uninstall" ? "readiness.bridge.uninstalledDone" : "readiness.bridge.installedDone")) : null,
|
|
974
|
+
bridgeJob?.phase === "failed" || bridgeJob?.phase === "cancelled" ? h("p", { key: "bridge-job-error", role: "alert", style: styles.error }, t(`readiness.bridge.${bridgeJob.phase}`)) : null,
|
|
975
|
+
bridgeError !== null ? h("p", { key: "bridge-error", role: "alert", style: styles.error }, t(bridgeError.key)) : null,
|
|
976
|
+
h("details", { key: "diagnostics", className: "dsh-bb-diagnostics" }, [
|
|
977
|
+
h("summary", { key: "title", style: styles.hint }, t("readiness.details")),
|
|
978
|
+
h("div", { key: "kv", style: styles.kv }, [
|
|
979
|
+
...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
|
|
980
|
+
runtime.resolvedCarrier ? row("resolved-carrier", t("readiness.resolvedCarrier"), t(`readiness.carrier.${runtime.resolvedCarrier}`)) : null,
|
|
981
|
+
runtime.systemBrowser?.checked === true ? row("system", t("readiness.system"), systemLabel) : null,
|
|
982
|
+
...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
|
|
983
|
+
...row("bridge", t("readiness.bridge"), bridgeLabel),
|
|
984
|
+
]),
|
|
985
|
+
runtime.systemBrowser?.path ? h("code", { key: "system-path", style: styles.mono }, runtime.systemBrowser.path) : null,
|
|
986
|
+
bridgeError?.detail ? h("code", { key: "bridge-error-detail", style: styles.mono }, bridgeError.detail) : null,
|
|
987
|
+
bridgeJobDiagnostic !== "" ? h("code", { key: "bridge-job-detail", style: styles.mono }, bridgeJobDiagnostic) : null,
|
|
988
|
+
runtime.electron.state === "failed" || runtime.electron.state === "skipped"
|
|
989
|
+
? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail) : null,
|
|
990
|
+
runtime.bridge.state === "installed" && runtime.bridge.running === false
|
|
991
|
+
? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail) : null,
|
|
992
|
+
runtime.bridge.command
|
|
993
|
+
? h("p", { key: "command", style: styles.hint }, [
|
|
994
|
+
h("span", { key: "label" }, t("readiness.fix")),
|
|
995
|
+
h("code", { key: "value", style: styles.mono }, runtime.bridge.command),
|
|
996
|
+
]) : null,
|
|
725
997
|
h("button", {
|
|
726
998
|
key: "recheck",
|
|
727
999
|
type: "button",
|
|
728
1000
|
style: styles.button,
|
|
729
|
-
disabled:
|
|
1001
|
+
disabled: controlsBusy || preparing,
|
|
730
1002
|
onClick: () => { void read() },
|
|
731
|
-
},
|
|
732
|
-
runtime.
|
|
733
|
-
|
|
734
|
-
:
|
|
735
|
-
|
|
1003
|
+
}, t("readiness.recheck")),
|
|
1004
|
+
canManageBridge && runtime.bridge.state === "installed" ? h("button", {
|
|
1005
|
+
key: "uninstall", type: "button", style: bridgeButtonStyle, disabled: controlsBusy || preparing, "aria-busy": bridgeButtonBusy ? "true" : undefined,
|
|
1006
|
+
onClick: () => bridgeAction("uninstall"),
|
|
1007
|
+
}, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.inProgress" : "readiness.bridge.uninstall")) : null,
|
|
736
1008
|
]),
|
|
1009
|
+
runtime.canProvision || preparing
|
|
1010
|
+
? h("div", { key: "buttons", style: styles.buttons }, [
|
|
1011
|
+
preparing ? h("span", { key: "progress", role: "status", style: styles.hint }, t("readiness.preparing")) : null,
|
|
1012
|
+
runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: controlsBusy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
|
|
1013
|
+
]) : null,
|
|
1014
|
+
error !== "" ? h("p", { key: "error", role: "alert", style: styles.error }, t("readiness.failed") + " " + error) : null,
|
|
1015
|
+
])
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** Save the delivery fields together so moving focus never writes a partial template. */
|
|
1019
|
+
function DeliverySettings({ delivery, busy, onSave }) {
|
|
1020
|
+
const t = translate
|
|
1021
|
+
const [invalid, setInvalid] = useState(false)
|
|
1022
|
+
const toolPattern = /^[A-Za-z0-9_.-]+$/
|
|
1023
|
+
const submit = event => {
|
|
1024
|
+
event.preventDefault()
|
|
1025
|
+
const fields = event.currentTarget.elements
|
|
1026
|
+
const tool = fields.namedItem("tool").value.trim()
|
|
1027
|
+
const onFail = fields.namedItem("onFail").value
|
|
1028
|
+
const rules = fields.namedItem("sites").value.split("\n").filter(line => line.trim() !== "")
|
|
1029
|
+
const entries = rules.map(line => line.split("=").map(value => value.trim()))
|
|
1030
|
+
let args
|
|
1031
|
+
try {
|
|
1032
|
+
args = JSON.parse(fields.namedItem("args").value)
|
|
1033
|
+
} catch {
|
|
1034
|
+
setInvalid(true)
|
|
1035
|
+
return
|
|
1036
|
+
}
|
|
1037
|
+
if ((tool !== "" && !toolPattern.test(tool))
|
|
1038
|
+
|| args === null || typeof args !== "object" || Array.isArray(args)
|
|
1039
|
+
|| Object.values(args).some(value => typeof value !== "string")
|
|
1040
|
+
|| entries.some(entry => entry.length !== 2 || !/^[A-Za-z0-9.-]+$/.test(entry[0]) || !toolPattern.test(entry[1]))) {
|
|
1041
|
+
setInvalid(true)
|
|
1042
|
+
return
|
|
1043
|
+
}
|
|
1044
|
+
const sites = Object.fromEntries(entries.map(([host, name]) => [host.toLowerCase(), name]))
|
|
1045
|
+
if (Object.keys(sites).length !== entries.length) {
|
|
1046
|
+
setInvalid(true)
|
|
1047
|
+
return
|
|
1048
|
+
}
|
|
1049
|
+
setInvalid(false)
|
|
1050
|
+
onSave({ tool, args, onFail, sites })
|
|
1051
|
+
}
|
|
1052
|
+
const field = (name, control) => h("label", { key: name, style: styles.label }, [
|
|
1053
|
+
h("span", { key: "label" }, t("delivery." + name)),
|
|
1054
|
+
control,
|
|
1055
|
+
name === "args" ? h("span", { key: "hint", style: styles.hint }, t("delivery.args.hint")) : null,
|
|
1056
|
+
])
|
|
1057
|
+
return h("form", { onSubmit: submit }, [
|
|
1058
|
+
h("fieldset", { key: "fields", disabled: busy, style: { border: 0, margin: 0, padding: 0, display: "grid", gap: "10px" } }, [
|
|
1059
|
+
field("tool", h("input", { key: "control", name: "tool", className: "dsh-bb-input", defaultValue: delivery?.tool ?? "", placeholder: "lark_drive_upload" })),
|
|
1060
|
+
field("args", h("textarea", { key: "control", name: "args", className: "dsh-bb-input", rows: 3, defaultValue: JSON.stringify(delivery?.args ?? { file_path: "{path}" }, null, 2) })),
|
|
1061
|
+
field("onFail", h("select", { key: "control", name: "onFail", className: "dsh-bb-input", defaultValue: delivery?.onFail ?? "keep-local" }, [
|
|
1062
|
+
h("option", { key: "keep", value: "keep-local" }, t("delivery.onFail.keep")),
|
|
1063
|
+
h("option", { key: "stop", value: "stop" }, t("delivery.onFail.stop")),
|
|
1064
|
+
])),
|
|
1065
|
+
field("sites", h("textarea", { key: "control", name: "sites", className: "dsh-bb-input", rows: 3, defaultValue: Object.entries(delivery?.sites ?? {}).map(([host, tool]) => host + "=" + tool).join("\n") })),
|
|
1066
|
+
h("div", { key: "actions" }, h("button", { type: "submit", style: styles.button }, t("delivery.save"))),
|
|
1067
|
+
]),
|
|
1068
|
+
invalid ? h("p", { key: "error", role: "alert", style: styles.error }, t("delivery.invalid")) : null,
|
|
737
1069
|
])
|
|
738
1070
|
}
|
|
739
1071
|
|
|
@@ -746,32 +1078,50 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
746
1078
|
const [error, setError] = useState("")
|
|
747
1079
|
const [busy, setBusy] = useState(false)
|
|
748
1080
|
const [saved, setSaved] = useState(false)
|
|
1081
|
+
const saving = useRef(false)
|
|
1082
|
+
const savedTimer = useRef(null)
|
|
1083
|
+
const alive = useRef(true)
|
|
749
1084
|
|
|
750
1085
|
const load = useCallback(() => {
|
|
751
1086
|
setError("")
|
|
752
1087
|
callSettings().then(data => {
|
|
1088
|
+
if (!alive.current) return
|
|
753
1089
|
setSettings(data.settings)
|
|
754
1090
|
setMeta({ path: data.path || "" })
|
|
755
|
-
}).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
|
|
1091
|
+
}).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
|
|
756
1092
|
}, [])
|
|
757
1093
|
|
|
758
|
-
useEffect(() => {
|
|
1094
|
+
useEffect(() => {
|
|
1095
|
+
alive.current = true
|
|
1096
|
+
load()
|
|
1097
|
+
return () => { alive.current = false }
|
|
1098
|
+
}, [load])
|
|
1099
|
+
useEffect(() => () => clearTimeout(savedTimer.current), [])
|
|
759
1100
|
|
|
760
1101
|
const patch = useCallback(next => {
|
|
1102
|
+
if (saving.current) return
|
|
1103
|
+
saving.current = true
|
|
1104
|
+
clearTimeout(savedTimer.current)
|
|
1105
|
+
setSaved(false)
|
|
761
1106
|
setBusy(true)
|
|
762
1107
|
setError("")
|
|
763
1108
|
callSettings(next).then(data => {
|
|
1109
|
+
if (!alive.current) return
|
|
764
1110
|
setSettings(data.settings)
|
|
765
1111
|
setSaved(true)
|
|
766
|
-
setTimeout(() => setSaved(false),
|
|
767
|
-
}).catch(failure => setError(String(failure && failure.message ? failure.message : failure)))
|
|
768
|
-
.
|
|
1112
|
+
savedTimer.current = setTimeout(() => setSaved(false), 1800)
|
|
1113
|
+
}).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
|
|
1114
|
+
.finally(() => {
|
|
1115
|
+
saving.current = false
|
|
1116
|
+
if (alive.current) setBusy(false)
|
|
1117
|
+
})
|
|
769
1118
|
}, [])
|
|
770
1119
|
|
|
771
1120
|
if (rawSettings === null) {
|
|
772
1121
|
return h("div", { style: styles.wrap }, [
|
|
773
|
-
h("p", { key: "l", style: styles.lead }, t("loading")),
|
|
1122
|
+
error === "" ? h("p", { key: "l", role: "status", style: styles.lead }, t("loading")) : null,
|
|
774
1123
|
error !== "" ? h("p", { key: "e", style: styles.error }, `${t("failed")} ${error}`) : null,
|
|
1124
|
+
error !== "" ? h("button", { key: "retry", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
775
1125
|
])
|
|
776
1126
|
}
|
|
777
1127
|
|
|
@@ -785,181 +1135,76 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
785
1135
|
? { ...rawSettings, actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true } }
|
|
786
1136
|
: rawSettings
|
|
787
1137
|
|
|
788
|
-
const
|
|
789
|
-
|
|
1138
|
+
const toggle = (group, key, labelKey = group + "." + key, hintKey) => h(Toggle, {
|
|
1139
|
+
key,
|
|
1140
|
+
labelKey,
|
|
1141
|
+
hintKey,
|
|
1142
|
+
checked: settings[group]?.[key] ?? (group === "cookies" && key === "persist"),
|
|
1143
|
+
busy,
|
|
1144
|
+
onChange: value => patch({ [group]: { [key]: value } }),
|
|
1145
|
+
})
|
|
1146
|
+
const selector = (labelKey, value, options, onChange, hintKey) => h("div", {
|
|
1147
|
+
key: labelKey,
|
|
1148
|
+
className: "dsh-bb-row",
|
|
1149
|
+
style: styles.row,
|
|
1150
|
+
}, [
|
|
1151
|
+
h("span", { key: "text", style: styles.label }, [
|
|
1152
|
+
h("span", { key: "label" }, t(labelKey)),
|
|
1153
|
+
hintKey ? h("span", { key: "hint", style: styles.hint }, t(hintKey)) : null,
|
|
1154
|
+
]),
|
|
1155
|
+
h(Dropdown, { key: "select", label: t(labelKey), value, options, disabled: busy, onChange }),
|
|
1156
|
+
])
|
|
1157
|
+
const options = (prefix, values) => values.map(value => ({ value, label: t(prefix + value) }))
|
|
1158
|
+
const section = (titleKey, children) => h("section", { key: titleKey, style: styles.group }, [
|
|
1159
|
+
h("h3", { key: "title", style: styles.groupTitle }, t(titleKey)),
|
|
790
1160
|
...children,
|
|
791
1161
|
])
|
|
1162
|
+
const systemBrowser = ["chrome", "edge", "auto"].includes(settings.browser.channel)
|
|
792
1163
|
|
|
793
|
-
return h("div", { style: styles.wrap }, [
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
section("readiness.title", [
|
|
799
|
-
h("p", { key: "lead", style: styles.hint }, t("readiness.lead")),
|
|
800
|
-
h(Readiness, { key: "r" }),
|
|
801
|
-
]),
|
|
802
|
-
|
|
803
|
-
section("history.title", [
|
|
804
|
-
h(Toggle, {
|
|
805
|
-
key: "enabled",
|
|
806
|
-
labelKey: "history.enabled",
|
|
807
|
-
hintKey: "history.hint",
|
|
808
|
-
checked: settings.history.enabled,
|
|
809
|
-
busy,
|
|
810
|
-
onChange: value => patch({ history: { enabled: value } }),
|
|
811
|
-
}),
|
|
812
|
-
]),
|
|
813
|
-
|
|
814
|
-
section("cookies.title", [
|
|
815
|
-
h(Toggle, {
|
|
816
|
-
key: "persist",
|
|
817
|
-
labelKey: "cookies.persist",
|
|
818
|
-
hintKey: "cookies.hint",
|
|
819
|
-
checked: settings.cookies.persist,
|
|
820
|
-
busy,
|
|
821
|
-
onChange: value => patch({ cookies: { persist: value } }),
|
|
822
|
-
}),
|
|
823
|
-
]),
|
|
824
|
-
|
|
1164
|
+
return h("div", { style: styles.wrap, className: "dsh-bb-settings" }, [
|
|
1165
|
+
selector("browser.channel", settings.browser.channel,
|
|
1166
|
+
options("browser.", ["bundled", "sidebar", "auto", "chrome", "edge"]),
|
|
1167
|
+
channel => patch({ browser: { channel } })),
|
|
1168
|
+
h(Readiness, { key: "readiness", channel: settings.browser.channel }),
|
|
825
1169
|
section("ui.title", [
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
busy,
|
|
832
|
-
onChange: value => patch({ ui: { autoExpandOnce: value } }),
|
|
833
|
-
}),
|
|
834
|
-
h(Toggle, {
|
|
835
|
-
key: "closeWithSession",
|
|
836
|
-
labelKey: "ui.closeWithSession",
|
|
837
|
-
hintKey: "ui.closeWithSession.hint",
|
|
838
|
-
checked: settings.ui.closeWithSession,
|
|
839
|
-
busy,
|
|
840
|
-
onChange: value => patch({ ui: { closeWithSession: value } }),
|
|
841
|
-
}),
|
|
842
|
-
h(Toggle, {
|
|
843
|
-
key: "virtualCursor",
|
|
844
|
-
labelKey: "ui.virtualCursor",
|
|
845
|
-
hintKey: "ui.virtualCursor.hint",
|
|
846
|
-
checked: settings.ui.virtualCursor,
|
|
847
|
-
busy,
|
|
848
|
-
onChange: value => patch({ ui: { virtualCursor: value } }),
|
|
849
|
-
}),
|
|
850
|
-
h(Toggle, {
|
|
851
|
-
key: "quiet",
|
|
852
|
-
labelKey: "ui.quiet",
|
|
853
|
-
hintKey: "ui.quiet.hint",
|
|
854
|
-
checked: settings.ui.quiet,
|
|
855
|
-
busy,
|
|
856
|
-
onChange: value => patch({ ui: { quiet: value } }),
|
|
857
|
-
}),
|
|
858
|
-
]),
|
|
859
|
-
|
|
860
|
-
section("vision.title", [
|
|
861
|
-
h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
|
|
862
|
-
h("label", { key: "l", style: styles.label }, [
|
|
863
|
-
h("span", { key: "t" }, t("vision.strategy")),
|
|
864
|
-
h(Dropdown, {
|
|
865
|
-
key: "s",
|
|
866
|
-
label: t("vision.strategy"),
|
|
867
|
-
value: settings.vision.strategy,
|
|
868
|
-
disabled: busy,
|
|
869
|
-
onChange: value => patch({ vision: { strategy: value } }),
|
|
870
|
-
options: [
|
|
871
|
-
{ value: "auto", label: t("vision.auto") },
|
|
872
|
-
{ value: "nonVisual", label: t("vision.nonVisual") },
|
|
873
|
-
],
|
|
874
|
-
}),
|
|
875
|
-
h("span", { key: "h", style: styles.hint }, t("vision.hint")),
|
|
876
|
-
]),
|
|
877
|
-
]),
|
|
1170
|
+
toggle("ui", "quiet", "ui.quiet", "ui.quiet.hint"),
|
|
1171
|
+
toggle("ui", "autoExpandOnce"),
|
|
1172
|
+
toggle("ui", "closeWithSession"),
|
|
1173
|
+
toggle("ui", "virtualCursor"),
|
|
1174
|
+
toggle("remoteView", "enabled", "remoteView.enabled", "remoteView.enabled.hint"),
|
|
878
1175
|
]),
|
|
879
|
-
|
|
880
|
-
section("browser.title", [
|
|
881
|
-
h("div", { key: "row", style: styles.row, className: "dsh-bb-row" }, [
|
|
882
|
-
h("label", { key: "l", style: styles.label }, [
|
|
883
|
-
h("span", { key: "t" }, t("browser.channel")),
|
|
884
|
-
h(Dropdown, {
|
|
885
|
-
key: "s",
|
|
886
|
-
label: t("browser.channel"),
|
|
887
|
-
value: settings.browser.channel,
|
|
888
|
-
disabled: busy,
|
|
889
|
-
onChange: value => patch({ browser: { channel: value } }),
|
|
890
|
-
options: [
|
|
891
|
-
{ value: "sidebar", label: t("browser.sidebar") },
|
|
892
|
-
{ value: "bundled", label: t("browser.bundled") },
|
|
893
|
-
{ value: "auto", label: t("browser.auto") },
|
|
894
|
-
{ value: "chrome", label: t("browser.chrome") },
|
|
895
|
-
{ value: "edge", label: t("browser.edge") },
|
|
896
|
-
],
|
|
897
|
-
}),
|
|
898
|
-
h("span", { key: "h", style: styles.hint }, t("browser.hint")),
|
|
899
|
-
]),
|
|
900
|
-
]),
|
|
901
|
-
]),
|
|
902
|
-
|
|
903
1176
|
section("actions.title", [
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
hintKey: "actions.allowExecute.hint",
|
|
909
|
-
checked: settings.actions.allowExecute,
|
|
910
|
-
busy,
|
|
911
|
-
onChange: value => patch({ actions: { allowExecute: value } }),
|
|
912
|
-
}),
|
|
913
|
-
h(Toggle, {
|
|
914
|
-
key: "allowDownload",
|
|
915
|
-
labelKey: "actions.allowDownload",
|
|
916
|
-
hintKey: "actions.allowDownload.hint",
|
|
917
|
-
checked: settings.actions.allowDownload,
|
|
918
|
-
busy,
|
|
919
|
-
onChange: value => patch({ actions: { allowDownload: value } }),
|
|
920
|
-
}),
|
|
921
|
-
h(Toggle, {
|
|
922
|
-
key: "allowCredentialWrite",
|
|
923
|
-
labelKey: "actions.allowCredentialWrite",
|
|
924
|
-
hintKey: "actions.allowCredentialWrite.hint",
|
|
925
|
-
checked: settings.actions.allowCredentialWrite,
|
|
926
|
-
busy,
|
|
927
|
-
onChange: value => patch({ actions: { allowCredentialWrite: value } }),
|
|
928
|
-
}),
|
|
1177
|
+
toggle("actions", "allowExecute"),
|
|
1178
|
+
toggle("actions", "allowDownload"),
|
|
1179
|
+
toggle("credentials", "allowRead"),
|
|
1180
|
+
toggle("actions", "allowCredentialWrite", "actions.allowCredentialWrite", "actions.allowCredentialWrite.hint"),
|
|
929
1181
|
]),
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1182
|
+
h("details", { key: "advanced", style: styles.group }, [
|
|
1183
|
+
h("summary", { key: "title", style: styles.groupTitle }, t("settings.advanced")),
|
|
1184
|
+
toggle("history", "enabled"),
|
|
1185
|
+
selector("vision.strategy", settings.vision.strategy, [
|
|
1186
|
+
{ value: "auto", label: t("vision.auto") },
|
|
1187
|
+
{ value: "nonVisual", label: t("vision.nonVisual") },
|
|
1188
|
+
], strategy => patch({ vision: { strategy } })),
|
|
1189
|
+
systemBrowser ? toggle("cookies", "persist", "browser.profile", "browser.profile.hint") : null,
|
|
1190
|
+
systemBrowser ? selector("browser.headless", settings.browser.headless ?? "auto",
|
|
1191
|
+
options("browser.headless.", ["auto", "windowed", "headless"]),
|
|
1192
|
+
headless => patch({ browser: { headless } }), "browser.headless.hint") : null,
|
|
1193
|
+
settings.delivery ? section("delivery.title", [
|
|
1194
|
+
h(DeliverySettings, {
|
|
1195
|
+
key: JSON.stringify(settings.delivery),
|
|
1196
|
+
delivery: settings.delivery,
|
|
1197
|
+
busy,
|
|
1198
|
+
onSave: delivery => patch({ delivery }),
|
|
1199
|
+
}),
|
|
1200
|
+
]) : null,
|
|
1201
|
+
meta.path !== "" ? h("p", { key: "path", style: styles.pathLine }, t("settings.details") + " · " + meta.path) : null,
|
|
940
1202
|
]),
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
// reloading the page — and a phone has no keyboard shortcut to reload with. The switch belongs
|
|
944
|
-
// here, and flipping it applies immediately (see `callSettings`).
|
|
945
|
-
section("remoteView.title", [
|
|
946
|
-
h(Toggle, {
|
|
947
|
-
key: "remoteViewEnabled",
|
|
948
|
-
labelKey: "remoteView.enabled",
|
|
949
|
-
hintKey: "remoteView.enabled.hint",
|
|
950
|
-
checked: settings.remoteView.enabled,
|
|
951
|
-
busy,
|
|
952
|
-
onChange: value => patch({ remoteView: { enabled: value } }),
|
|
953
|
-
}),
|
|
954
|
-
]),
|
|
955
|
-
|
|
956
|
-
h("div", { key: "status", style: styles.status }, [
|
|
957
|
-
saved ? h("span", { key: "s" }, t("saved")) : null,
|
|
1203
|
+
h("div", { key: "status", style: styles.status, role: "status" }, [
|
|
1204
|
+
busy || saved ? h("span", { key: "s" }, t(busy ? "settings.saving" : "saved")) : null,
|
|
958
1205
|
error !== "" ? h("span", { key: "e", style: styles.error }, ` ${t("failed")} ${error} `) : null,
|
|
959
|
-
error !== "" ? h("button", { key: "r", style: styles.button, onClick: load }, t("retry")) : null,
|
|
1206
|
+
error !== "" ? h("button", { key: "r", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
960
1207
|
]),
|
|
961
|
-
|
|
962
|
-
meta.path !== "" ? h("div", { key: "path", style: styles.pathLine }, `${t("path")}: ${meta.path}`) : null,
|
|
963
1208
|
])
|
|
964
1209
|
}
|
|
965
1210
|
|
|
@@ -1070,10 +1315,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1070
1315
|
}
|
|
1071
1316
|
|
|
1072
1317
|
/** Read this conversation's current guest, preferring the one actually drawn. */
|
|
1073
|
-
function guestStateFor(sessionId) {
|
|
1318
|
+
function guestStateFor(sessionId, tabId) {
|
|
1074
1319
|
const roots = panelRootsFor(sessionId)
|
|
1075
1320
|
if (roots === undefined ? tabStripFor(sessionId) === null : roots.length === 0) return { panel: false, guestId: null, url: "" }
|
|
1076
|
-
const guests = guestsInPanel(sessionId)
|
|
1321
|
+
const guests = guestsInPanel(sessionId).filter(view => tabId === undefined
|
|
1322
|
+
|| tabIdOfElement(view, new Set([tabId]), roots) === tabId)
|
|
1077
1323
|
if (guests.length === 0) return { panel: true, guestId: null, url: "" }
|
|
1078
1324
|
// A sidebar keeps every tab mounted (`keepMounted`), so a background tab's guest is
|
|
1079
1325
|
// in the tree too. Prefer the one with a drawn box; fall back to the newest.
|
|
@@ -1125,6 +1371,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1125
1371
|
*/
|
|
1126
1372
|
function installPanelService(ctx) {
|
|
1127
1373
|
let sidebarRight = null
|
|
1374
|
+
const pendingTabs = new Map()
|
|
1128
1375
|
/** The shell's own navigation service: `openSession` is how it is asked to DISPLAY a conversation. */
|
|
1129
1376
|
let uiWorkspace = null
|
|
1130
1377
|
// `inject` is how a client plugin waits for a service to appear. A host that does not offer it
|
|
@@ -1134,9 +1381,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1134
1381
|
// with it, which is exactly the shape of regression this file has been bitten by before.
|
|
1135
1382
|
if (typeof ctx.inject === "function") {
|
|
1136
1383
|
ctx.inject(["sidebarRight"], (scope) => {
|
|
1384
|
+
if (sidebarRight !== scope.sidebarRight) pendingTabs.clear()
|
|
1137
1385
|
sidebarRight = scope.sidebarRight
|
|
1138
1386
|
scope.effect(() => () => {
|
|
1139
|
-
if (sidebarRight === scope.sidebarRight)
|
|
1387
|
+
if (sidebarRight === scope.sidebarRight) {
|
|
1388
|
+
sidebarRight = null
|
|
1389
|
+
pendingTabs.clear()
|
|
1390
|
+
}
|
|
1140
1391
|
}, "dsh-builtin-browser: conversation panel binding")
|
|
1141
1392
|
})
|
|
1142
1393
|
// A separate inject, deliberately: waiting for both services in one call would take the
|
|
@@ -1149,28 +1400,11 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1149
1400
|
}, "dsh-builtin-browser: workspace binding")
|
|
1150
1401
|
})
|
|
1151
1402
|
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Ask the shell to DISPLAY the conversation a page was requested for.
|
|
1154
|
-
*
|
|
1155
|
-
* The shell renders the sidebar of the conversation it shows and no other, so a request from a
|
|
1156
|
-
* background conversation can place a tab but never grow a webview. The old answer was "show
|
|
1157
|
-
* that conversation and the page appears" — true, and a dependency on the human's timing.
|
|
1158
|
-
* `openSession` is the shell's own navigation for exactly this: the same call its own session
|
|
1159
|
-
* list makes, aimed at a session id, with no input event and no DOM touched.
|
|
1160
|
-
*
|
|
1161
|
-
* Only called when this conversation's panel DOM is absent, so it never fires for the
|
|
1162
|
-
* conversation the human is already reading, and never as a side effect of a read.
|
|
1163
|
-
*
|
|
1164
|
-
* @param sessionId - the conversation the page belongs to.
|
|
1165
|
-
* @param state - the panel read taken just before; `panel: true` means nothing to claim.
|
|
1166
|
-
* @returns whether the shell was asked to switch.
|
|
1167
|
-
*/
|
|
1168
1403
|
/**
|
|
1169
1404
|
* The conversation the shell is displaying, as the shell itself reports it.
|
|
1170
1405
|
*
|
|
1171
1406
|
* `undefined`/`null` means "the shell would not say" — an older shell, or one whose surface was
|
|
1172
|
-
* never minted.
|
|
1173
|
-
* direction: no navigation, no expand, nothing that could move a view it cannot identify.
|
|
1407
|
+
* never minted. Expansion requires a known owner, because it acts on the displayed surface.
|
|
1174
1408
|
* @returns the on-screen session id, or null.
|
|
1175
1409
|
*/
|
|
1176
1410
|
function onScreenSession() {
|
|
@@ -1182,8 +1416,8 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1182
1416
|
}
|
|
1183
1417
|
}
|
|
1184
1418
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1419
|
+
/** Display the owner of an explicit open request, including an already mounted hidden guest. */
|
|
1420
|
+
function claimConversation(sessionId) {
|
|
1187
1421
|
if (uiWorkspace === null || typeof uiWorkspace.openSession !== "function") return false
|
|
1188
1422
|
// Already displayed? Then the shell needs no navigation: the panel simply has not been opened
|
|
1189
1423
|
// yet, and `revealPlacedPanel` opens it. Re-opening the conversation a human is reading would
|
|
@@ -1220,12 +1454,12 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1220
1454
|
* so passing it a tab id from another conversation's list cannot move that view.
|
|
1221
1455
|
*
|
|
1222
1456
|
* @param sessionId - the conversation whose page was just placed.
|
|
1223
|
-
*
|
|
1457
|
+
* A live guest may remain mounted while its column is folded, so it still needs this step.
|
|
1224
1458
|
* @returns what was asked for, so a caller can tell "expanded" from "already visible", and
|
|
1225
1459
|
* `displayed` so it can tell "the shell is showing this conversation" from "it is not".
|
|
1226
1460
|
*/
|
|
1227
|
-
function revealPlacedPanel(sessionId,
|
|
1228
|
-
if (
|
|
1461
|
+
function revealPlacedPanel(sessionId, tabId) {
|
|
1462
|
+
if (sidebarRight === null) return {}
|
|
1229
1463
|
const done = {}
|
|
1230
1464
|
// Which conversation is the shell DISPLAYING? `screen()` answers it, and it is the question
|
|
1231
1465
|
// that decides whether an expand call is safe: `toggleExpanded()` acts on the on-screen
|
|
@@ -1262,7 +1496,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1262
1496
|
}
|
|
1263
1497
|
try {
|
|
1264
1498
|
const tabs = typeof sidebarRight.tabsIn === "function" ? sidebarRight.tabsIn(sessionId) : []
|
|
1265
|
-
const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser") : undefined
|
|
1499
|
+
const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser" && entry.id === tabId) : undefined
|
|
1266
1500
|
if (page !== undefined && typeof sidebarRight.focus === "function") {
|
|
1267
1501
|
sidebarRight.focus(page.id)
|
|
1268
1502
|
done.focused = String(page.id)
|
|
@@ -1273,9 +1507,97 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1273
1507
|
return done
|
|
1274
1508
|
}
|
|
1275
1509
|
|
|
1510
|
+
function viewKey(sessionId, viewId) {
|
|
1511
|
+
return JSON.stringify([sessionId, viewId])
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
/** Bind each logical view to one native tab; URLs can change without changing that identity. */
|
|
1515
|
+
function openViewPanel(sessionId, address, viewId, guestId) {
|
|
1516
|
+
const key = viewKey(sessionId, viewId)
|
|
1517
|
+
const switched = claimConversation(sessionId)
|
|
1518
|
+
let tabs
|
|
1519
|
+
try { tabs = Array.from(sidebarRight.tabsIn(sessionId)) }
|
|
1520
|
+
catch { return { ok: false, reason: "the shell cannot list this conversation's tabs", panel: false, guestId: null, ...switched ? { switched: true } : {} } }
|
|
1521
|
+
const browsers = tabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser" && typeof tab.id === "string")
|
|
1522
|
+
const allowed = new Set(browsers.map(tab => tab.id))
|
|
1523
|
+
const roots = panelRootsFor(sessionId)
|
|
1524
|
+
const owned = new Set(Array.from(pendingTabs.entries())
|
|
1525
|
+
.filter(([otherKey, binding]) => otherKey !== key && binding.sessionId === sessionId)
|
|
1526
|
+
.map(([, binding]) => binding.id))
|
|
1527
|
+
let binding = pendingTabs.get(key)
|
|
1528
|
+
if (binding !== undefined && !allowed.has(binding.id)) {
|
|
1529
|
+
// A missing store while the conversation mounts is temporary. Keep its identity until the
|
|
1530
|
+
// store is readable again; a nonempty store proves that the original tab actually closed.
|
|
1531
|
+
if (tabs.length === 0 && onScreenSession() !== sessionId) {
|
|
1532
|
+
return { ok: false, reason: "this conversation's sidebar is not mounted", panel: false, guestId: null, ...switched ? { switched: true } : {} }
|
|
1533
|
+
}
|
|
1534
|
+
pendingTabs.delete(key)
|
|
1535
|
+
binding = undefined
|
|
1536
|
+
}
|
|
1537
|
+
const guests = guestsInPanel(sessionId)
|
|
1538
|
+
const hasCachedGuest = Number.isInteger(guestId) && guestId > 0
|
|
1539
|
+
if (binding === undefined && hasCachedGuest) {
|
|
1540
|
+
const cached = guests.find(view => view.getWebContentsId() === guestId)
|
|
1541
|
+
if (cached !== undefined) {
|
|
1542
|
+
const id = tabIdOfElement(cached, allowed, roots)
|
|
1543
|
+
if (id === null || owned.has(id)) {
|
|
1544
|
+
return { ok: false, reason: "the requested guest cannot be assigned to this browser view", panel: true, guestId: null }
|
|
1545
|
+
}
|
|
1546
|
+
binding = { sessionId, id, url: address, scoped: true }
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
if (binding === undefined && !hasCachedGuest) {
|
|
1550
|
+
// Adopt only an unclaimed guest whose native tab can be proved. Multiple visible guests
|
|
1551
|
+
// are ambiguous (split panes); creating a tab is safer than choosing by list order.
|
|
1552
|
+
const candidates = guests.map(view => ({ view, id: tabIdOfElement(view, allowed, roots) }))
|
|
1553
|
+
.filter(candidate => candidate.id !== null && !owned.has(candidate.id))
|
|
1554
|
+
const drawn = candidates.filter(({ view }) => {
|
|
1555
|
+
const rect = view.getBoundingClientRect()
|
|
1556
|
+
return rect.width > 0 && rect.height > 0
|
|
1557
|
+
})
|
|
1558
|
+
const candidate = drawn.length === 1 ? drawn[0] : candidates.length === 1 ? candidates[0] : undefined
|
|
1559
|
+
if (candidate !== undefined) binding = { sessionId, id: candidate.id, url: address, scoped: true }
|
|
1560
|
+
}
|
|
1561
|
+
let created = false
|
|
1562
|
+
if (binding === undefined) {
|
|
1563
|
+
const before = new Set(tabs.map(tab => tab.id))
|
|
1564
|
+
try { sidebarRight.openTabIn(sessionId, "browser", address ? { params: { url: address } } : {}) }
|
|
1565
|
+
catch (error) { return { ok: false, reason: String(error?.message ?? error), panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null } }
|
|
1566
|
+
let placed
|
|
1567
|
+
try { placed = Array.from(sidebarRight.tabsIn(sessionId)) }
|
|
1568
|
+
catch { placed = [] }
|
|
1569
|
+
const added = placed.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser"
|
|
1570
|
+
&& typeof tab.id === "string" && !before.has(tab.id) && !owned.has(tab.id))
|
|
1571
|
+
if (added.length !== 1) {
|
|
1572
|
+
return {
|
|
1573
|
+
ok: false,
|
|
1574
|
+
reason: placed.length === 0 ? "this conversation's sidebar is not mounted" : "the shell did not identify a new browser tab for this view",
|
|
1575
|
+
panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0,
|
|
1576
|
+
guestId: null,
|
|
1577
|
+
...switched ? { switched: true } : {},
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
binding = { sessionId, id: added[0].id, url: address, scoped: true }
|
|
1581
|
+
created = true
|
|
1582
|
+
}
|
|
1583
|
+
pendingTabs.set(key, binding)
|
|
1584
|
+
const state = guestStateFor(sessionId, binding.id)
|
|
1585
|
+
return {
|
|
1586
|
+
ok: true,
|
|
1587
|
+
created,
|
|
1588
|
+
panel: state.panel,
|
|
1589
|
+
guestId: state.guestId,
|
|
1590
|
+
url: state.url,
|
|
1591
|
+
tabId: binding.id,
|
|
1592
|
+
...switched ? { switched: true } : {},
|
|
1593
|
+
...revealPlacedPanel(sessionId, binding.id),
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1276
1597
|
const api = {
|
|
1598
|
+
panelProtocol: 3,
|
|
1277
1599
|
/** @returns what happened: an existing guest, a newly opened tab, or a named refusal. */
|
|
1278
|
-
openPanel(sessionId, url) {
|
|
1600
|
+
openPanel(sessionId, url, options) {
|
|
1279
1601
|
const wanted = typeof sessionId === "string" ? sessionId : ""
|
|
1280
1602
|
if (!/^session-/.test(wanted)) {
|
|
1281
1603
|
return { ok: false, reason: "not a conversation id: " + JSON.stringify(sessionId), panel: false, guestId: null }
|
|
@@ -1283,9 +1605,26 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1283
1605
|
if (sidebarRight === null || typeof sidebarRight.openTabIn !== "function") {
|
|
1284
1606
|
return { ok: false, reason: "the shell's sidebar service is not available", panel: false, guestId: null }
|
|
1285
1607
|
}
|
|
1286
|
-
const
|
|
1608
|
+
const address = url ? String(url) : ""
|
|
1609
|
+
if (typeof options?.viewId === "string" && options.viewId !== "") {
|
|
1610
|
+
return openViewPanel(wanted, address, options.viewId, options.guestId)
|
|
1611
|
+
}
|
|
1612
|
+
const pending = pendingTabs.get(wanted)
|
|
1613
|
+
const state = guestStateFor(wanted, pending?.url === address && pending.scoped ? pending.id : undefined)
|
|
1614
|
+
// Explicit opening also reveals a guest kept mounted in a collapsed or hidden sidebar.
|
|
1615
|
+
// Passive panelGuest/panelGuests reads never call either presentation helper.
|
|
1616
|
+
const switched = claimConversation(wanted)
|
|
1287
1617
|
if (state.guestId !== null) {
|
|
1288
|
-
|
|
1618
|
+
const revealed = revealPlacedPanel(wanted, pending?.url === address ? pending.id : undefined)
|
|
1619
|
+
return {
|
|
1620
|
+
ok: true,
|
|
1621
|
+
created: false,
|
|
1622
|
+
panel: true,
|
|
1623
|
+
guestId: state.guestId,
|
|
1624
|
+
url: state.url,
|
|
1625
|
+
...switched ? { switched: true } : {},
|
|
1626
|
+
...revealed,
|
|
1627
|
+
}
|
|
1289
1628
|
}
|
|
1290
1629
|
// No panel DOM for this conversation means the shell is not DISPLAYING it, and no tab placed
|
|
1291
1630
|
// here can ever grow a webview: the shell renders one sidebar, for the conversation it shows.
|
|
@@ -1293,7 +1632,6 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1293
1632
|
// their timing. Ask the shell instead — `openSession` is its own navigation, one call on its
|
|
1294
1633
|
// own workspace service, no input events — and report `switched` so the caller can retry one
|
|
1295
1634
|
// render later instead of reporting a dead carrier.
|
|
1296
|
-
const switched = claimConversation(wanted, state)
|
|
1297
1635
|
// A mounted panel is NOT required to place a tab.
|
|
1298
1636
|
//
|
|
1299
1637
|
// `openTabIn` acts on the conversation's own surface store, and the sidebar-right service
|
|
@@ -1303,15 +1641,37 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1303
1641
|
// (a public method) is what says whether it actually landed: `openTabIn` SILENTLY ignores a
|
|
1304
1642
|
// conversation whose store was never minted, and a silent no-op must never be reported as
|
|
1305
1643
|
// success.
|
|
1306
|
-
let
|
|
1307
|
-
try {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1644
|
+
let beforeTabs = []
|
|
1645
|
+
try { beforeTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
1646
|
+
const before = beforeTabs.length
|
|
1647
|
+
const beforeIds = new Set(beforeTabs.map(tab => tab.id))
|
|
1648
|
+
const remembered = pending?.url === address
|
|
1649
|
+
? beforeTabs.find(tab => tab.kind === "browser" && tab.id === pending.id)
|
|
1650
|
+
: undefined
|
|
1651
|
+
if (remembered === undefined) {
|
|
1652
|
+
try {
|
|
1653
|
+
sidebarRight.openTabIn(wanted, "browser", address ? { params: { url: address } } : {})
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
return { ok: false, reason: String((error && error.message) || error), panel: state.panel, guestId: null }
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
let placedTabs = beforeTabs
|
|
1659
|
+
try { placedTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
1660
|
+
const placed = placedTabs.length
|
|
1661
|
+
const browserTabs = placedTabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser")
|
|
1662
|
+
const added = browserTabs.filter(tab => !beforeIds.has(tab.id))
|
|
1663
|
+
const matching = browserTabs.filter(tab => address !== "" && (tab.params?.url === address || tab.url === address))
|
|
1664
|
+
// Multiple browser tabs use separate ids. Correlate this placement before revealing it.
|
|
1665
|
+
// Older shells deduplicate the browser kind, so their sole browser is unambiguous.
|
|
1666
|
+
const page = remembered
|
|
1667
|
+
?? (added.length === 1 ? added[0] : undefined)
|
|
1668
|
+
?? (matching.length === 1 ? matching[0] : undefined)
|
|
1669
|
+
?? (browserTabs.length === 1 ? browserTabs[0] : undefined)
|
|
1670
|
+
const scoped = browserTabs.length > 1 || panelRootsFor(wanted) !== undefined
|
|
1671
|
+
if (page !== undefined) pendingTabs.set(wanted, { id: page.id, url: address, scoped })
|
|
1672
|
+
if (page === undefined && browserTabs.length > 1) {
|
|
1673
|
+
return { ok: false, reason: "the shell did not identify which browser tab was placed", panel: state.panel, guestId: null }
|
|
1312
1674
|
}
|
|
1313
|
-
let placed = 0
|
|
1314
|
-
try { placed = sidebarRight.tabsIn(wanted).length } catch (error) { placed = before }
|
|
1315
1675
|
// `openTabIn` DEDUPLICATES, so "the count grew" is the wrong test for "is this
|
|
1316
1676
|
// conversation's surface mounted".
|
|
1317
1677
|
//
|
|
@@ -1346,20 +1706,33 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1346
1706
|
// Placing is not showing: ask the shell to expand the column and focus that tab, so the
|
|
1347
1707
|
// body (and with it the `<webview>`) actually gets created. Without this the caller polls
|
|
1348
1708
|
// a panel that can never answer, which is exactly what "produced no page" used to mean.
|
|
1349
|
-
const revealed = revealPlacedPanel(wanted,
|
|
1709
|
+
const revealed = revealPlacedPanel(wanted, page?.id)
|
|
1350
1710
|
return {
|
|
1351
1711
|
ok: true,
|
|
1352
1712
|
created: placed > before,
|
|
1353
1713
|
panel: state.panel,
|
|
1354
1714
|
guestId: null,
|
|
1355
1715
|
tabs: placed,
|
|
1716
|
+
...page === undefined || !scoped ? {} : { tabId: String(page.id) },
|
|
1356
1717
|
...switched ? { switched: true } : {},
|
|
1357
1718
|
...revealed,
|
|
1358
1719
|
}
|
|
1359
1720
|
},
|
|
1360
1721
|
/** Read-only: this conversation's current guest, if it has one. */
|
|
1361
|
-
panelGuest(sessionId) {
|
|
1362
|
-
|
|
1722
|
+
panelGuest(sessionId, tabId, options) {
|
|
1723
|
+
if (typeof options?.viewId === "string" && options.viewId !== "") {
|
|
1724
|
+
const bound = pendingTabs.get(viewKey(sessionId, options.viewId))
|
|
1725
|
+
const intended = typeof tabId === "string" && tabId !== "" ? tabId : bound?.id
|
|
1726
|
+
if (intended === undefined || (bound !== undefined && bound.id !== intended)) {
|
|
1727
|
+
const roots = panelRootsFor(sessionId)
|
|
1728
|
+
return { panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null, url: "" }
|
|
1729
|
+
}
|
|
1730
|
+
return guestStateFor(sessionId, intended)
|
|
1731
|
+
}
|
|
1732
|
+
return guestStateFor(
|
|
1733
|
+
typeof sessionId === "string" ? sessionId : "",
|
|
1734
|
+
typeof tabId === "string" && tabId !== "" ? tabId : undefined,
|
|
1735
|
+
)
|
|
1363
1736
|
},
|
|
1364
1737
|
/** All guest ids verified inside this conversation, including shell-created popup tabs. */
|
|
1365
1738
|
panelGuests(sessionId) {
|
|
@@ -1454,9 +1827,13 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1454
1827
|
const head = make("header", "dsh-bw-watch-head")
|
|
1455
1828
|
const title = make("span", "dsh-bw-watch-title")
|
|
1456
1829
|
const state = make("span", "dsh-bw-watch-state")
|
|
1830
|
+
/** Only visible when the host reports more than one session to watch. */
|
|
1831
|
+
const sessionSelect = make("select", "dsh-bw-watch-session")
|
|
1832
|
+
sessionSelect.hidden = true
|
|
1457
1833
|
const closeButton = make("button", "dsh-bw-watch-close", "×")
|
|
1458
1834
|
closeButton.setAttribute("type", "button")
|
|
1459
1835
|
head.appendChild(title)
|
|
1836
|
+
head.appendChild(sessionSelect)
|
|
1460
1837
|
head.appendChild(state)
|
|
1461
1838
|
head.appendChild(closeButton)
|
|
1462
1839
|
|
|
@@ -1508,6 +1885,8 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1508
1885
|
readonlyLabel.textContent = say("watch.readOnly")
|
|
1509
1886
|
stopButton.textContent = say("watch.stop")
|
|
1510
1887
|
openButton.title = say("watch.open")
|
|
1888
|
+
sessionSelect.title = say("watch.session")
|
|
1889
|
+
sessionSelect.setAttribute("aria-label", say("watch.session"))
|
|
1511
1890
|
}
|
|
1512
1891
|
relabel()
|
|
1513
1892
|
// A runtime language switch must reach labels that are already on screen. `subscribe` fires on
|
|
@@ -1530,8 +1909,17 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1530
1909
|
layer.remove()
|
|
1531
1910
|
}
|
|
1532
1911
|
|
|
1533
|
-
/**
|
|
1534
|
-
|
|
1912
|
+
/**
|
|
1913
|
+
* One running view. `generation` is the identity of a single watching run: a stop, a session
|
|
1914
|
+
* switch and a reopen all advance it, so a request already in flight can never paint into the
|
|
1915
|
+
* new run or resurrect a second scheduling chain.
|
|
1916
|
+
*/
|
|
1917
|
+
const view = {
|
|
1918
|
+
session: undefined, timer: undefined, running: false, lastAt: 0, objectUrl: undefined,
|
|
1919
|
+
generation: 0, controller: undefined,
|
|
1920
|
+
}
|
|
1921
|
+
/** Guards the async probe: two clicks in the same tick must not both reach start(). */
|
|
1922
|
+
let starting = false
|
|
1535
1923
|
|
|
1536
1924
|
const setState = text => { state.textContent = text }
|
|
1537
1925
|
const showNote = text => {
|
|
@@ -1546,12 +1934,21 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1546
1934
|
view.objectUrl = undefined
|
|
1547
1935
|
}
|
|
1548
1936
|
}
|
|
1549
|
-
|
|
1937
|
+
/** End one generation: cancel its request, timer and frame, without touching the panel chrome. */
|
|
1938
|
+
const cancelLoop = () => {
|
|
1550
1939
|
view.running = false
|
|
1940
|
+
view.generation += 1
|
|
1941
|
+
if (view.controller !== undefined) {
|
|
1942
|
+
try { view.controller.abort() } catch { /* an already settled controller is harmless */ }
|
|
1943
|
+
view.controller = undefined
|
|
1944
|
+
}
|
|
1551
1945
|
if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
|
|
1552
1946
|
dropFrame()
|
|
1553
1947
|
img.removeAttribute("src")
|
|
1554
1948
|
img.hidden = true
|
|
1949
|
+
}
|
|
1950
|
+
const stop = () => {
|
|
1951
|
+
cancelLoop()
|
|
1555
1952
|
setState(say("watch.stopped"))
|
|
1556
1953
|
showNote(say("watch.stopped"))
|
|
1557
1954
|
panel.hidden = true
|
|
@@ -1569,34 +1966,55 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1569
1966
|
}
|
|
1570
1967
|
}
|
|
1571
1968
|
|
|
1969
|
+
/** Show the sessions the host handed out, so a later-created one can actually be chosen. */
|
|
1970
|
+
const fillSessions = sessions => {
|
|
1971
|
+
// Clearing via innerHTML is the one exception to "build element by element": it removes
|
|
1972
|
+
// options, it does not parse markup, and a stale option list would keep a dead session on screen.
|
|
1973
|
+
sessionSelect.innerHTML = ""
|
|
1974
|
+
for (let index = 0; index < sessions.length; index += 1) {
|
|
1975
|
+
const id = String(sessions[index])
|
|
1976
|
+
const option = make("option")
|
|
1977
|
+
option.setAttribute("value", id)
|
|
1978
|
+
const short = id.length > 24 ? `${id.slice(0, 15)}…${id.slice(-6)}` : id
|
|
1979
|
+
option.textContent = `#${index + 1} ${short}`
|
|
1980
|
+
sessionSelect.appendChild(option)
|
|
1981
|
+
}
|
|
1982
|
+
sessionSelect.hidden = sessions.length < 2
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1572
1985
|
/**
|
|
1573
1986
|
* Pull frames until stopped. One request in flight at a time, and the next one is scheduled only
|
|
1574
1987
|
* after the current image has painted — that is what makes a slow link degrade into fewer
|
|
1575
|
-
* frames rather than a growing queue.
|
|
1988
|
+
* frames rather than a growing queue. `gen` is captured once per run and re-checked after every
|
|
1989
|
+
* await: a frame belonging to a superseded run is dropped instead of painted.
|
|
1576
1990
|
*/
|
|
1577
|
-
const pump = async
|
|
1578
|
-
if (!view.running) return
|
|
1991
|
+
const pump = async gen => {
|
|
1992
|
+
if (!view.running || gen !== view.generation) return
|
|
1579
1993
|
if (document.visibilityState === "hidden") {
|
|
1580
1994
|
// The design's rule: a hidden panel stops pulling immediately. Resuming is the user's
|
|
1581
1995
|
// action, not a timer's.
|
|
1582
1996
|
setState(say("watch.paused"))
|
|
1583
1997
|
showNote(say("watch.paused"))
|
|
1584
|
-
view.timer = setTimeout(pump, MIN_INTERVAL_MS * 4)
|
|
1998
|
+
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS * 4)
|
|
1585
1999
|
return
|
|
1586
2000
|
}
|
|
1587
2001
|
const waited = Date.now() - view.lastAt
|
|
1588
2002
|
if (waited < MIN_INTERVAL_MS) {
|
|
1589
|
-
view.timer = setTimeout(pump, MIN_INTERVAL_MS - waited)
|
|
2003
|
+
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS - waited)
|
|
1590
2004
|
return
|
|
1591
2005
|
}
|
|
1592
2006
|
view.lastAt = Date.now()
|
|
1593
2007
|
let nextDelay = MIN_INTERVAL_MS
|
|
2008
|
+
const controller = view.controller
|
|
1594
2009
|
try {
|
|
1595
2010
|
const url = `${FRAME}?session=${encodeURIComponent(String(view.session))}`
|
|
1596
|
-
const
|
|
1597
|
-
if (
|
|
2011
|
+
const init = { headers: { accept: "image/jpeg" } }
|
|
2012
|
+
if (controller !== undefined) init.signal = controller.signal
|
|
2013
|
+
const response = await fetch(url, init)
|
|
2014
|
+
if (!view.running || gen !== view.generation) return
|
|
1598
2015
|
if (!response.ok) {
|
|
1599
2016
|
const body = await response.json().catch(() => undefined)
|
|
2017
|
+
if (!view.running || gen !== view.generation) return
|
|
1600
2018
|
setState(say("watch.paused"))
|
|
1601
2019
|
showNote(body?.error === "remote-view-disabled"
|
|
1602
2020
|
? say("watch.disabled")
|
|
@@ -1607,7 +2025,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1607
2025
|
nextDelay = MIN_INTERVAL_MS * 4
|
|
1608
2026
|
} else {
|
|
1609
2027
|
const blob = await response.blob()
|
|
1610
|
-
if (!view.running) return
|
|
2028
|
+
if (!view.running || gen !== view.generation) return
|
|
1611
2029
|
const painted = new Promise(resolve => {
|
|
1612
2030
|
img.onload = () => resolve()
|
|
1613
2031
|
img.onerror = () => resolve()
|
|
@@ -1618,43 +2036,70 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1618
2036
|
img.hidden = false
|
|
1619
2037
|
note.hidden = true
|
|
1620
2038
|
await painted
|
|
1621
|
-
if (!view.running) return
|
|
2039
|
+
if (!view.running || gen !== view.generation) return
|
|
1622
2040
|
setState(say("watch.live"))
|
|
1623
2041
|
}
|
|
1624
2042
|
} catch {
|
|
1625
|
-
if (!view.running) return
|
|
2043
|
+
if (!view.running || gen !== view.generation) return
|
|
1626
2044
|
setState(say("watch.disconnected"))
|
|
1627
2045
|
showNote(say("watch.disconnected"))
|
|
1628
2046
|
nextDelay = MIN_INTERVAL_MS * 4
|
|
1629
2047
|
}
|
|
1630
|
-
if (view.running) view.timer = setTimeout(pump, nextDelay)
|
|
2048
|
+
if (view.running && gen === view.generation) view.timer = setTimeout(() => pump(gen), nextDelay)
|
|
1631
2049
|
}
|
|
1632
2050
|
|
|
1633
2051
|
const start = async session => {
|
|
2052
|
+
cancelLoop()
|
|
1634
2053
|
view.session = session
|
|
1635
2054
|
view.running = true
|
|
1636
2055
|
view.lastAt = 0
|
|
2056
|
+
view.controller = typeof AbortController === "function" ? new AbortController() : undefined
|
|
2057
|
+
const gen = view.generation
|
|
1637
2058
|
panel.hidden = false
|
|
1638
2059
|
setState(say("watch.connecting"))
|
|
1639
2060
|
showNote(say("watch.connecting"))
|
|
1640
|
-
await pump()
|
|
2061
|
+
await pump(gen)
|
|
1641
2062
|
}
|
|
1642
2063
|
|
|
2064
|
+
/**
|
|
2065
|
+
* The session a viewer most likely means when the host cannot name the current conversation:
|
|
2066
|
+
* the newest session it created, rather than always the first entry of the map.
|
|
2067
|
+
*/
|
|
2068
|
+
const preferredSession = sessions => sessions[sessions.length - 1]
|
|
2069
|
+
|
|
1643
2070
|
openButton.addEventListener("click", () => {
|
|
1644
2071
|
void (async () => {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
2072
|
+
if (view.running || starting) return
|
|
2073
|
+
starting = true
|
|
2074
|
+
try {
|
|
2075
|
+
const found = await probe()
|
|
2076
|
+
if (!found.enabled) { showNote(say("watch.disabled")); panel.hidden = false; return }
|
|
2077
|
+
if (found.sessions.length === 0) { showNote(say("watch.noPage")); panel.hidden = false; return }
|
|
2078
|
+
fillSessions(found.sessions)
|
|
2079
|
+
sessionSelect.value = String(preferredSession(found.sessions))
|
|
2080
|
+
const chosen = sessionSelect.value
|
|
2081
|
+
// Release before start(): the first frame may take a long time (or never arrive), and
|
|
2082
|
+
// holding the guard until then would also block a legitimate stop-then-reopen.
|
|
2083
|
+
// There is no await between here and start(), whose synchronous part sets view.running.
|
|
2084
|
+
starting = false
|
|
2085
|
+
await start(chosen)
|
|
2086
|
+
} finally { starting = false }
|
|
1649
2087
|
})()
|
|
1650
2088
|
})
|
|
2089
|
+
// Switching sessions replaces the run; it never adds a second loop alongside the live one.
|
|
2090
|
+
sessionSelect.addEventListener("change", () => {
|
|
2091
|
+
if (!view.running) return
|
|
2092
|
+
const chosen = sessionSelect.value
|
|
2093
|
+
if (typeof chosen === "string" && chosen !== "") void start(chosen)
|
|
2094
|
+
})
|
|
1651
2095
|
closeButton.addEventListener("click", stop)
|
|
1652
2096
|
stopButton.addEventListener("click", stop)
|
|
1653
2097
|
// A panel hidden by a closed button must not keep pulling frames.
|
|
1654
2098
|
document.addEventListener("visibilitychange", () => {
|
|
1655
2099
|
if (document.visibilityState === "hidden" && view.running) {
|
|
1656
2100
|
if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
|
|
1657
|
-
|
|
2101
|
+
const gen = view.generation
|
|
2102
|
+
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS)
|
|
1658
2103
|
}
|
|
1659
2104
|
})
|
|
1660
2105
|
|
|
@@ -1740,6 +2185,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1740
2185
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-builtin-browser: dictionaries")
|
|
1741
2186
|
const t = ctx.locale.bind(NS)
|
|
1742
2187
|
translate = t
|
|
2188
|
+
updateCurrentLocale(ctx.locale)
|
|
1743
2189
|
// A language switch has to reach text that is already on screen. `subscribe` fires on every
|
|
1744
2190
|
// locale snapshot change (switch, and late dictionary registration); guarded, because a host
|
|
1745
2191
|
// without it must still get the panel — the labels then simply keep their first language.
|
|
@@ -1747,6 +2193,7 @@ window.__ModuleLoader__.load({ id: "dsh-builtin-browser", factory: (require) =>
|
|
|
1747
2193
|
ctx.effect(() => {
|
|
1748
2194
|
const off = ctx.locale.subscribe(() => {
|
|
1749
2195
|
translate = ctx.locale.bind(NS)
|
|
2196
|
+
updateCurrentLocale(ctx.locale)
|
|
1750
2197
|
// Two audiences, one notification: the vanilla watch panel rewrites its own text, and the
|
|
1751
2198
|
// React settings section re-renders (see `useLocaleVersion`). Bumping the counter here is
|
|
1752
2199
|
// what makes `t()` inside a mounted component return the new language at all.
|