跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

initialization-storage.jsx

34 行 · 2.1 KB历史下载
1import React, { useEffect, useState } from "react";
2import { FolderOpen } from "lucide-react";
3import { api, native, nativeAvailable } from "./api";
4
5export function InitializationStorage({ value, onChange, disabled }) {
6 const [error, setError] = useState("");
7 const [attempt, retry] = useState(0);
8 useEffect(() => {
9 if (value) return;
10 let live = true;
11 api("/environment/storage").then(location => {
12 if (live) onChange({ location, directory: location.suggested_directory || location.directory });
13 }).catch(error => { if (live) setError(error.message); });
14 return () => { live = false; };
15 }, [Boolean(value), onChange, attempt]);
16 const locked = disabled || !value || value.location.has_environment;
17 async function choose() {
18 try {
19 const directory = await native("chooseFolder", { purpose: "environmentStorage" });
20 if (directory) { onChange({ ...value, directory }); setError(""); }
21 } catch (error) { setError(error.message); }
22 }
23 return <section className="initialization-storage" aria-label="环境存储目录">
24 <label htmlFor="initialization-directory">存储目录</label>
25 <p>系统镜像、下载缓存和虚拟磁盘保存在这里。已填入默认目录,也可以选择其他本地磁盘上的专用空文件夹。</p>
26 <p>这是 Cage 的环境数据目录。更新、重装或卸载应用会保留这里的数据;请勿手动删除。</p>
27 <div className="initialization-directory-control">
28 <input id="initialization-directory" value={value?.directory || ""} disabled={locked} spellCheck={false} placeholder={value ? "请输入存储目录的完整路径" : "正在读取默认目录…"} onChange={event => onChange({ ...value, directory: event.target.value })} />
29 {nativeAvailable() && <button type="button" disabled={locked} onClick={choose}><FolderOpen size={16} />选择文件夹</button>}
30 </div>
31 {value?.location.has_environment && <p>已有虚拟磁盘,继续使用原存储目录。完成初始化后可在设置中迁移。</p>}
32 {error && <p role="alert">{error}<button onClick={() => { setError(""); retry(value => value + 1); }}>重新读取</button></p>}
33 </section>;
34}