@ds-hu/dsh-tailcat-remote 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +33 -0
- package/README.en.md +115 -0
- package/README.md +114 -2
- package/client.js +1205 -0
- package/cordis.patch.yml +39 -0
- package/docs/CONTRACT.md +186 -0
- package/docs/SECURITY.md +97 -0
- package/docs/TECHNICAL.md +156 -0
- package/docs/screenshots/01-pairing.png +0 -0
- package/docs/screenshots/02-security.png +0 -0
- package/docs/screenshots/03-install.png +0 -0
- package/icon.svg +18 -0
- package/index.js +34 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +78 -4
- package/src/config.js +130 -0
- package/src/control.js +84 -0
- package/src/devices.js +153 -0
- package/src/door.js +472 -0
- package/src/errors.js +24 -0
- package/src/installer.js +824 -0
- package/src/parse.js +241 -0
- package/src/paths.js +109 -0
- package/src/qr.js +61 -0
- package/src/remote.js +272 -0
- package/src/tailcat.js +715 -0
- package/vendor/qrcode.mjs +2289 -0
package/client.js
ADDED
|
@@ -0,0 +1,1205 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: '@ds-hu/dsh-tailcat-remote',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
const { useCallback, useEffect, useMemo, useState } = React;
|
|
7
|
+
|
|
8
|
+
const NS = 'tailcat-remote';
|
|
9
|
+
const API = '/api/tailcat-remote';
|
|
10
|
+
|
|
11
|
+
const zh = {
|
|
12
|
+
nav: '远程访问',
|
|
13
|
+
title: '远程访问',
|
|
14
|
+
subtitle: '通过 tailcat 从任意地点访问本 Harness,无需开放公网端口,也无需调整入站防火墙。',
|
|
15
|
+
refresh: '刷新',
|
|
16
|
+
loading: '正在读取远程访问状态…',
|
|
17
|
+
statusLabel: '隧道',
|
|
18
|
+
statusOnline: '运行中',
|
|
19
|
+
statusStarting: '启动中',
|
|
20
|
+
statusRestarting: '等待重启',
|
|
21
|
+
statusStopping: '停止中',
|
|
22
|
+
statusStopped: '已停止',
|
|
23
|
+
statusError: '异常',
|
|
24
|
+
statusUnknown: '未知',
|
|
25
|
+
start: '启动',
|
|
26
|
+
stop: '停止',
|
|
27
|
+
restart: '重启',
|
|
28
|
+
rotating: '正在更换…',
|
|
29
|
+
rotate: '更换地址',
|
|
30
|
+
rotateArm: '确认更换地址?',
|
|
31
|
+
rotateConfirm: '确认,立即更换',
|
|
32
|
+
cancel: '取消',
|
|
33
|
+
rotateHint: '旧的 tailcat 密钥会被覆盖,隧道重新启动,旧地址立即失效。',
|
|
34
|
+
rotateCaveat: '更换 tailcat 地址不会让已持有 DSH 浏览器会话凭据的浏览器退出登录;这些凭据到期或从浏览器会话记录中移除后才失效。',
|
|
35
|
+
rotateDisconnect: '如果你正通过 tailcat 打开本页,更换、停止或保存设备列表都会断开当前页面;请在本机页面操作,或用新地址重新连接。',
|
|
36
|
+
qrUnavailable: '二维码生成失败,请直接复制上方地址。',
|
|
37
|
+
copy: '复制',
|
|
38
|
+
copied: '已复制',
|
|
39
|
+
copyFailed: '复制失败,请手动选择文本。',
|
|
40
|
+
showQr: '显示二维码',
|
|
41
|
+
hideQr: '隐藏二维码',
|
|
42
|
+
pairingTitle: '配对这台 Harness',
|
|
43
|
+
pairingHint: '在承载隧道的设备上运行下面的命令,然后用该设备的浏览器打开本地地址。',
|
|
44
|
+
addressLabel: 'tailcat 地址',
|
|
45
|
+
commandLabel: '客户端设备命令',
|
|
46
|
+
commandHint: '客户端绑定 {localPort} 端口,Harness 位于虚拟端口 {port}。',
|
|
47
|
+
openLocal: '打开本地地址',
|
|
48
|
+
localUrlHint: '隧道建立后,这个地址会走一次正常的 DSH 登录流程,之后沿用浏览器会话 Cookie。',
|
|
49
|
+
stepsTitle: '使用步骤',
|
|
50
|
+
stepInstall: '在客户端设备安装 tailcat。',
|
|
51
|
+
stepRun: '运行下面的命令,或扫描二维码把地址带到那台设备。',
|
|
52
|
+
stepOpen: '在客户端浏览器打开 http://127.0.0.1:{localPort}/。',
|
|
53
|
+
installHint: '插件可以自动安装 tailcat;如果自动安装不可用,也可以从 GitHub Release 手动安装并设置 binaryPath。',
|
|
54
|
+
securityTitle: '安全',
|
|
55
|
+
allowOffTitle: '地址就是唯一的钥匙',
|
|
56
|
+
allowOffBody: '任何拿到 tailcat 地址的人都能访问本 Harness。在下方添加至少一个客户端公钥后,访问才会限制在已配对设备。',
|
|
57
|
+
allowOnTitle: '已限制 {count} 台设备',
|
|
58
|
+
allowOnBody: '不在列表中的客户端会被 tailcat 拒绝。地址仍然需要,但不再足够。',
|
|
59
|
+
devicesLabel: '允许的客户端公钥',
|
|
60
|
+
devicesHint: '每行一个 nodekey。在客户端运行 tailcat genkey --client --key=client-default 创建密钥并打印公钥。',
|
|
61
|
+
devicesPlaceholder: 'nodekey:…',
|
|
62
|
+
devicesSave: '保存并应用',
|
|
63
|
+
devicesReset: '撤销修改',
|
|
64
|
+
devicesSaved: '设备列表已保存,tailcat 已重启生效。',
|
|
65
|
+
devicesEmpty: '还没有设备密钥,当前仅凭地址访问。',
|
|
66
|
+
deviceCount: '{count} 台已授权',
|
|
67
|
+
devicesGenerate: '在客户端设备生成密钥:',
|
|
68
|
+
diagnosticsTitle: '状态与诊断',
|
|
69
|
+
diagPhase: '状态',
|
|
70
|
+
diagAddressMode: '密钥模式',
|
|
71
|
+
diagKeyName: '密钥名',
|
|
72
|
+
diagVersion: 'tailcat 版本',
|
|
73
|
+
diagBinary: '可执行文件',
|
|
74
|
+
diagRegion: '中继区域',
|
|
75
|
+
diagRestarts: '自动重启',
|
|
76
|
+
diagDoor: '门',
|
|
77
|
+
diagTarget: '转发目标',
|
|
78
|
+
diagLastError: '最近错误',
|
|
79
|
+
diagWarnings: '警告',
|
|
80
|
+
recentTitle: '最近连接',
|
|
81
|
+
recentEmpty: '暂无连接记录。',
|
|
82
|
+
recentPeer: '设备',
|
|
83
|
+
recentPort: '端口',
|
|
84
|
+
recentVia: '路径',
|
|
85
|
+
recentDuration: '时长',
|
|
86
|
+
recentTime: '时间',
|
|
87
|
+
errorTitle: '远程访问需要处理',
|
|
88
|
+
retry: '重试',
|
|
89
|
+
unavailableTitle: '远程访问不可用',
|
|
90
|
+
unavailableBody: '插件无法读取控制接口。请刷新页面或查看 Host 日志。',
|
|
91
|
+
sessionExpired: '浏览器会话已过期,请重新打开 dsh web 输出的地址。',
|
|
92
|
+
setupTitle: '安装 tailcat',
|
|
93
|
+
setupBody: '插件找不到 tailcat 可执行文件。可以一键安装,也可以使用系统已有的 tailcat。',
|
|
94
|
+
setupRetry: '重新检测',
|
|
95
|
+
installMethodDownload: '安装方式:下载官方 {asset},校验 SHA-256 后解压。',
|
|
96
|
+
installMethodBrew: '安装方式:Homebrew({command})。',
|
|
97
|
+
installButton: '一键安装 tailcat',
|
|
98
|
+
installReinstall: '重新安装受管版本',
|
|
99
|
+
installBusy: '正在安装 tailcat…',
|
|
100
|
+
installPhaseChecksums: '正在获取官方 SHA-256 校验值…',
|
|
101
|
+
installPhaseDownload: '正在下载 tailcat…',
|
|
102
|
+
installPhaseVerify: '正在校验下载文件…',
|
|
103
|
+
installPhaseExtract: '正在解压…',
|
|
104
|
+
installPhaseInstall: '正在安装…',
|
|
105
|
+
installPhaseHomebrew: '正在通过 Homebrew 安装 tailcat,这可能需要几分钟…',
|
|
106
|
+
installProgress: '{percent}%({received} / {total})',
|
|
107
|
+
installProgressUnknown: '已下载 {received}',
|
|
108
|
+
installFailed: '安装失败',
|
|
109
|
+
installDetected: '已检测到系统 tailcat',
|
|
110
|
+
installDetectedBody: '版本 {version}。插件会直接使用它,不需要重复安装;路径见下方诊断。',
|
|
111
|
+
installChecking: '正在检查系统是否已安装 tailcat…',
|
|
112
|
+
installSystemOutdated: '检测到的 tailcat {version} 缺少本插件需要的能力(需要 0.8.0 或更新)。可以一键安装受管版本,或先升级系统 tailcat。',
|
|
113
|
+
installSystemOutdatedBrew: '检测到的 tailcat {version} 缺少本插件需要的能力(需要 0.8.0 或更新)。点击按钮会通过 Homebrew 升级系统 tailcat,并复制一份到受管目录;也可以先手动升级。',
|
|
114
|
+
installUnsupported: '当前平台 {platform}/{arch} 暂无自动安装。',
|
|
115
|
+
installConfigOverride: 'binaryPath 当前为 {path}。一键安装只会写入受管目录,不会覆盖该配置;请改回 tailcat 或手动安装到该路径。',
|
|
116
|
+
installManual: '手动安装说明',
|
|
117
|
+
installManagedNote: '受管版本位于 {path},不会修改系统 PATH。',
|
|
118
|
+
diagBinarySource: '可执行文件来源',
|
|
119
|
+
diagInstallSource: 'tailcat 安装',
|
|
120
|
+
sourceManaged: '受管安装',
|
|
121
|
+
sourcePath: '系统 PATH',
|
|
122
|
+
sourceConfig: '配置指定',
|
|
123
|
+
sourceUnavailable: '未检测到',
|
|
124
|
+
noticeInstalled: 'tailcat 已安装。',
|
|
125
|
+
firstRun: '首次启动:tailcat 正在生成保存密钥并向 DERP 中继探测路由,可能需要一分钟。',
|
|
126
|
+
modeStable: '保存密钥(稳定)',
|
|
127
|
+
modeEphemeral: '临时密钥(重启后变化)',
|
|
128
|
+
modeSocket: 'Unix socket',
|
|
129
|
+
modeTcp: '127.0.0.1 TCP',
|
|
130
|
+
busyStart: '正在启动 tailcat…',
|
|
131
|
+
busyStop: '正在停止 tailcat…',
|
|
132
|
+
busyRestart: '正在重启 tailcat…',
|
|
133
|
+
busyRotate: '正在更换地址…',
|
|
134
|
+
busySave: '正在保存设备密钥…',
|
|
135
|
+
noticeStarted: 'tailcat 正在启动。',
|
|
136
|
+
noticeStopped: 'tailcat 已停止。',
|
|
137
|
+
noticeRestarted: 'tailcat 已重启。',
|
|
138
|
+
noticeRotated: '地址已更换,新地址显示在下方。',
|
|
139
|
+
qrAlt: '包含 tailcat 地址的二维码',
|
|
140
|
+
footerNote: 'tailcat 地址即凭据,请只分享给你控制的设备。',
|
|
141
|
+
never: '从未',
|
|
142
|
+
unknown: '未知',
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const en = {
|
|
146
|
+
nav: 'Remote Access',
|
|
147
|
+
title: 'Remote Access',
|
|
148
|
+
subtitle: 'Reach this Harness from anywhere through tailcat — no public port and no inbound firewall change.',
|
|
149
|
+
refresh: 'Refresh',
|
|
150
|
+
loading: 'Reading remote-access state…',
|
|
151
|
+
statusLabel: 'Tunnel',
|
|
152
|
+
statusOnline: 'Online',
|
|
153
|
+
statusStarting: 'Starting',
|
|
154
|
+
statusRestarting: 'Restarting',
|
|
155
|
+
statusStopping: 'Stopping',
|
|
156
|
+
statusStopped: 'Stopped',
|
|
157
|
+
statusError: 'Error',
|
|
158
|
+
statusUnknown: 'Unknown',
|
|
159
|
+
start: 'Start',
|
|
160
|
+
stop: 'Stop',
|
|
161
|
+
restart: 'Restart',
|
|
162
|
+
rotating: 'Rotating…',
|
|
163
|
+
rotate: 'Rotate address',
|
|
164
|
+
rotateArm: 'Rotate address?',
|
|
165
|
+
rotateConfirm: 'Yes, rotate now',
|
|
166
|
+
cancel: 'Cancel',
|
|
167
|
+
rotateHint: 'The saved tailcat key is replaced, the tunnel restarts, and the old address stops working immediately.',
|
|
168
|
+
rotateCaveat: 'Rotating the tailcat address does not sign out browsers that already hold a DSH session cookie. Those credentials end when they expire or are removed from the browser-session record.',
|
|
169
|
+
rotateDisconnect: 'If this page is open through tailcat, rotating, stopping, or saving the device list drops the current connection. Use the page on the Host, then reconnect with the new address.',
|
|
170
|
+
qrUnavailable: 'The QR code could not be generated; copy the address above instead.',
|
|
171
|
+
copy: 'Copy',
|
|
172
|
+
copied: 'Copied',
|
|
173
|
+
copyFailed: 'Could not copy; select the text manually.',
|
|
174
|
+
showQr: 'Show QR code',
|
|
175
|
+
hideQr: 'Hide QR code',
|
|
176
|
+
pairingTitle: 'Pair this Harness',
|
|
177
|
+
pairingHint: 'Run the command on the device that will carry the tunnel, then open the local URL in that device’s browser.',
|
|
178
|
+
addressLabel: 'tailcat address',
|
|
179
|
+
commandLabel: 'Command for the client device',
|
|
180
|
+
commandHint: 'The client binds port {localPort}; the Harness lives on virtual port {port}.',
|
|
181
|
+
openLocal: 'Open local URL',
|
|
182
|
+
localUrlHint: 'Once the tunnel is up, this URL offers the normal DSH login flow once, then keeps the session cookie.',
|
|
183
|
+
stepsTitle: 'Three steps',
|
|
184
|
+
stepInstall: 'Install tailcat on the client device.',
|
|
185
|
+
stepRun: 'Run the command, or scan the QR code to move the address to that device.',
|
|
186
|
+
stepOpen: 'Open http://127.0.0.1:{localPort}/ in the client browser.',
|
|
187
|
+
installHint: 'The plugin can install tailcat automatically. If that is unavailable, install it from the GitHub release and set binaryPath.',
|
|
188
|
+
securityTitle: 'Security',
|
|
189
|
+
allowOffTitle: 'The address is the only key',
|
|
190
|
+
allowOffBody: 'Anyone who obtains the tailcat address can reach this Harness. Add at least one client public key below to restrict access to paired devices.',
|
|
191
|
+
allowOnTitle: 'Restricted to {count} device(s)',
|
|
192
|
+
allowOnBody: 'tailcat refuses every client whose key is not in this list. The address remains necessary, but it is not sufficient.',
|
|
193
|
+
devicesLabel: 'Allowed client public keys',
|
|
194
|
+
devicesHint: 'One nodekey per line. On the client, run tailcat genkey --client --key=client-default to create a key and print its public key.',
|
|
195
|
+
devicesPlaceholder: 'nodekey:…',
|
|
196
|
+
devicesSave: 'Save and apply',
|
|
197
|
+
devicesReset: 'Reset changes',
|
|
198
|
+
devicesSaved: 'Device list saved; tailcat restarted to apply it.',
|
|
199
|
+
devicesEmpty: 'No device keys yet — address-only mode.',
|
|
200
|
+
deviceCount: '{count} allowed',
|
|
201
|
+
devicesGenerate: 'Generate a client key on the client device:',
|
|
202
|
+
diagnosticsTitle: 'Status & diagnostics',
|
|
203
|
+
diagPhase: 'Phase',
|
|
204
|
+
diagAddressMode: 'Key mode',
|
|
205
|
+
diagKeyName: 'Key name',
|
|
206
|
+
diagVersion: 'tailcat version',
|
|
207
|
+
diagBinary: 'Executable',
|
|
208
|
+
diagRegion: 'Relay region',
|
|
209
|
+
diagRestarts: 'Auto-restarts',
|
|
210
|
+
diagDoor: 'Door',
|
|
211
|
+
diagTarget: 'Forward target',
|
|
212
|
+
diagLastError: 'Last error',
|
|
213
|
+
diagWarnings: 'Warnings',
|
|
214
|
+
recentTitle: 'Recent connections',
|
|
215
|
+
recentEmpty: 'No connections recorded yet.',
|
|
216
|
+
recentPeer: 'Device',
|
|
217
|
+
recentPort: 'Port',
|
|
218
|
+
recentVia: 'Path',
|
|
219
|
+
recentDuration: 'Duration',
|
|
220
|
+
recentTime: 'Time',
|
|
221
|
+
errorTitle: 'Remote access needs attention',
|
|
222
|
+
retry: 'Retry',
|
|
223
|
+
unavailableTitle: 'Remote access is unavailable',
|
|
224
|
+
unavailableBody: 'The plugin could not read its control API. Reload the page or check the Host log.',
|
|
225
|
+
sessionExpired: 'The browser session expired; reopen the URL printed by dsh web.',
|
|
226
|
+
setupTitle: 'Install tailcat',
|
|
227
|
+
setupBody: 'The plugin could not find the tailcat executable. Install it here or use an existing system copy.',
|
|
228
|
+
setupRetry: 'Check again',
|
|
229
|
+
installMethodDownload: 'Method: download the official {asset} and verify its SHA-256 before extraction.',
|
|
230
|
+
installMethodBrew: 'Method: Homebrew ({command}).',
|
|
231
|
+
installButton: 'Install tailcat',
|
|
232
|
+
installReinstall: 'Reinstall managed copy',
|
|
233
|
+
installBusy: 'Installing tailcat…',
|
|
234
|
+
installPhaseChecksums: 'Fetching the official SHA-256 manifest…',
|
|
235
|
+
installPhaseDownload: 'Downloading tailcat…',
|
|
236
|
+
installPhaseVerify: 'Verifying the download…',
|
|
237
|
+
installPhaseExtract: 'Extracting…',
|
|
238
|
+
installPhaseInstall: 'Installing…',
|
|
239
|
+
installPhaseHomebrew: 'Installing tailcat through Homebrew; this can take a few minutes…',
|
|
240
|
+
installProgress: '{percent}% ({received} / {total})',
|
|
241
|
+
installProgressUnknown: '{received} downloaded',
|
|
242
|
+
installFailed: 'Installation failed',
|
|
243
|
+
installDetected: 'Existing tailcat detected',
|
|
244
|
+
installDetectedBody: 'Version {version}. The plugin uses it directly; no duplicate install is needed. The path is in diagnostics below.',
|
|
245
|
+
installChecking: 'Checking whether tailcat is already installed…',
|
|
246
|
+
installSystemOutdated: 'The detected tailcat {version} lacks the features this plugin needs (0.8.0 or newer is required). Install the managed copy or upgrade the system tailcat first.',
|
|
247
|
+
installSystemOutdatedBrew: 'The detected tailcat {version} lacks the features this plugin needs (0.8.0 or newer is required). The button upgrades it through Homebrew and copies the result into the managed directory; you can also upgrade manually first.',
|
|
248
|
+
installUnsupported: 'Automatic installation is unavailable on {platform}/{arch}.',
|
|
249
|
+
installConfigOverride: 'binaryPath is set to {path}. A managed install only writes the plugin directory and will not override that setting; set it back to tailcat or install manually at that path.',
|
|
250
|
+
installManual: 'Manual install instructions',
|
|
251
|
+
installManagedNote: 'The managed copy lives at {path}; the system PATH is not modified.',
|
|
252
|
+
diagBinarySource: 'Executable source',
|
|
253
|
+
diagInstallSource: 'tailcat install',
|
|
254
|
+
sourceManaged: 'Managed',
|
|
255
|
+
sourcePath: 'System PATH',
|
|
256
|
+
sourceConfig: 'Configured path',
|
|
257
|
+
sourceUnavailable: 'Not detected',
|
|
258
|
+
noticeInstalled: 'tailcat is installed.',
|
|
259
|
+
firstRun: 'First run: tailcat is creating a saved key and asking a DERP relay for a route. This can take a minute.',
|
|
260
|
+
modeStable: 'Saved (stable)',
|
|
261
|
+
modeEphemeral: 'Ephemeral (changes on restart)',
|
|
262
|
+
modeSocket: 'Unix socket',
|
|
263
|
+
modeTcp: '127.0.0.1 TCP',
|
|
264
|
+
busyStart: 'Starting tailcat…',
|
|
265
|
+
busyStop: 'Stopping tailcat…',
|
|
266
|
+
busyRestart: 'Restarting tailcat…',
|
|
267
|
+
busyRotate: 'Rotating the address…',
|
|
268
|
+
busySave: 'Saving device keys…',
|
|
269
|
+
noticeStarted: 'tailcat is starting.',
|
|
270
|
+
noticeStopped: 'tailcat is stopped.',
|
|
271
|
+
noticeRestarted: 'tailcat restarted.',
|
|
272
|
+
noticeRotated: 'The address was rotated; the new one is below.',
|
|
273
|
+
qrAlt: 'QR code containing the tailcat address',
|
|
274
|
+
footerNote: 'The tailcat address is a credential. Share it only with devices you control.',
|
|
275
|
+
never: 'never',
|
|
276
|
+
unknown: 'unknown',
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const PHASE_KEY = {
|
|
280
|
+
online: 'statusOnline',
|
|
281
|
+
starting: 'statusStarting',
|
|
282
|
+
restarting: 'statusRestarting',
|
|
283
|
+
stopping: 'statusStopping',
|
|
284
|
+
stopped: 'statusStopped',
|
|
285
|
+
error: 'statusError',
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Dark/light-theme-aware page shell. All colors come from Harness theme
|
|
290
|
+
* tokens except the QR code itself, which must stay black on white.
|
|
291
|
+
*/
|
|
292
|
+
const STYLE = `
|
|
293
|
+
.tcr-page { height: 100%; overflow-y: auto; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); font-family: inherit; }
|
|
294
|
+
.tcr-shell { max-width: 980px; margin: 0 auto; padding: 28px 24px 56px; display: flex; flex-direction: column; gap: 16px; }
|
|
295
|
+
.tcr-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
|
|
296
|
+
.tcr-heading { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
|
|
297
|
+
.tcr-mark { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l3); display: grid; place-items: center; color: var(--dsw-alias-brand-primary); }
|
|
298
|
+
.tcr-title { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
|
|
299
|
+
.tcr-subtitle { margin: 5px 0 0; font-size: 13px; line-height: 1.55; color: var(--dsw-alias-label-secondary); max-width: 620px; }
|
|
300
|
+
.tcr-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
|
|
301
|
+
.tcr-card { background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l3); border-radius: 14px; padding: 18px 20px; }
|
|
302
|
+
.tcr-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
|
|
303
|
+
.tcr-card-title { margin: 0; font-size: 15px; line-height: 1.4; font-weight: 600; }
|
|
304
|
+
.tcr-card-sub { margin: 4px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--dsw-alias-label-secondary); }
|
|
305
|
+
.tcr-btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background .15s ease, border-color .15s ease, opacity .15s ease; }
|
|
306
|
+
.tcr-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
307
|
+
.tcr-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
|
|
308
|
+
.tcr-btn:disabled { opacity: .45; cursor: not-allowed; }
|
|
309
|
+
.tcr-btn-primary { background: var(--dsw-alias-button-primary-fill); border-color: transparent; color: var(--dsw-alias-label-primary-foreground); }
|
|
310
|
+
.tcr-btn-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }
|
|
311
|
+
.tcr-btn-danger { color: var(--dsw-alias-state-error-primary); border-color: var(--dsw-alias-border-l3); background: transparent; }
|
|
312
|
+
.tcr-btn-danger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-danger); }
|
|
313
|
+
.tcr-btn-ghost { background: transparent; border-color: transparent; color: var(--dsw-alias-label-secondary); }
|
|
314
|
+
.tcr-btn-ghost:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
315
|
+
.tcr-pill { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l3); font-size: 12.5px; color: var(--dsw-alias-label-secondary); }
|
|
316
|
+
.tcr-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dsw-alias-label-tertiary); }
|
|
317
|
+
.tcr-phase-online .tcr-dot { background: var(--dsw-alias-state-success-primary); }
|
|
318
|
+
.tcr-phase-starting .tcr-dot, .tcr-phase-restarting .tcr-dot { background: var(--dsw-alias-state-warn-primary); }
|
|
319
|
+
.tcr-phase-error .tcr-dot { background: var(--dsw-alias-state-error-primary); }
|
|
320
|
+
.tcr-phase-stopping .tcr-dot { background: var(--dsw-alias-state-warn-primary); }
|
|
321
|
+
.tcr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
|
|
322
|
+
.tcr-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px dashed var(--dsw-alias-border-l3); font-size: 13px; min-width: 0; }
|
|
323
|
+
.tcr-row:last-child { border-bottom: 0; }
|
|
324
|
+
.tcr-row-label { color: var(--dsw-alias-label-secondary); flex: 0 0 auto; }
|
|
325
|
+
.tcr-row-value { text-align: right; color: var(--dsw-alias-label-primary); min-width: 0; overflow-wrap: anywhere; }
|
|
326
|
+
.tcr-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 12.5px; }
|
|
327
|
+
.tcr-code { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l3); border-radius: 10px; padding: 10px 12px; margin-top: 8px; min-width: 0; }
|
|
328
|
+
.tcr-code-text { min-width: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 12.5px; line-height: 1.55; user-select: all; }
|
|
329
|
+
.tcr-address { font-size: 13px; line-height: 1.65; }
|
|
330
|
+
.tcr-label { display: block; font-size: 12px; font-weight: 500; color: var(--dsw-alias-label-secondary); margin: 0 0 6px; }
|
|
331
|
+
.tcr-textarea { width: 100%; box-sizing: border-box; min-height: 92px; resize: vertical; border-radius: 10px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); padding: 10px 12px; font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.6; }
|
|
332
|
+
.tcr-textarea:focus { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
333
|
+
.tcr-alert { border-radius: 10px; padding: 12px 14px; border: 1px solid var(--dsw-alias-border-l3); background: var(--dsw-alias-bg-layer-2); font-size: 13px; line-height: 1.6; }
|
|
334
|
+
.tcr-alert-danger { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, var(--dsw-alias-border-l3)); background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 9%, var(--dsw-alias-bg-layer-1)); }
|
|
335
|
+
.tcr-alert-warn { border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 35%, var(--dsw-alias-border-l3)); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 10%, var(--dsw-alias-bg-layer-1)); }
|
|
336
|
+
.tcr-alert-title { font-weight: 600; margin: 0 0 4px; }
|
|
337
|
+
.tcr-alert-body { margin: 0; color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
338
|
+
.tcr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
|
|
339
|
+
.tcr-hint { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-tertiary); margin-top: 8px; }
|
|
340
|
+
.tcr-qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }
|
|
341
|
+
.tcr-qr { width: min(240px, 62vw); padding: 12px; background: #fff; border-radius: 12px; border: 1px solid var(--dsw-alias-border-l3); box-sizing: content-box; }
|
|
342
|
+
.tcr-qr svg { display: block; width: 100%; height: auto; }
|
|
343
|
+
.tcr-steps { margin: 12px 0 0; padding-left: 20px; color: var(--dsw-alias-label-secondary); font-size: 13px; line-height: 1.7; }
|
|
344
|
+
.tcr-steps code { color: var(--dsw-alias-label-primary); }
|
|
345
|
+
.tcr-badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-secondary); font-size: 11.5px; white-space: nowrap; }
|
|
346
|
+
.tcr-recent { display: flex; flex-direction: column; gap: 0; margin-top: 4px; }
|
|
347
|
+
.tcr-recent-row { display: grid; grid-template-columns: 1.5fr .5fr .9fr .6fr .7fr; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px dashed var(--dsw-alias-border-l3); font-size: 12.5px; }
|
|
348
|
+
.tcr-recent-row:last-child { border-bottom: 0; }
|
|
349
|
+
.tcr-recent-head { color: var(--dsw-alias-label-tertiary); font-size: 11.5px; }
|
|
350
|
+
.tcr-notice { border-radius: 10px; padding: 10px 14px; font-size: 13px; border: 1px solid var(--dsw-alias-border-l3); background: var(--dsw-alias-bg-layer-2); }
|
|
351
|
+
.tcr-notice-ok { border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 35%, var(--dsw-alias-border-l3)); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 9%, var(--dsw-alias-bg-layer-1)); }
|
|
352
|
+
.tcr-notice-error { border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, var(--dsw-alias-border-l3)); background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 9%, var(--dsw-alias-bg-layer-1)); color: var(--dsw-alias-label-primary); }
|
|
353
|
+
.tcr-footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--dsw-alias-label-tertiary); font-size: 11.5px; line-height: 1.6; padding-top: 6px; }
|
|
354
|
+
.tcr-progress { height: 6px; overflow: hidden; border-radius: 999px; background: var(--dsw-alias-bg-layer-3); margin-top: 8px; }
|
|
355
|
+
.tcr-progress-bar { height: 100%; border-radius: inherit; background: var(--dsw-alias-brand-primary); transition: width .25s ease; }
|
|
356
|
+
.tcr-spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--dsw-alias-border-l2); border-top-color: var(--dsw-alias-brand-primary); animation: tcr-spin .8s linear infinite; }
|
|
357
|
+
@keyframes tcr-spin { to { transform: rotate(360deg); } }
|
|
358
|
+
.tcr-empty { color: var(--dsw-alias-label-tertiary); font-size: 13px; }
|
|
359
|
+
.tcr-warning-list { margin: 8px 0 0; padding-left: 18px; color: var(--dsw-alias-state-warn-label); font-size: 12px; line-height: 1.6; }
|
|
360
|
+
@media (max-width: 720px) {
|
|
361
|
+
.tcr-shell { padding: 16px 14px 40px; }
|
|
362
|
+
.tcr-header { flex-direction: column; }
|
|
363
|
+
.tcr-header-actions { justify-content: flex-start; }
|
|
364
|
+
.tcr-grid { grid-template-columns: 1fr; }
|
|
365
|
+
.tcr-recent-row { grid-template-columns: 1.4fr .6fr .9fr; }
|
|
366
|
+
.tcr-recent-row > :nth-child(4), .tcr-recent-row > :nth-child(5) { display: none; }
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Sidebar glyph. Inherits the row color so the active state is the shell's.
|
|
372
|
+
* @param {{ size?: number }} props - slot-injected icon props.
|
|
373
|
+
*/
|
|
374
|
+
function PanelIcon({ size = 20 }) {
|
|
375
|
+
return h(
|
|
376
|
+
'svg',
|
|
377
|
+
{
|
|
378
|
+
width: size,
|
|
379
|
+
height: size,
|
|
380
|
+
viewBox: '0 0 24 24',
|
|
381
|
+
fill: 'none',
|
|
382
|
+
'aria-hidden': 'true',
|
|
383
|
+
style: { display: 'block' },
|
|
384
|
+
},
|
|
385
|
+
h('path', {
|
|
386
|
+
d: 'M7.2 8.6 6 4.8l4.2 2.5',
|
|
387
|
+
stroke: 'currentColor',
|
|
388
|
+
strokeWidth: 1.7,
|
|
389
|
+
strokeLinecap: 'round',
|
|
390
|
+
strokeLinejoin: 'round',
|
|
391
|
+
}),
|
|
392
|
+
h('path', {
|
|
393
|
+
d: 'M16.8 8.6 18 4.8l-4.2 2.5',
|
|
394
|
+
stroke: 'currentColor',
|
|
395
|
+
strokeWidth: 1.7,
|
|
396
|
+
strokeLinecap: 'round',
|
|
397
|
+
strokeLinejoin: 'round',
|
|
398
|
+
}),
|
|
399
|
+
h('path', {
|
|
400
|
+
d: 'M5.6 11.4c0-3.1 2.8-5.6 6.4-5.6s6.4 2.5 6.4 5.6v1.7c0 3.1-2.8 5.6-6.4 5.6s-6.4-2.5-6.4-5.6z',
|
|
401
|
+
stroke: 'currentColor',
|
|
402
|
+
strokeWidth: 1.6,
|
|
403
|
+
}),
|
|
404
|
+
h('circle', { cx: 12, cy: 12.3, r: 1.9, fill: 'currentColor' }),
|
|
405
|
+
h('path', { d: 'M12 14.2v2.2', stroke: 'currentColor', strokeWidth: 1.9, strokeLinecap: 'round' }),
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @param {object} props - tone, title, children.
|
|
411
|
+
*/
|
|
412
|
+
function Alert({ tone = 'info', title, children }) {
|
|
413
|
+
return h(
|
|
414
|
+
'div',
|
|
415
|
+
{ className: `tcr-alert ${tone === 'danger' ? 'tcr-alert-danger' : tone === 'warn' ? 'tcr-alert-warn' : ''}` },
|
|
416
|
+
title ? h('p', { className: 'tcr-alert-title' }, title) : null,
|
|
417
|
+
h('div', { className: 'tcr-alert-body' }, children),
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @param {object} props - card framing.
|
|
423
|
+
*/
|
|
424
|
+
function Card({ title, subtitle, actions, children }) {
|
|
425
|
+
return h(
|
|
426
|
+
'section',
|
|
427
|
+
{ className: 'tcr-card' },
|
|
428
|
+
title
|
|
429
|
+
? h(
|
|
430
|
+
'div',
|
|
431
|
+
{ className: 'tcr-card-head' },
|
|
432
|
+
h('div', null, h('h2', { className: 'tcr-card-title' }, title), subtitle ? h('p', { className: 'tcr-card-sub' }, subtitle) : null),
|
|
433
|
+
actions ? h('div', { className: 'tcr-actions', style: { marginTop: 0 } }, actions) : null,
|
|
434
|
+
)
|
|
435
|
+
: null,
|
|
436
|
+
children,
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @param {object} props - button props.
|
|
442
|
+
*/
|
|
443
|
+
function Button({ variant = 'secondary', disabled = false, onClick, children, title }) {
|
|
444
|
+
return h(
|
|
445
|
+
'button',
|
|
446
|
+
{ type: 'button', className: `tcr-btn tcr-btn-${variant}`, disabled, onClick, title },
|
|
447
|
+
children,
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @param {object} props - copy payload and label.
|
|
453
|
+
*/
|
|
454
|
+
function CopyButton({ text, label, t, onResult }) {
|
|
455
|
+
return h(
|
|
456
|
+
Button,
|
|
457
|
+
{
|
|
458
|
+
variant: 'ghost',
|
|
459
|
+
onClick: async () => {
|
|
460
|
+
const ok = await copyText(text);
|
|
461
|
+
onResult?.(ok ? t('copied') : t('copyFailed'), ok);
|
|
462
|
+
},
|
|
463
|
+
title: label ?? t('copy'),
|
|
464
|
+
},
|
|
465
|
+
label ?? t('copy'),
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* @param {object} props - address matrix.
|
|
471
|
+
*/
|
|
472
|
+
function QrCode({ matrix, t }) {
|
|
473
|
+
const geometry = useMemo(() => (matrix ? qrGeometry(matrix) : null), [matrix]);
|
|
474
|
+
if (!geometry) return null;
|
|
475
|
+
return h(
|
|
476
|
+
'div',
|
|
477
|
+
{ className: 'tcr-qr' },
|
|
478
|
+
h(
|
|
479
|
+
'svg',
|
|
480
|
+
{
|
|
481
|
+
viewBox: geometry.viewBox,
|
|
482
|
+
role: 'img',
|
|
483
|
+
'aria-label': t('qrAlt'),
|
|
484
|
+
shapeRendering: 'crispEdges',
|
|
485
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
486
|
+
},
|
|
487
|
+
h('rect', { width: '100%', height: '100%', fill: '#fff' }),
|
|
488
|
+
h('path', { d: geometry.path, fill: '#000' }),
|
|
489
|
+
),
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @param {{ phase?: string, t: Function }} props - phase from the Host.
|
|
495
|
+
*/
|
|
496
|
+
function StatusPill({ phase, t }) {
|
|
497
|
+
const key = PHASE_KEY[phase] ?? 'statusUnknown';
|
|
498
|
+
return h(
|
|
499
|
+
'span',
|
|
500
|
+
{ className: `tcr-pill tcr-phase-${phase ?? 'unknown'}`, role: 'status', 'aria-live': 'polite' },
|
|
501
|
+
h('span', { className: 'tcr-dot' }),
|
|
502
|
+
`${t('statusLabel')} · ${t(key)}`,
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @param {object} props - label and value.
|
|
508
|
+
*/
|
|
509
|
+
function Row({ label, children }) {
|
|
510
|
+
return h(
|
|
511
|
+
'div',
|
|
512
|
+
{ className: 'tcr-row' },
|
|
513
|
+
h('span', { className: 'tcr-row-label' }, label),
|
|
514
|
+
h('span', { className: 'tcr-row-value' }, children),
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** @returns {object} polling state and action helpers. */
|
|
519
|
+
function useRemoteState() {
|
|
520
|
+
const [snapshot, setSnapshot] = useState(null);
|
|
521
|
+
const [error, setError] = useState(null);
|
|
522
|
+
const [busy, setBusy] = useState(null);
|
|
523
|
+
const [notice, setNotice] = useState(null);
|
|
524
|
+
|
|
525
|
+
const reload = useCallback(async () => {
|
|
526
|
+
try {
|
|
527
|
+
const response = await fetch(API, {
|
|
528
|
+
method: 'GET',
|
|
529
|
+
headers: { accept: 'application/json' },
|
|
530
|
+
cache: 'no-store',
|
|
531
|
+
credentials: 'same-origin',
|
|
532
|
+
});
|
|
533
|
+
const data = await response.json().catch(() => null);
|
|
534
|
+
if (!response.ok || !data?.ok) {
|
|
535
|
+
throw new Error(data?.error?.message ?? `HTTP ${response.status}`);
|
|
536
|
+
}
|
|
537
|
+
setSnapshot(data);
|
|
538
|
+
setError(null);
|
|
539
|
+
} catch (failure) {
|
|
540
|
+
setError(failure instanceof Error ? failure.message : String(failure));
|
|
541
|
+
}
|
|
542
|
+
}, []);
|
|
543
|
+
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
void reload();
|
|
546
|
+
const timer = setInterval(() => {
|
|
547
|
+
if (!document.hidden) void reload();
|
|
548
|
+
}, 2_500);
|
|
549
|
+
const onVisibility = () => {
|
|
550
|
+
if (!document.hidden) void reload();
|
|
551
|
+
};
|
|
552
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
553
|
+
return () => {
|
|
554
|
+
clearInterval(timer);
|
|
555
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
556
|
+
};
|
|
557
|
+
}, [reload]);
|
|
558
|
+
|
|
559
|
+
const act = useCallback(
|
|
560
|
+
async (action, extra, noticeKey) => {
|
|
561
|
+
setBusy(action);
|
|
562
|
+
setNotice(null);
|
|
563
|
+
try {
|
|
564
|
+
const response = await fetch(API, {
|
|
565
|
+
method: 'POST',
|
|
566
|
+
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
|
567
|
+
credentials: 'same-origin',
|
|
568
|
+
body: JSON.stringify({ action, ...extra }),
|
|
569
|
+
});
|
|
570
|
+
const data = await response.json().catch(() => null);
|
|
571
|
+
if (!response.ok || !data?.ok) {
|
|
572
|
+
throw new Error(data?.error?.message ?? `HTTP ${response.status}`);
|
|
573
|
+
}
|
|
574
|
+
setSnapshot(data);
|
|
575
|
+
if (noticeKey) setNotice({ kind: 'ok', key: noticeKey });
|
|
576
|
+
return true;
|
|
577
|
+
} catch (failure) {
|
|
578
|
+
setNotice({ kind: 'error', text: failure instanceof Error ? failure.message : String(failure) });
|
|
579
|
+
return false;
|
|
580
|
+
} finally {
|
|
581
|
+
setBusy(null);
|
|
582
|
+
void reload();
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
[reload],
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
return { snapshot, error, busy, notice, setNotice, act, reload };
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** The page registered at the `main` key `tailcat-remote`. */
|
|
592
|
+
function RemotePage({ t }) {
|
|
593
|
+
const { snapshot, error, busy, notice, setNotice, act, reload } = useRemoteState();
|
|
594
|
+
const [showQr, setShowQr] = useState(false);
|
|
595
|
+
const [rotateArmed, setRotateArmed] = useState(false);
|
|
596
|
+
const [draft, setDraft] = useState('');
|
|
597
|
+
const [devicesDirty, setDevicesDirty] = useState(false);
|
|
598
|
+
const [localNotice, setLocalNotice] = useState(null);
|
|
599
|
+
|
|
600
|
+
const displayedNotice = localNotice ?? notice;
|
|
601
|
+
useEffect(() => {
|
|
602
|
+
if (!displayedNotice) return undefined;
|
|
603
|
+
const timer = setTimeout(() => {
|
|
604
|
+
setLocalNotice(null);
|
|
605
|
+
setNotice(null);
|
|
606
|
+
}, 6_000);
|
|
607
|
+
return () => clearTimeout(timer);
|
|
608
|
+
}, [displayedNotice, setNotice]);
|
|
609
|
+
|
|
610
|
+
useEffect(() => {
|
|
611
|
+
if (rotateArmed) {
|
|
612
|
+
const timer = setTimeout(() => setRotateArmed(false), 8_000);
|
|
613
|
+
return () => clearTimeout(timer);
|
|
614
|
+
}
|
|
615
|
+
return undefined;
|
|
616
|
+
}, [rotateArmed]);
|
|
617
|
+
|
|
618
|
+
useEffect(() => {
|
|
619
|
+
if (!snapshot || devicesDirty) return;
|
|
620
|
+
setDraft((snapshot.devices.allow ?? []).join('\n'));
|
|
621
|
+
}, [snapshot, devicesDirty]);
|
|
622
|
+
|
|
623
|
+
const tailcat = snapshot?.tailcat;
|
|
624
|
+
const phase = tailcat?.phase ?? 'stopped';
|
|
625
|
+
const pairing = snapshot?.pairing ?? null;
|
|
626
|
+
const busyKey =
|
|
627
|
+
busy === 'start'
|
|
628
|
+
? 'busyStart'
|
|
629
|
+
: busy === 'stop'
|
|
630
|
+
? 'busyStop'
|
|
631
|
+
: busy === 'restart'
|
|
632
|
+
? 'busyRestart'
|
|
633
|
+
: busy === 'rotate'
|
|
634
|
+
? 'busyRotate'
|
|
635
|
+
: busy === 'devices'
|
|
636
|
+
? 'busySave'
|
|
637
|
+
: busy === 'install'
|
|
638
|
+
? 'installBusy'
|
|
639
|
+
: null;
|
|
640
|
+
|
|
641
|
+
const reportCopy = (text, ok) => setLocalNotice({ kind: ok ? 'ok' : 'error', text });
|
|
642
|
+
|
|
643
|
+
if (!snapshot) {
|
|
644
|
+
return h(
|
|
645
|
+
'div',
|
|
646
|
+
{ className: 'tcr-page' },
|
|
647
|
+
h('style', null, STYLE),
|
|
648
|
+
h(
|
|
649
|
+
'div',
|
|
650
|
+
{ className: 'tcr-shell' },
|
|
651
|
+
h('div', { className: 'tcr-header' }, h('div', { className: 'tcr-heading' },
|
|
652
|
+
h('div', { className: 'tcr-mark' }, h(PanelIcon, { size: 22 })),
|
|
653
|
+
h('div', null, h('h1', { className: 'tcr-title' }, t('title')), h('p', { className: 'tcr-subtitle' }, t('subtitle'))),
|
|
654
|
+
)),
|
|
655
|
+
error
|
|
656
|
+
? h(
|
|
657
|
+
Alert,
|
|
658
|
+
{ tone: 'danger', title: t('unavailableTitle') },
|
|
659
|
+
h('p', null, t('unavailableBody')),
|
|
660
|
+
h('p', { className: 'tcr-mono' }, error),
|
|
661
|
+
h('div', { className: 'tcr-actions' }, h(Button, { onClick: () => void reload() }, t('retry'))),
|
|
662
|
+
)
|
|
663
|
+
: h('div', { className: 'tcr-empty' }, h('span', { className: 'tcr-spinner', style: { display: 'inline-block', verticalAlign: 'middle', marginRight: 8 } }), t('loading')),
|
|
664
|
+
),
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const binaryMissing = tailcat.binary?.resolved === null && phase === 'error';
|
|
669
|
+
const installer = snapshot.installer;
|
|
670
|
+
const system = installer?.system;
|
|
671
|
+
const systemFound = system?.status === 'found';
|
|
672
|
+
const systemCompatible = system?.compatible !== false;
|
|
673
|
+
const configOverride = snapshot.config.binaryPath !== 'tailcat';
|
|
674
|
+
const installerBusy = busy === 'install' || Boolean(installer?.busy);
|
|
675
|
+
const anyBusy = Boolean(busy) || Boolean(installer?.busy);
|
|
676
|
+
const progress = installer?.progress;
|
|
677
|
+
const percent = progress && Number.isFinite(progress.percent) ? progress.percent : null;
|
|
678
|
+
const phaseText = progress
|
|
679
|
+
? progress.phase === 'checksums'
|
|
680
|
+
? t('installPhaseChecksums')
|
|
681
|
+
: progress.phase === 'verifying'
|
|
682
|
+
? t('installPhaseVerify')
|
|
683
|
+
: progress.phase === 'extracting'
|
|
684
|
+
? t('installPhaseExtract')
|
|
685
|
+
: progress.phase === 'installing'
|
|
686
|
+
? t('installPhaseInstall')
|
|
687
|
+
: progress.phase === 'homebrew'
|
|
688
|
+
? t('installPhaseHomebrew')
|
|
689
|
+
: t('installPhaseDownload')
|
|
690
|
+
: null;
|
|
691
|
+
const installProgress = progress
|
|
692
|
+
? h(
|
|
693
|
+
'div',
|
|
694
|
+
{ className: 'tcr-install-progress' },
|
|
695
|
+
h(
|
|
696
|
+
'p',
|
|
697
|
+
{ className: 'tcr-hint', style: { marginTop: 0 } },
|
|
698
|
+
percent === null
|
|
699
|
+
? h('span', { className: 'tcr-spinner', style: { display: 'inline-block', verticalAlign: 'middle', marginRight: 8 } })
|
|
700
|
+
: null,
|
|
701
|
+
phaseText,
|
|
702
|
+
progress.phase === 'downloading' && progress.total > 0
|
|
703
|
+
? ` ${t('installProgress', { percent, received: formatBytes(progress.received), total: formatBytes(progress.total) })}`
|
|
704
|
+
: progress.phase === 'downloading' && progress.received > 0
|
|
705
|
+
? ` ${t('installProgressUnknown', { received: formatBytes(progress.received) })}`
|
|
706
|
+
: null,
|
|
707
|
+
),
|
|
708
|
+
percent !== null ? h('div', { className: 'tcr-progress' }, h('div', { className: 'tcr-progress-bar', style: { width: `${percent}%` } })) : null,
|
|
709
|
+
)
|
|
710
|
+
: null;
|
|
711
|
+
const sourceLabel =
|
|
712
|
+
tailcat.binary?.source === 'managed'
|
|
713
|
+
? t('sourceManaged')
|
|
714
|
+
: tailcat.binary?.source === 'config'
|
|
715
|
+
? t('sourceConfig')
|
|
716
|
+
: tailcat.binary?.source === 'path'
|
|
717
|
+
? t('sourcePath')
|
|
718
|
+
: t('sourceUnavailable');
|
|
719
|
+
const install = snapshot.plugin?.name ?? '@ds-hu/dsh-tailcat-remote';
|
|
720
|
+
const command = pairing?.command ?? '';
|
|
721
|
+
const localUrl = pairing ? `http://127.0.0.1:${pairing.localPort}/` : '';
|
|
722
|
+
const saveBusy = busy === 'devices';
|
|
723
|
+
|
|
724
|
+
const saveDevices = async () => {
|
|
725
|
+
const allow = draft
|
|
726
|
+
.split(/\r?\n/)
|
|
727
|
+
.map((line) => line.trim())
|
|
728
|
+
.filter((line) => line.length > 0 && !line.startsWith('#'));
|
|
729
|
+
const ok = await act('devices', { allow }, 'devicesSaved');
|
|
730
|
+
if (ok) setDevicesDirty(false);
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const rotate = async () => {
|
|
734
|
+
setRotateArmed(false);
|
|
735
|
+
await act('rotate', {}, 'noticeRotated');
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
return h(
|
|
739
|
+
'div',
|
|
740
|
+
{ className: 'tcr-page' },
|
|
741
|
+
h('style', null, STYLE),
|
|
742
|
+
h(
|
|
743
|
+
'div',
|
|
744
|
+
{ className: 'tcr-shell' },
|
|
745
|
+
h(
|
|
746
|
+
'div',
|
|
747
|
+
{ className: 'tcr-header' },
|
|
748
|
+
h(
|
|
749
|
+
'div',
|
|
750
|
+
{ className: 'tcr-heading' },
|
|
751
|
+
h('div', { className: 'tcr-mark' }, h(PanelIcon, { size: 22 })),
|
|
752
|
+
h(
|
|
753
|
+
'div',
|
|
754
|
+
null,
|
|
755
|
+
h('h1', { className: 'tcr-title' }, t('title')),
|
|
756
|
+
h('p', { className: 'tcr-subtitle' }, t('subtitle')),
|
|
757
|
+
),
|
|
758
|
+
),
|
|
759
|
+
h(
|
|
760
|
+
'div',
|
|
761
|
+
{ className: 'tcr-header-actions' },
|
|
762
|
+
h(StatusPill, { phase, t }),
|
|
763
|
+
phase === 'stopped' || phase === 'error'
|
|
764
|
+
? h(
|
|
765
|
+
Button,
|
|
766
|
+
{
|
|
767
|
+
variant: 'primary',
|
|
768
|
+
disabled: anyBusy,
|
|
769
|
+
onClick: () => void act('start', {}, 'noticeStarted'),
|
|
770
|
+
},
|
|
771
|
+
t('start'),
|
|
772
|
+
)
|
|
773
|
+
: h(
|
|
774
|
+
Button,
|
|
775
|
+
{
|
|
776
|
+
disabled: anyBusy,
|
|
777
|
+
onClick: () => void act('stop', {}, 'noticeStopped'),
|
|
778
|
+
},
|
|
779
|
+
t('stop'),
|
|
780
|
+
),
|
|
781
|
+
h(
|
|
782
|
+
Button,
|
|
783
|
+
{ disabled: anyBusy, onClick: () => void act('restart', {}, 'noticeRestarted') },
|
|
784
|
+
t('restart'),
|
|
785
|
+
),
|
|
786
|
+
h(Button, { variant: 'ghost', disabled: anyBusy, onClick: () => void reload() }, t('refresh')),
|
|
787
|
+
),
|
|
788
|
+
),
|
|
789
|
+
|
|
790
|
+
displayedNotice
|
|
791
|
+
? h(
|
|
792
|
+
'div',
|
|
793
|
+
{ className: `tcr-notice ${displayedNotice.kind === 'ok' ? 'tcr-notice-ok' : 'tcr-notice-error'}`, role: 'status' },
|
|
794
|
+
displayedNotice.key ? t(displayedNotice.key) : displayedNotice.text,
|
|
795
|
+
)
|
|
796
|
+
: null,
|
|
797
|
+
busyKey ? h('div', { className: 'tcr-hint' }, h('span', { className: 'tcr-spinner', style: { display: 'inline-block', verticalAlign: 'middle', marginRight: 8 } }), t(busyKey)) : null,
|
|
798
|
+
|
|
799
|
+
error ? h(Alert, { tone: 'danger', title: t('unavailableTitle') }, h('p', null, t('unavailableBody')), h('p', { className: 'tcr-mono' }, error)) : null,
|
|
800
|
+
snapshot.door?.phase === 'error'
|
|
801
|
+
? h(Alert, { tone: 'danger', title: t('diagDoor') }, snapshot.door.lastError ?? t('unknown'))
|
|
802
|
+
: null,
|
|
803
|
+
tailcat.lastError && phase === 'error' && !binaryMissing
|
|
804
|
+
? h(Alert, { tone: 'danger', title: t('diagLastError') }, h('p', { className: 'tcr-mono' }, tailcat.lastError))
|
|
805
|
+
: null,
|
|
806
|
+
|
|
807
|
+
!binaryMissing && systemFound && systemCompatible && !installer?.installed
|
|
808
|
+
? h(
|
|
809
|
+
Alert,
|
|
810
|
+
{ tone: 'info', title: t('installDetected') },
|
|
811
|
+
h('p', null, t('installDetectedBody', { version: system.version ?? t('unknown'), path: system.path })),
|
|
812
|
+
)
|
|
813
|
+
: null,
|
|
814
|
+
|
|
815
|
+
binaryMissing
|
|
816
|
+
? h(
|
|
817
|
+
Card,
|
|
818
|
+
{
|
|
819
|
+
title: systemFound && systemCompatible ? t('installDetected') : t('setupTitle'),
|
|
820
|
+
subtitle: systemFound
|
|
821
|
+
? systemCompatible
|
|
822
|
+
? t('installDetectedBody', { version: system.version ?? t('unknown'), path: system.path })
|
|
823
|
+
: t(installer?.method === 'brew' ? 'installSystemOutdatedBrew' : 'installSystemOutdated', { version: system.version ?? t('unknown') })
|
|
824
|
+
: system?.status === 'checking' || !system
|
|
825
|
+
? t('installChecking')
|
|
826
|
+
: t('setupBody'),
|
|
827
|
+
},
|
|
828
|
+
!systemFound
|
|
829
|
+
? h('p', { className: 'tcr-hint' }, t('installHint'))
|
|
830
|
+
: null,
|
|
831
|
+
configOverride
|
|
832
|
+
? h(Alert, { tone: 'warn', title: t('setupTitle') }, t('installConfigOverride', { path: snapshot.config.binaryPath }))
|
|
833
|
+
: null,
|
|
834
|
+
(!systemFound || !systemCompatible) && installer?.supported && !configOverride
|
|
835
|
+
? h(
|
|
836
|
+
'p',
|
|
837
|
+
{ className: 'tcr-hint' },
|
|
838
|
+
installer.method === 'brew'
|
|
839
|
+
? t('installMethodBrew', { command: installer.command })
|
|
840
|
+
: t('installMethodDownload', { asset: installer.asset ?? 'tailcat' }),
|
|
841
|
+
)
|
|
842
|
+
: null,
|
|
843
|
+
!installer?.supported
|
|
844
|
+
? h(Alert, { tone: 'warn' }, t('installUnsupported', { platform: installer?.platform ?? 'unknown', arch: installer?.arch ?? 'unknown' }))
|
|
845
|
+
: null,
|
|
846
|
+
installer?.error
|
|
847
|
+
? h(Alert, { tone: 'danger', title: t('installFailed') }, h('p', { className: 'tcr-mono' }, installer.error))
|
|
848
|
+
: null,
|
|
849
|
+
installerBusy ? installProgress : null,
|
|
850
|
+
h(
|
|
851
|
+
'div',
|
|
852
|
+
{ className: 'tcr-actions' },
|
|
853
|
+
(!systemFound || !systemCompatible) && installer?.supported && !configOverride
|
|
854
|
+
? h(
|
|
855
|
+
Button,
|
|
856
|
+
{
|
|
857
|
+
variant: 'primary',
|
|
858
|
+
disabled: installerBusy,
|
|
859
|
+
onClick: () => void act('install', {}, 'noticeInstalled'),
|
|
860
|
+
},
|
|
861
|
+
installerBusy ? t('installBusy') : installer?.installed ? t('installReinstall') : t('installButton'),
|
|
862
|
+
)
|
|
863
|
+
: null,
|
|
864
|
+
h(
|
|
865
|
+
Button,
|
|
866
|
+
{ variant: 'ghost', disabled: installerBusy, onClick: () => void act('restart', {}, 'noticeRestarted') },
|
|
867
|
+
t('setupRetry'),
|
|
868
|
+
),
|
|
869
|
+
installer?.manualUrl
|
|
870
|
+
? h(
|
|
871
|
+
'a',
|
|
872
|
+
{
|
|
873
|
+
className: 'tcr-btn tcr-btn-ghost',
|
|
874
|
+
href: installer.manualUrl,
|
|
875
|
+
target: '_blank',
|
|
876
|
+
rel: 'noopener noreferrer',
|
|
877
|
+
style: { textDecoration: 'none' },
|
|
878
|
+
},
|
|
879
|
+
t('installManual'),
|
|
880
|
+
)
|
|
881
|
+
: null,
|
|
882
|
+
),
|
|
883
|
+
installer?.installed && installer.binaryPath
|
|
884
|
+
? h('p', { className: 'tcr-hint' }, t('installManagedNote', { path: installer.binaryPath }))
|
|
885
|
+
: null,
|
|
886
|
+
)
|
|
887
|
+
: null,
|
|
888
|
+
|
|
889
|
+
!pairing && !binaryMissing
|
|
890
|
+
? h(
|
|
891
|
+
Card,
|
|
892
|
+
{ title: t('statusLabel') },
|
|
893
|
+
h(
|
|
894
|
+
'div',
|
|
895
|
+
{ className: 'tcr-grid' },
|
|
896
|
+
h(Row, { label: t('diagPhase') }, t(PHASE_KEY[phase] ?? 'statusUnknown')),
|
|
897
|
+
h(Row, { label: t('diagBinary') }, h('span', { className: 'tcr-mono' }, tailcat.binary?.resolved ?? snapshot.config.binaryPath)),
|
|
898
|
+
),
|
|
899
|
+
phase === 'starting' || phase === 'restarting'
|
|
900
|
+
? h(Alert, { tone: 'warn' }, h('div', { className: 'tcr-hint', style: { marginTop: 0 } }, h('span', { className: 'tcr-spinner', style: { display: 'inline-block', verticalAlign: 'middle', marginRight: 8 } }), t('firstRun')))
|
|
901
|
+
: h('p', { className: 'tcr-hint' }, h(Button, { variant: 'primary', disabled: Boolean(busy), onClick: () => void act('start', {}, 'noticeStarted') }, t('start'))),
|
|
902
|
+
)
|
|
903
|
+
: null,
|
|
904
|
+
|
|
905
|
+
pairing
|
|
906
|
+
? h(
|
|
907
|
+
Card,
|
|
908
|
+
{
|
|
909
|
+
title: t('pairingTitle'),
|
|
910
|
+
subtitle: t('pairingHint'),
|
|
911
|
+
actions: h('span', { className: 'tcr-badge' }, tailcat.keyMode === 'ephemeral' ? t('modeEphemeral') : t('modeStable')),
|
|
912
|
+
},
|
|
913
|
+
h('label', { className: 'tcr-label' }, t('addressLabel')),
|
|
914
|
+
h(
|
|
915
|
+
'div',
|
|
916
|
+
{ className: 'tcr-code' },
|
|
917
|
+
h('span', { className: 'tcr-code-text tcr-address' }, pairing.address),
|
|
918
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
919
|
+
h(CopyButton, { text: pairing.address, t, onResult: reportCopy }),
|
|
920
|
+
h(Button, { variant: 'ghost', onClick: () => setShowQr((value) => !value), 'aria-pressed': showQr }, showQr ? t('hideQr') : t('showQr')),
|
|
921
|
+
),
|
|
922
|
+
),
|
|
923
|
+
showQr
|
|
924
|
+
? h('div', { className: 'tcr-qr-wrap' },
|
|
925
|
+
pairing.qr
|
|
926
|
+
? h(QrCode, { matrix: pairing.qr, t })
|
|
927
|
+
: h('p', { className: 'tcr-hint', style: { marginTop: 0 } }, t('qrUnavailable')),
|
|
928
|
+
h('div', { className: 'tcr-hint', style: { marginTop: 0 } }, t('stepRun')),
|
|
929
|
+
)
|
|
930
|
+
: null,
|
|
931
|
+
h('label', { className: 'tcr-label', style: { marginTop: 16 } }, t('commandLabel')),
|
|
932
|
+
h(
|
|
933
|
+
'div',
|
|
934
|
+
{ className: 'tcr-code' },
|
|
935
|
+
h('span', { className: 'tcr-code-text' }, command),
|
|
936
|
+
h(CopyButton, { text: command, t, onResult: reportCopy }),
|
|
937
|
+
),
|
|
938
|
+
h('p', { className: 'tcr-hint' }, t('commandHint', { localPort: pairing.localPort, port: pairing.port })),
|
|
939
|
+
h('ol', { className: 'tcr-steps' },
|
|
940
|
+
h('li', null, t('stepInstall')),
|
|
941
|
+
h('li', null, t('stepRun')),
|
|
942
|
+
h('li', null, t('stepOpen', { localPort: pairing.localPort })),
|
|
943
|
+
),
|
|
944
|
+
h('label', { className: 'tcr-label', style: { marginTop: 16 } }, t('openLocal')),
|
|
945
|
+
h(
|
|
946
|
+
'div',
|
|
947
|
+
{ className: 'tcr-code' },
|
|
948
|
+
h('span', { className: 'tcr-code-text' }, localUrl),
|
|
949
|
+
h(CopyButton, { text: localUrl, t, onResult: reportCopy }),
|
|
950
|
+
h(
|
|
951
|
+
'a',
|
|
952
|
+
{ className: 'tcr-btn tcr-btn-ghost', href: localUrl, target: '_blank', rel: 'noopener noreferrer', style: { textDecoration: 'none' } },
|
|
953
|
+
t('openLocal'),
|
|
954
|
+
),
|
|
955
|
+
),
|
|
956
|
+
h('p', { className: 'tcr-hint' }, t('localUrlHint')),
|
|
957
|
+
)
|
|
958
|
+
: null,
|
|
959
|
+
|
|
960
|
+
h(
|
|
961
|
+
Card,
|
|
962
|
+
{ title: t('securityTitle') },
|
|
963
|
+
snapshot.devices.enforced
|
|
964
|
+
? h(Alert, { tone: 'info', title: t('allowOnTitle', { count: snapshot.devices.count }) }, t('allowOnBody'))
|
|
965
|
+
: h(Alert, { tone: 'danger', title: t('allowOffTitle') }, t('allowOffBody')),
|
|
966
|
+
h('label', { className: 'tcr-label', style: { marginTop: 16 } }, t('devicesLabel')),
|
|
967
|
+
h('textarea', {
|
|
968
|
+
className: 'tcr-textarea',
|
|
969
|
+
value: draft,
|
|
970
|
+
placeholder: t('devicesPlaceholder'),
|
|
971
|
+
spellCheck: false,
|
|
972
|
+
onChange: (event) => {
|
|
973
|
+
setDraft(event.target.value);
|
|
974
|
+
setDevicesDirty(true);
|
|
975
|
+
},
|
|
976
|
+
}),
|
|
977
|
+
h('p', { className: 'tcr-hint' }, t('devicesHint')),
|
|
978
|
+
h('p', { className: 'tcr-hint' }, t('devicesGenerate'), h('code', { className: 'tcr-mono' }, ' tailcat genkey --client --key=client-default')),
|
|
979
|
+
h(
|
|
980
|
+
'div',
|
|
981
|
+
{ className: 'tcr-actions' },
|
|
982
|
+
h(Button, { variant: 'primary', disabled: saveBusy || !devicesDirty, onClick: () => void saveDevices() }, saveBusy ? t('busySave') : t('devicesSave')),
|
|
983
|
+
h(Button, { variant: 'ghost', disabled: saveBusy || !devicesDirty, onClick: () => { setDevicesDirty(false); setDraft((snapshot.devices.allow ?? []).join('\n')); } }, t('devicesReset')),
|
|
984
|
+
),
|
|
985
|
+
snapshot.devices.warnings?.length
|
|
986
|
+
? h('ul', { className: 'tcr-warning-list' }, snapshot.devices.warnings.map((warning, index) => h('li', { key: index }, warning)))
|
|
987
|
+
: null,
|
|
988
|
+
h('div', { style: { marginTop: 20, paddingTop: 16, borderTop: '1px dashed var(--dsw-alias-border-l3)' } },
|
|
989
|
+
h('p', { className: 'tcr-card-title', style: { fontSize: 14 } }, t('rotate')),
|
|
990
|
+
h('p', { className: 'tcr-hint' }, t('rotateHint')),
|
|
991
|
+
h(
|
|
992
|
+
'div',
|
|
993
|
+
{ className: 'tcr-actions' },
|
|
994
|
+
rotateArmed
|
|
995
|
+
? h(Button, { variant: 'danger', disabled: Boolean(busy), onClick: () => void rotate() }, t('rotateConfirm'))
|
|
996
|
+
: h(Button, { variant: 'danger', disabled: Boolean(busy), onClick: () => setRotateArmed(true) }, t('rotate')),
|
|
997
|
+
rotateArmed
|
|
998
|
+
? h(Button, { variant: 'ghost', disabled: Boolean(busy), onClick: () => setRotateArmed(false) }, t('cancel'))
|
|
999
|
+
: null,
|
|
1000
|
+
),
|
|
1001
|
+
h('p', { className: 'tcr-hint' }, t('rotateCaveat')),
|
|
1002
|
+
h('p', { className: 'tcr-hint' }, t('rotateDisconnect')),
|
|
1003
|
+
),
|
|
1004
|
+
),
|
|
1005
|
+
|
|
1006
|
+
h(
|
|
1007
|
+
Card,
|
|
1008
|
+
{ title: t('diagnosticsTitle') },
|
|
1009
|
+
h(
|
|
1010
|
+
'div',
|
|
1011
|
+
{ className: 'tcr-grid' },
|
|
1012
|
+
h(Row, { label: t('diagPhase') }, t(PHASE_KEY[phase] ?? 'statusUnknown')),
|
|
1013
|
+
h(Row, { label: t('diagAddressMode') }, tailcat.addressMode === 'ephemeral' ? t('modeEphemeral') : t('modeStable')),
|
|
1014
|
+
h(Row, { label: t('diagKeyName') }, h('span', { className: 'tcr-mono' }, tailcat.keyName)),
|
|
1015
|
+
h(Row, { label: t('diagVersion') }, tailcat.binary?.version ?? t('unknown')),
|
|
1016
|
+
h(Row, { label: t('diagBinary') }, h('span', { className: 'tcr-mono' }, tailcat.binary?.resolved ?? snapshot.config.binaryPath)),
|
|
1017
|
+
h(Row, { label: t('diagBinarySource') }, sourceLabel),
|
|
1018
|
+
h(Row, { label: t('diagInstallSource') }, installer?.installed ? `${t('sourceManaged')} · ${installer.installedVersion ?? t('unknown')}` : systemFound ? `${t('sourcePath')} · ${system.version ?? t('unknown')}` : t('sourceUnavailable')),
|
|
1019
|
+
h(Row, { label: t('diagRegion') }, tailcat.region ? `${tailcat.region.name} (${tailcat.region.id})` : t('unknown')),
|
|
1020
|
+
h(Row, { label: t('diagRestarts') }, String(tailcat.restarts ?? 0)),
|
|
1021
|
+
h(Row, { label: t('diagDoor') }, snapshot.door.mode === 'socket' ? `${t('modeSocket')} · ${snapshot.door.socketPath}` : `${t('modeTcp')} · 127.0.0.1:${snapshot.door.port}`),
|
|
1022
|
+
h(Row, { label: t('diagTarget') }, snapshot.door.target ? `${snapshot.door.target.host}:${snapshot.door.target.port}` : t('unknown')),
|
|
1023
|
+
h(Row, { label: t('diagLastError') }, tailcat.lastError ?? t('never')),
|
|
1024
|
+
),
|
|
1025
|
+
tailcat.warnings?.length
|
|
1026
|
+
? h('ul', { className: 'tcr-warning-list' }, tailcat.warnings.map((warning, index) => h('li', { key: index }, warning)))
|
|
1027
|
+
: null,
|
|
1028
|
+
),
|
|
1029
|
+
|
|
1030
|
+
h(
|
|
1031
|
+
Card,
|
|
1032
|
+
{ title: t('recentTitle') },
|
|
1033
|
+
tailcat.recent?.length
|
|
1034
|
+
? h(
|
|
1035
|
+
'div',
|
|
1036
|
+
{ className: 'tcr-recent' },
|
|
1037
|
+
h(
|
|
1038
|
+
'div',
|
|
1039
|
+
{ className: 'tcr-recent-row tcr-recent-head' },
|
|
1040
|
+
h('span', null, t('recentPeer')),
|
|
1041
|
+
h('span', null, t('recentPort')),
|
|
1042
|
+
h('span', null, t('recentVia')),
|
|
1043
|
+
h('span', null, t('recentDuration')),
|
|
1044
|
+
h('span', null, t('recentTime')),
|
|
1045
|
+
),
|
|
1046
|
+
...tailcat.recent.slice(0, 8).map((entry, index) =>
|
|
1047
|
+
h(
|
|
1048
|
+
'div',
|
|
1049
|
+
{ className: 'tcr-recent-row', key: `${entry.at}-${index}` },
|
|
1050
|
+
h('span', { className: 'tcr-mono', title: entry.peer ?? entry.reason ?? '' }, entry.peer ?? t('unknown')),
|
|
1051
|
+
h('span', null, entry.port ?? '—'),
|
|
1052
|
+
h('span', null, entry.via ?? entry.reason ?? '—'),
|
|
1053
|
+
h('span', null, formatDuration(entry.durationMs)),
|
|
1054
|
+
h('span', { title: entry.at }, formatTime(entry.at)),
|
|
1055
|
+
),
|
|
1056
|
+
),
|
|
1057
|
+
)
|
|
1058
|
+
: h('div', { className: 'tcr-empty' }, t('recentEmpty')),
|
|
1059
|
+
),
|
|
1060
|
+
|
|
1061
|
+
h(
|
|
1062
|
+
'div',
|
|
1063
|
+
{ className: 'tcr-footer' },
|
|
1064
|
+
h('span', null, `${install} · v${snapshot.plugin.version}`),
|
|
1065
|
+
h('span', null, t('footerNote')),
|
|
1066
|
+
),
|
|
1067
|
+
),
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* @param {string} key - translation key.
|
|
1073
|
+
* @param {object} [params] - named placeholders.
|
|
1074
|
+
* @returns {string} translated copy.
|
|
1075
|
+
*/
|
|
1076
|
+
function translate(t, key, params) {
|
|
1077
|
+
return params ? t(key, params) : t(key);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Copy text through the async clipboard API, with a legacy fallback for
|
|
1082
|
+
* browsers that only allow copy from a user-gesture-owned textarea.
|
|
1083
|
+
* @param {string} text - payload.
|
|
1084
|
+
* @returns {Promise<boolean>} whether the copy succeeded.
|
|
1085
|
+
*/
|
|
1086
|
+
async function copyText(text) {
|
|
1087
|
+
try {
|
|
1088
|
+
await navigator.clipboard.writeText(text);
|
|
1089
|
+
return true;
|
|
1090
|
+
} catch {
|
|
1091
|
+
try {
|
|
1092
|
+
const area = document.createElement('textarea');
|
|
1093
|
+
area.value = text;
|
|
1094
|
+
area.style.position = 'fixed';
|
|
1095
|
+
area.style.top = '-1000px';
|
|
1096
|
+
area.style.opacity = '0';
|
|
1097
|
+
document.body.appendChild(area);
|
|
1098
|
+
area.select();
|
|
1099
|
+
const ok = document.execCommand('copy');
|
|
1100
|
+
area.remove();
|
|
1101
|
+
return ok;
|
|
1102
|
+
} catch {
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Turn a server QR matrix into one crisp SVG path plus quiet zone.
|
|
1110
|
+
* @param {{ size: number, rows: string[] }} matrix - matrix from the Host.
|
|
1111
|
+
* @param {number} [quietZone] - white border in modules.
|
|
1112
|
+
* @returns {{ viewBox: string, path: string }} geometry.
|
|
1113
|
+
*/
|
|
1114
|
+
function qrGeometry(matrix, quietZone = 2) {
|
|
1115
|
+
const total = matrix.size + quietZone * 2;
|
|
1116
|
+
let path = '';
|
|
1117
|
+
for (let row = 0; row < matrix.rows.length; row += 1) {
|
|
1118
|
+
const bits = matrix.rows[row];
|
|
1119
|
+
let column = 0;
|
|
1120
|
+
while (column < bits.length) {
|
|
1121
|
+
if (bits[column] !== '1') {
|
|
1122
|
+
column += 1;
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
const start = column;
|
|
1126
|
+
while (column < bits.length && bits[column] === '1') column += 1;
|
|
1127
|
+
path += `M${start + quietZone} ${row + quietZone}h${column - start}v1h-${column - start}z`;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return { viewBox: `0 0 ${total} ${total}`, path };
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* @param {number | null | undefined} ms - duration.
|
|
1135
|
+
* @returns {string} compact duration.
|
|
1136
|
+
*/
|
|
1137
|
+
function formatDuration(ms) {
|
|
1138
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms)) return '—';
|
|
1139
|
+
if (ms < 1_000) return `${Math.round(ms)} ms`;
|
|
1140
|
+
if (ms < 60_000) return `${(ms / 1_000).toFixed(1)} s`;
|
|
1141
|
+
return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1_000)}s`;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* @param {number | null | undefined} bytes - byte count.
|
|
1146
|
+
* @returns {string} compact size for installer progress.
|
|
1147
|
+
*/
|
|
1148
|
+
function formatBytes(bytes) {
|
|
1149
|
+
if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes <= 0) return '0 B';
|
|
1150
|
+
if (bytes < 1_024) return `${bytes} B`;
|
|
1151
|
+
if (bytes < 1_048_576) return `${(bytes / 1_024).toFixed(1)} KB`;
|
|
1152
|
+
return `${(bytes / 1_048_576).toFixed(1)} MB`;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* @param {string | null | undefined} iso - timestamp.
|
|
1157
|
+
* @returns {string} local clock time.
|
|
1158
|
+
*/
|
|
1159
|
+
function formatTime(iso) {
|
|
1160
|
+
if (!iso) return '—';
|
|
1161
|
+
try {
|
|
1162
|
+
return new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' }).format(new Date(iso));
|
|
1163
|
+
} catch {
|
|
1164
|
+
return String(iso);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
return {
|
|
1169
|
+
inject: ['slots', 'locale'],
|
|
1170
|
+
apply(ctx) {
|
|
1171
|
+
const t = ctx.locale.bind(NS);
|
|
1172
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'tailcat-remote: dictionaries');
|
|
1173
|
+
ctx.effect(
|
|
1174
|
+
() =>
|
|
1175
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
1176
|
+
ctx.slots.register(
|
|
1177
|
+
{
|
|
1178
|
+
name: 'sidebar.panellist',
|
|
1179
|
+
id: 'tailcat-remote',
|
|
1180
|
+
order: 30,
|
|
1181
|
+
label: () => translate(t, 'nav'),
|
|
1182
|
+
},
|
|
1183
|
+
PanelIcon,
|
|
1184
|
+
),
|
|
1185
|
+
),
|
|
1186
|
+
'tailcat-remote: sidebar entry',
|
|
1187
|
+
);
|
|
1188
|
+
ctx.effect(
|
|
1189
|
+
() =>
|
|
1190
|
+
ctx.slots.inject('main', () =>
|
|
1191
|
+
ctx.slots.register(
|
|
1192
|
+
{
|
|
1193
|
+
name: 'main',
|
|
1194
|
+
key: 'tailcat-remote',
|
|
1195
|
+
locale: NS,
|
|
1196
|
+
},
|
|
1197
|
+
RemotePage,
|
|
1198
|
+
),
|
|
1199
|
+
),
|
|
1200
|
+
'tailcat-remote: page',
|
|
1201
|
+
);
|
|
1202
|
+
},
|
|
1203
|
+
};
|
|
1204
|
+
},
|
|
1205
|
+
});
|