| 1 | import { MobilePairSettings } from "./mobile-pair-settings"; |
| 2 | import { ArchivedSessions } from "./cli-sessions"; |
| 3 | import { Smartphone } from "lucide-react"; |
| 4 | import { PasswordVaultSettings } from "./password-vault"; |
| 5 | import { KeyRound } from "lucide-react"; |
| 6 | import { InlineSelect } from "./inline-select"; |
| 7 | import { clientKeyboard, isRemoteClient, saveClientKeyboard } from "./client-context.mjs"; |
| 8 | import { shortcut, usesControl } from "./platform.mjs"; |
| 9 | import React, { useEffect, useMemo, useRef, useState } from "react"; |
| 10 | import { |
| 11 | Globe2, |
| 12 | Clock3, |
| 13 | FolderOpen, |
| 14 | Check, |
| 15 | LoaderCircle, |
| 16 | RotateCcw, |
| 17 | ArrowLeft, |
| 18 | Settings, |
| 19 | Palette, |
| 20 | UserRound, |
| 21 | UsersRound, |
| 22 | Archive, |
| 23 | } from "lucide-react"; |
| 24 | import { api } from "./api"; |
| 25 | import { SafetyMessage } from "./safety-message"; |
| 26 | import { AppearanceSettings } from "./appearance-settings"; |
| 27 | import { ProxySettings } from "./proxy-settings"; |
| 28 | import { ExitPolicyFields } from "./exit-policy"; |
| 29 | import { canonicalExitPolicy } from "./safety-state.mjs"; |
| 30 | import { EnvironmentVersions } from "./environment-versions"; |
| 31 | import { EnvironmentStorage } from "./environment-storage"; |
| 32 | import { ResourceSettings } from "./resources"; |
| 33 | import { DiagnosticSettings } from "./diagnostics.jsx"; |
| 34 | import { MacOSLogin } from "./macos-login"; |
| 35 | import { AccountSettings } from "./account"; |
| 36 | import { ClaudeAccountsPanel } from "./claude-accounts"; |
| 37 | const sections = [ |
| 38 | ["account", "账户", UserRound], |
| 39 | ["vault", "密码保险箱", KeyRound], |
| 40 | ["claude-accounts", "Claude 账号", UsersRound], |
| 41 | ["archived-sessions", "已归档会话", Archive], |
| 42 | ["keyboard", "通用", Settings], |
| 43 | ["appearance", "外观", Palette], |
| 44 | ["mobile", "远程连接", Smartphone], |
| 45 | ["network", "网络与代理", Globe2], |
| 46 | ["region", "时区与语言", Clock3], |
| 47 | ["project", "环境与恢复", RotateCcw], |
| 48 | ]; |
| 49 | export function SettingsPanel({ |
| 50 | current, |
| 51 | status, |
| 52 | onClose, |
| 53 | onSaved, |
| 54 | onConfirm, |
| 55 | claudeProfiles, |
| 56 | terminalTabs, |
| 57 | onClaudeLogin, |
| 58 | initialSection = "keyboard", |
| 59 | }) { |
| 60 | const [localKeyboard, setLocalKeyboard] = useState(() => clientKeyboard(current.keyboard)); |
| 61 | const [accountDirty, setAccountDirty] = useState(false); |
| 62 | const [proxyDirty, setProxyDirty] = useState(false); |
| 63 | const [resourceDirty, setResourceDirty] = useState(false); |
| 64 | const [draft, setDraft] = useState({ ...current }), |
| 65 | [section, setSection] = useState(initialSection), |
| 66 | [probe, setProbe] = useState(null), |
| 67 | [probing, setProbing] = useState(false), |
| 68 | [probeFailed, setProbeFailed] = useState(false), |
| 69 | [error, setError] = useState(""), |
| 70 | [jobId, setJobId] = useState(""), |
| 71 | [submitting, setSubmitting] = useState(false); |
| 72 | const changed = |
| 73 | JSON.stringify({ |
| 74 | ...draft, |
| 75 | browser_home_url: undefined, |
| 76 | exit_policy: canonicalExitPolicy(draft.exit_policy), |
| 77 | }) !== |
| 78 | JSON.stringify({ |
| 79 | ...current, |
| 80 | browser_home_url: undefined, |
| 81 | exit_policy: canonicalExitPolicy(current.exit_policy), |
| 82 | }); |
| 83 | const environmentChanged = [ |
| 84 | "dns_url", |
| 85 | "timezone", |
| 86 | "locale", |
| 87 | "browser_language", |
| 88 | "auto_timezone", |
| 89 | "auto_language", |
| 90 | "exit_policy", |
| 91 | ].some((k) => |
| 92 | k === "exit_policy" |
| 93 | ? JSON.stringify(canonicalExitPolicy(draft[k])) !== |
| 94 | JSON.stringify(canonicalExitPolicy(current[k])) |
| 95 | : draft[k] !== current[k], |
| 96 | ); |
| 97 | const busy = |
| 98 | Boolean(status.job?.running) || Boolean(status.storage_recovery?.required) || probing || submitting || Boolean(jobId); |
| 99 | const update = (key, value) => { |
| 100 | setDraft((p) => ({ ...p, [key]: value })); |
| 101 | if (["dns_url"].includes(key)) setProbe(null); |
| 102 | setError(""); |
| 103 | }; |
| 104 | const close = async () => { |
| 105 | if (submitting) return; |
| 106 | if (status.job?.running && jobId) { |
| 107 | onClose(); |
| 108 | return; |
| 109 | } |
| 110 | if ( |
| 111 | (!changed && !accountDirty && !proxyDirty && !resourceDirty) || |
| 112 | (await onConfirm({ |
| 113 | title: "放弃尚未保存的修改?", |
| 114 | body: "当前环境不会改变。关闭后会丢弃这次表单修改。", |
| 115 | confirm: "放弃修改", |
| 116 | })) |
| 117 | ) |
| 118 | onClose(); |
| 119 | }; |
| 120 | useEffect(() => { |
| 121 | if (jobId && status.job?.id === jobId && !status.job.running) { |
| 122 | setJobId(""); |
| 123 | if (status.job.error || status.job.canceled) { |
| 124 | if (status.job.settings_saved) onSaved(); |
| 125 | setError(status.job.error || status.job.message); |
| 126 | } else { |
| 127 | onSaved(); |
| 128 | if (!proxyDirty) onClose(); |
| 129 | } |
| 130 | } |
| 131 | }, [status.job, jobId]); |
| 132 | const check = async () => { |
| 133 | setProbing(true); |
| 134 | setProbeFailed(false); |
| 135 | setError(""); |
| 136 | try { |
| 137 | const result = await api("/settings/probe", draft); |
| 138 | setProbe(result); |
| 139 | if (draft.auto_timezone) |
| 140 | setDraft((previous) => ({ ...previous, timezone: result.timezone })); |
| 141 | if (draft.auto_language && result.suggested_locale) |
| 142 | setDraft((previous) => ({ |
| 143 | ...previous, |
| 144 | locale: result.suggested_locale, |
| 145 | browser_language: result.suggested_browser_language, |
| 146 | })); |
| 147 | } catch (e) { |
| 148 | setError(e.message); |
| 149 | setProbeFailed(true); |
| 150 | } finally { |
| 151 | setProbing(false); |
| 152 | } |
| 153 | }; |
| 154 | const save = async () => { |
| 155 | if (busy) return; |
| 156 | if ( |
| 157 | environmentChanged && |
| 158 | status.vm_running && |
| 159 | !(await onConfirm({ |
| 160 | title: "应用设置并重启环境?", |
| 161 | body: "请先保存编辑器中的文件。当前终端会话会结束,浏览器的页面和登录状态将保留。", |
| 162 | confirm: "保存并重启", |
| 163 | })) |
| 164 | ) |
| 165 | return; |
| 166 | setError(""); |
| 167 | setSubmitting(true); |
| 168 | try { |
| 169 | const payload = { ...draft }; |
| 170 | delete payload.browser_home_url; |
| 171 | const result = await api("/settings", payload); |
| 172 | setJobId(result.id); |
| 173 | } catch (e) { |
| 174 | setError(e.message); |
| 175 | } finally { |
| 176 | setSubmitting(false); |
| 177 | } |
| 178 | }; |
| 179 | const zones = useMemo( |
| 180 | () => [ |
| 181 | ...new Set([ |
| 182 | "Etc/UTC", |
| 183 | current.timezone, |
| 184 | ...(Intl.supportedValuesOf?.("timeZone") || []), |
| 185 | ]), |
| 186 | ], |
| 187 | [], |
| 188 | ); |
| 189 | const contentRef = useRef(); |
| 190 | useEffect(() => { |
| 191 | contentRef.current?.scrollTo(0, 0); |
| 192 | }, [section]); |
| 193 | const currentLoc = probe || status.location; |
| 194 | const closeRef = useRef(close); |
| 195 | closeRef.current = close; |
| 196 | useEffect(() => { |
| 197 | const previous = document.activeElement; |
| 198 | document.getElementById("settings-back")?.focus(); |
| 199 | const dismiss = (event) => { |
| 200 | if (document.querySelector('[role="dialog"]')) return; |
| 201 | if (event.type === "cage-close-modal" || event.key === "Escape") { |
| 202 | event.preventDefault(); |
| 203 | closeRef.current(); |
| 204 | } |
| 205 | }; |
| 206 | document.addEventListener("keydown", dismiss); |
| 207 | document.addEventListener("cage-close-modal", dismiss); |
| 208 | return () => { |
| 209 | document.removeEventListener("keydown", dismiss); |
| 210 | document.removeEventListener("cage-close-modal", dismiss); |
| 211 | previous?.focus?.(); |
| 212 | }; |
| 213 | }, []); |
| 214 | return ( |
| 215 | <section className="settings-page" aria-label="设置"> |
| 216 | <aside className="settings-sidebar"> |
| 217 | <button |
| 218 | id="settings-back" |
| 219 | className="back-to-workspace" |
| 220 | onClick={close} |
| 221 | > |
| 222 | <ArrowLeft size={17} /> |
| 223 | 返回工作台 |
| 224 | </button> |
| 225 | <h2>设置</h2> |
| 226 | <nav aria-label="设置分组"> |
| 227 | {sections.map(([id, label, Icon]) => ( |
| 228 | <button |
| 229 | key={id} |
| 230 | className={section === id ? "selected" : ""} |
| 231 | aria-current={section === id ? "page" : undefined} |
| 232 | onClick={async () => { |
| 233 | if (id !== section && accountDirty && !(await onConfirm({ title: "放弃尚未保存的修改?", body: "已保存的资料和密码保持不变。", confirm: "放弃修改" }))) return; |
| 234 | if (id !== section && proxyDirty && !(await onConfirm({ title: "放弃尚未应用的代理修改?", body: "当前代理仍按已应用的链路运行。离开会丢弃这次节点选择。", confirm: "放弃修改" }))) return; |
| 235 | setSection(id); |
| 236 | }} |
| 237 | > |
| 238 | <Icon size={17} /> |
| 239 | {label} |
| 240 | </button> |
| 241 | ))} |
| 242 | </nav> |
| 243 | </aside> |
| 244 | <div className="settings-main"> |
| 245 | <div className={section === "archived-sessions" ? "settings-content settings-content--archives" : section === "claude-accounts" ? "settings-content settings-content--accounts" : section === "mobile" ? "settings-content settings-content--remote" : "settings-content"} ref={contentRef}> |
| 246 | {section === "appearance" && <AppearanceSettings />} |
| 247 | {section === "archived-sessions" && <ArchivedSessions ready={status.ready && !busy} />} |
| 248 | {section === "vault" && <PasswordVaultSettings onConfirm={onConfirm} onDirty={setAccountDirty} />} |
| 249 | {section === "account" && <AccountSettings busy={busy} onDirty={setAccountDirty} />} |
| 250 | {section === "claude-accounts" && <ClaudeAccountsPanel store={claudeProfiles} tabs={terminalTabs} onConfirm={onConfirm} |
| 251 | running={status.vm_running} environmentBusy={busy} login={async (id) => { |
| 252 | if (changed && !(await onConfirm({ title: "放弃尚未保存的设置并登录?", |
| 253 | body: "打开登录终端会离开设置页。", confirm: "打开登录终端" }))) return; |
| 254 | await onClaudeLogin(id); |
| 255 | onClose(); |
| 256 | }} />} |
| 257 | <fieldset className="settings-fields" disabled={busy && !(section === "project" && status.storage_recovery?.required)}> |
| 258 | {section === "mobile" && (isRemoteClient() |
| 259 | ? <section className="section-title"><h3>连接这台电脑</h3><p>请先切换到这台电脑的本机环境,再生成或管理手机配对码。</p></section> |
| 260 | : <MobilePairSettings relay={draft.mobile_relay ?? ""} savedRelay={current.mobile_relay ?? ""} onChange={value => update("mobile_relay",value)} onConfirm={onConfirm} />)} |
| 261 | {section === "network" && ( |
| 262 | <> |
| 263 | <ProxySettings |
| 264 | onDirty={setProxyDirty} |
| 265 | status={status} |
| 266 | onConfirm={onConfirm} |
| 267 | onApplied={async () => { |
| 268 | setProbe(null); |
| 269 | onSaved(); |
| 270 | }} |
| 271 | /> |
| 272 | <label> |
| 273 | 加密 DNS |
| 274 | <input |
| 275 | value={draft.dns_url} |
| 276 | onChange={(e) => update("dns_url", e.target.value)} |
| 277 | spellCheck="false" |
| 278 | /> |
| 279 | </label> |
| 280 | <div className="probe-line"> |
| 281 | <button disabled={busy} onClick={check}> |
| 282 | {probing ? ( |
| 283 | <LoaderCircle size={15} className="spin" /> |
| 284 | ) : ( |
| 285 | <Globe2 size={15} /> |
| 286 | )} |
| 287 | 验证出口 |
| 288 | </button> |
| 289 | <span>通过当前节点查询 IP 和位置</span> |
| 290 | </div> |
| 291 | {currentLoc && ( |
| 292 | <div className={`location-result ${probe ? "fresh" : ""}`}> |
| 293 | <span className="result-icon"> |
| 294 | <Globe2 size={19} /> |
| 295 | </span> |
| 296 | <div> |
| 297 | <strong> |
| 298 | {currentLoc.country} · {currentLoc.city} |
| 299 | </strong> |
| 300 | <code>{currentLoc.ip}</code> |
| 301 | <small> |
| 302 | {currentLoc.timezone} ·{" "} |
| 303 | {new Date(currentLoc.checked_at).toLocaleTimeString( |
| 304 | "zh-CN", |
| 305 | { hour: "2-digit", minute: "2-digit" }, |
| 306 | )}{" "} |
| 307 | {probe ? "验证通过" : "当前环境 · 最近检测"} |
| 308 | </small> |
| 309 | </div> |
| 310 | {probe && <Check size={18} />} |
| 311 | </div> |
| 312 | )} |
| 313 | <p className="footnote"> |
| 314 | 代理不可用时,Cage 会停止对外联网。修改表单后需要重新验证。 |
| 315 | </p> |
| 316 | <section className="network-exit-policy" aria-label="IP 变化规则"> |
| 317 | <ExitPolicyFields |
| 318 | value={draft.exit_policy} |
| 319 | onChange={(value) => update("exit_policy", value)} |
| 320 | observation={probe} |
| 321 | onProbe={check} |
| 322 | busy={busy} |
| 323 | probing={probing} |
| 324 | /> |
| 325 | </section> |
| 326 | </> |
| 327 | )} |
| 328 | {section === "region" && ( |
| 329 | <> |
| 330 | <div className="section-title"> |
| 331 | <h3>时区与语言</h3> |
| 332 | <p>这些设置作用于 Cage 内的系统、CLI 和浏览器。</p> |
| 333 | </div> |
| 334 | {!draft.auto_timezone && !draft.auto_language && ( |
| 335 | <p className="field-help"> |
| 336 | 时区和语言将使用下方手动选择的值。所有出口仍须查询国家或地区,确认不属于中国大陆;静态 IP 和不限地区也不能跳过此检查。 |
| 337 | </p> |
| 338 | )} |
| 339 | <label className="toggle-row"> |
| 340 | <span> |
| 341 | <strong>跟随出口 IP 的时区</strong> |
| 342 | <small> |
| 343 | 在启动或应用设置时重新查询,不会静默重启正在运行的任务。 |
| 344 | </small> |
| 345 | </span> |
| 346 | <input |
| 347 | role="switch" |
| 348 | type="checkbox" |
| 349 | checked={draft.auto_timezone} |
| 350 | onChange={(e) => update("auto_timezone", e.target.checked)} |
| 351 | /> |
| 352 | </label> |
| 353 | <label> |
| 354 | {draft.auto_timezone ? "将应用的时区" : "系统时区"} |
| 355 | <InlineSelect editable |
| 356 | aria-label={draft.auto_timezone ? "将应用的时区" : "系统时区"} |
| 357 | value={draft.timezone} |
| 358 | disabled={draft.auto_timezone} |
| 359 | onValueChange={(next) => update("timezone", next)} |
| 360 | > |
| 361 | {zones.map((zone) => ( |
| 362 | <option key={zone} value={zone} /> |
| 363 | ))} |
| 364 | </InlineSelect> |
| 365 | </label> |
| 366 | {draft.auto_timezone && ( |
| 367 | <div className="inline-info"> |
| 368 | <Clock3 size={16} /> |
| 369 | <span> |
| 370 | {probe |
| 371 | ? `出口建议时区:${probe.timezone},保存时应用。` |
| 372 | : "保存时经代理查询所在地;查询失败会保留原配置。"} |
| 373 | </span> |
| 374 | <button |
| 375 | className="text-button" |
| 376 | onClick={check} |
| 377 | disabled={busy} |
| 378 | > |
| 379 | 现在检测 |
| 380 | </button> |
| 381 | </div> |
| 382 | )} |
| 383 | <label className="toggle-row"> |
| 384 | <span> |
| 385 | <strong>跟随出口地区的语言建议</strong> |
| 386 | <small> |
| 387 | 启动或应用设置时更新。多语言地区使用内置默认值;没有建议时保留已选语言。 |
| 388 | </small> |
| 389 | </span> |
| 390 | <input |
| 391 | role="switch" |
| 392 | type="checkbox" |
| 393 | checked={Boolean(draft.auto_language)} |
| 394 | onChange={(e) => update("auto_language", e.target.checked)} |
| 395 | /> |
| 396 | </label> |
| 397 | {draft.auto_language && ( |
| 398 | <div className="inline-info"> |
| 399 | <Globe2 size={16} /> |
| 400 | <span> |
| 401 | {currentLoc?.suggested_locale |
| 402 | ? `地区建议:${currentLoc.suggested_locale} / ${currentLoc.suggested_browser_language}` |
| 403 | : "检测出口后获取地区建议,也可以关闭自动并手动选择。"} |
| 404 | </span> |
| 405 | <button |
| 406 | className="text-button" |
| 407 | onClick={check} |
| 408 | disabled={busy} |
| 409 | > |
| 410 | 现在检测 |
| 411 | </button> |
| 412 | </div> |
| 413 | )} |
| 414 | <label> |
| 415 | 系统语言 |
| 416 | <InlineSelect |
| 417 | aria-label="系统语言" |
| 418 | value={draft.locale} |
| 419 | disabled={draft.auto_language} |
| 420 | onValueChange={(next) => update("locale", next)} |
| 421 | > |
| 422 | {[ |
| 423 | ["en_US.UTF-8", "English (United States)"], |
| 424 | ["zh_CN.UTF-8", "简体中文"], |
| 425 | ["zh_TW.UTF-8", "繁體中文"], |
| 426 | ["ja_JP.UTF-8", "日本語"], |
| 427 | ["de_DE.UTF-8", "Deutsch"], |
| 428 | ["fr_FR.UTF-8", "Français"], |
| 429 | ].map(([value, label]) => ( |
| 430 | <option key={value} value={value}> |
| 431 | {label} |
| 432 | </option> |
| 433 | ))} |
| 434 | {![ |
| 435 | "en_US.UTF-8", |
| 436 | "zh_CN.UTF-8", |
| 437 | "zh_TW.UTF-8", |
| 438 | "ja_JP.UTF-8", |
| 439 | "de_DE.UTF-8", |
| 440 | "fr_FR.UTF-8", |
| 441 | ].includes(draft.locale) && ( |
| 442 | <option value={draft.locale}>{draft.locale}</option> |
| 443 | )} |
| 444 | </InlineSelect> |
| 445 | </label> |
| 446 | <label> |
| 447 | 网页首选语言 |
| 448 | <InlineSelect |
| 449 | aria-label="网页首选语言" |
| 450 | value={draft.browser_language} |
| 451 | disabled={draft.auto_language} |
| 452 | onValueChange={(next) => update("browser_language", next)} |
| 453 | > |
| 454 | {[ |
| 455 | ["en-US", "English (United States)"], |
| 456 | ["zh-CN", "简体中文"], |
| 457 | ["zh-TW", "繁體中文"], |
| 458 | ["ja-JP", "日本語"], |
| 459 | ["de-DE", "Deutsch"], |
| 460 | ["fr-FR", "Français"], |
| 461 | ].map(([value, label]) => ( |
| 462 | <option key={value} value={value}> |
| 463 | {label} |
| 464 | </option> |
| 465 | ))} |
| 466 | {![ |
| 467 | "en-US", |
| 468 | "zh-CN", |
| 469 | "zh-TW", |
| 470 | "ja-JP", |
| 471 | "de-DE", |
| 472 | "fr-FR", |
| 473 | ].includes(draft.browser_language) && ( |
| 474 | <option value={draft.browser_language}> |
| 475 | {draft.browser_language} |
| 476 | </option> |
| 477 | )} |
| 478 | </InlineSelect> |
| 479 | </label> |
| 480 | <p className="footnote"> |
| 481 | 网页仍可按自己的规则选择语言。工作台界面使用中文。 |
| 482 | </p> |
| 483 | </> |
| 484 | )} |
| 485 | {section === "keyboard" && ( |
| 486 | <> |
| 487 | <div className="section-title"> |
| 488 | <h3>通用</h3> |
| 489 | <p>管理工作台的按键习惯与日常操作。</p> |
| 490 | </div> |
| 491 | <label> |
| 492 | Claude 终端启动命令 |
| 493 | <input |
| 494 | value={draft.claude_terminal_command ?? "claude"} |
| 495 | onChange={(e) => update("claude_terminal_command", e.target.value)} |
| 496 | placeholder="claude" |
| 497 | maxLength={4096} |
| 498 | spellCheck="false" |
| 499 | autoComplete="off" |
| 500 | /> |
| 501 | </label> |
| 502 | <p className="field-help"> |
| 503 | 选择“Claude 终端”后,在所选项目中运行此命令,例如 claude --continue。 |
| 504 | 留空使用 claude;保存后仅影响新建的 Claude 终端,退出 Claude 后可继续使用 shell。 |
| 505 | </p> |
| 506 | {typeof current.balanced_display === "boolean" && <label className="toggle-row"> |
| 507 | <span> |
| 508 | <strong>优先流畅</strong> |
| 509 | <small>降低浏览器和 Claude Desktop 的清晰度。下次启动环境时生效。</small> |
| 510 | </span> |
| 511 | <input type="checkbox" role="switch" checked={draft.balanced_display} |
| 512 | onChange={(event) => update("balanced_display", event.target.checked)} /> |
| 513 | </label>} |
| 514 | <h4>键盘习惯</h4> |
| 515 | <div className="choice-list"> |
| 516 | {[ |
| 517 | [ |
| 518 | "mac", |
| 519 | "Mac 快捷键", |
| 520 | "使用 ⌘ 操作网页和编辑器。Linux、Windows 客机使用对应的 Ctrl 快捷键,macOS 客机保留 Command。", |
| 521 | ], |
| 522 | [ |
| 523 | "native", |
| 524 | "客机原生快捷键", |
| 525 | "按客机系统的习惯使用 Control、Command 和其他组合键。", |
| 526 | ], |
| 527 | ].map(([value, title, help]) => ( |
| 528 | <label |
| 529 | className={`choice ${(isRemoteClient() ? localKeyboard : draft.keyboard) === value ? "checked" : ""}`} |
| 530 | key={value} |
| 531 | > |
| 532 | <input |
| 533 | type="radio" |
| 534 | name="keyboard" |
| 535 | value={value} |
| 536 | checked={(isRemoteClient() ? localKeyboard : draft.keyboard) === value} |
| 537 | onChange={() => { |
| 538 | if (!isRemoteClient()) { update("keyboard", value); return; } |
| 539 | try { saveClientKeyboard(value); setLocalKeyboard(value); setError(""); } |
| 540 | catch { setError("未能保存本机键盘习惯,请检查本地存储空间。"); } |
| 541 | }} |
| 542 | /> |
| 543 | <span> |
| 544 | <strong>{title}</strong> |
| 545 | <small>{help}</small> |
| 546 | </span> |
| 547 | </label> |
| 548 | ))} |
| 549 | </div> |
| 550 | <p className="field-help"> |
| 551 | 终端使用 {usesControl ? "Ctrl+Shift+C / Ctrl+Shift+V" : "⌘C / ⌘V"} 复制粘贴;Ctrl+C 始终用于中断命令。 |
| 552 | {isRemoteClient() && "键盘习惯立即生效,仅保存在当前客户端,不修改云端设置。"} |
| 553 | </p> |
| 554 | <h4>工作台快捷键</h4> |
| 555 | <div className="shortcut-list"> |
| 556 | {[ |
| 557 | ["打开项目", "⌘O"], |
| 558 | ["新建网页", "⌘T"], |
| 559 | ["新建终端", "⌘⇧↵"], |
| 560 | ["地址栏", "⌘L"], |
| 561 | ["关闭当前标签", "⌘W"], |
| 562 | ["切换标签", "⌘1–9"], |
| 563 | ["设置", "⌘,"], |
| 564 | ].map(([label, key]) => ( |
| 565 | <div key={label}> |
| 566 | <span>{label}</span> |
| 567 | <kbd>{shortcut(key)}</kbd> |
| 568 | </div> |
| 569 | ))} |
| 570 | </div> |
| 571 | </> |
| 572 | )} |
| 573 | {section === "project" && ( |
| 574 | <> |
| 575 | <div className="section-title"> |
| 576 | <h3>环境与恢复</h3> |
| 577 | <p>{isRemoteClient() ? "项目位于云端,Cage 中的改动会直接保存到云端文件。" : "本机与 Cage 中的改动会双向同步。"}</p> |
| 578 | </div> |
| 579 | {status.local_vm_storage && !isRemoteClient() && <EnvironmentStorage status={status} onConfirm={onConfirm} />} |
| 580 | <div className="setting-summary-row"> |
| 581 | <span>当前项目</span> |
| 582 | <strong title={current.workspace}> |
| 583 | {status.environment_workspace |
| 584 | ? "Cage 默认工作区" |
| 585 | : current.workspace || "尚未选择项目"} |
| 586 | </strong> |
| 587 | </div> |
| 588 | <p className="field-help"> |
| 589 | {isRemoteClient() ? "点击侧栏“项目”标题旁的加号,可浏览并选择云端文件夹。" : "点击侧栏“项目”标题旁的加号,可选择其他本地文件夹。"} |
| 590 | </p> |
| 591 | <div className="project-explanation"> |
| 592 | <FolderOpen size={22} /> |
| 593 | <div> |
| 594 | <strong>所有项目共用一个 Cage 环境</strong> |
| 595 | <p> |
| 596 | 明确打开的项目文件夹会共享到同一个环境。主机的 Claude |
| 597 | 登录、SSH 密钥和个人配置不会自动导入。浏览器下载统一保存到 |
| 598 | Cage 默认工作区的 Downloads 文件夹。 |
| 599 | </p> |
| 600 | </div> |
| 601 | </div> |
| 602 | <p className="footnote"> |
| 603 | 切换项目只改变新终端和文件编辑器的起始位置;已有终端、网页和登录态会保留。 |
| 604 | </p> |
| 605 | {!status.storage_recovery?.required && <EnvironmentVersions status={status} onConfirm={onConfirm} />} |
| 606 | {status.guest_system === "macos" && <section aria-label="客机系统权限"> |
| 607 | <h4>客机系统权限</h4> |
| 608 | <p className="field-help">在受限的客机系统设置窗口中完成授权,Cage 会自动检查并重新连接项目。</p> |
| 609 | <div className="project-recovery-actions"> |
| 610 | <MacOSLogin maintenance="projects" label="文件共享权限" disabled={!status.ready || busy} /> |
| 611 | <MacOSLogin maintenance="screen" label="屏幕录制权限" disabled={!status.ready || busy} /> |
| 612 | <MacOSLogin maintenance="input" label="辅助功能权限" disabled={!status.ready || busy} /> |
| 613 | </div> |
| 614 | </section>} |
| 615 | {!status.storage_recovery?.required && <ResourceSettings status={status} onConfirm={onConfirm} onDirtyChange={setResourceDirty} />} |
| 616 | <DiagnosticSettings /> |
| 617 | {status.can_restore && ( |
| 618 | <button |
| 619 | className="text-button" |
| 620 | disabled={busy} |
| 621 | onClick={async () => { |
| 622 | if ( |
| 623 | await onConfirm({ |
| 624 | title: "恢复上一份配置?", |
| 625 | body: "会停止当前环境并恢复上次应用前的设置。已经结束的终端进程无法恢复。", |
| 626 | confirm: "恢复并重启", |
| 627 | }) |
| 628 | ) { |
| 629 | try { |
| 630 | const result = await api("/restore", {}); |
| 631 | setJobId(result.id); |
| 632 | } catch (e) { |
| 633 | setError(e.message); |
| 634 | } |
| 635 | } |
| 636 | }} |
| 637 | > |
| 638 | <RotateCcw size={14} /> |
| 639 | 恢复上一份配置 |
| 640 | </button> |
| 641 | )} |
| 642 | </> |
| 643 | )} |
| 644 | </fieldset> |
| 645 | {error && ( |
| 646 | <div role="alert" className="error-message"> |
| 647 | <SafetyMessage message={error} /> |
| 648 | {probeFailed && (draft.auto_timezone || draft.auto_language) && ( |
| 649 | <button |
| 650 | className="text-button" |
| 651 | disabled={busy} |
| 652 | onClick={() => { |
| 653 | setDraft((previous) => ({ |
| 654 | ...previous, |
| 655 | auto_timezone: false, |
| 656 | auto_language: false, |
| 657 | })); |
| 658 | setProbeFailed(false); |
| 659 | setError(""); |
| 660 | setSection("region"); |
| 661 | }} |
| 662 | > |
| 663 | 手动设置时区和语言 |
| 664 | </button> |
| 665 | )} |
| 666 | </div> |
| 667 | )} |
| 668 | </div> |
| 669 | {(!["appearance", "browser", "account", "claude-accounts", "vault", "mobile", "archived-sessions", "project"].includes(section) || changed) && ( |
| 670 | <footer className="settings-footer"> |
| 671 | {" "} |
| 672 | <> |
| 673 | <span className="save-note"> |
| 674 | {status.job?.running |
| 675 | ? status.job.message |
| 676 | : proxyDirty |
| 677 | ? "代理修改待应用,请点击「应用代理」" |
| 678 | : changed |
| 679 | ? environmentChanged && status.vm_running |
| 680 | ? "网络和系统设置需要重启" |
| 681 | : "有尚未保存的修改" |
| 682 | : "没有未保存的修改"} |
| 683 | </span> |
| 684 | <button onClick={close}>返回工作台</button> |
| 685 | <button |
| 686 | className="primary" |
| 687 | disabled={!changed || busy} |
| 688 | onClick={save} |
| 689 | > |
| 690 | {busy ? ( |
| 691 | <LoaderCircle size={15} className="spin" /> |
| 692 | ) : ( |
| 693 | <Check size={15} /> |
| 694 | )}{" "} |
| 695 | {environmentChanged && status.vm_running |
| 696 | ? "保存并重启" |
| 697 | : "保存设置"} |
| 698 | </button> |
| 699 | </> |
| 700 | </footer> |
| 701 | )} |
| 702 | </div> |
| 703 | </section> |
| 704 | ); |
| 705 | } |