Fix SCUM file workbench interactions

This commit is contained in:
npc0-hue
2026-08-04 12:05:27 +08:00
parent 8a25f52d68
commit 86a50ec8fa
6 changed files with 158 additions and 49 deletions
+20 -1
View File
@@ -67,11 +67,24 @@ export function PluginPageHostPage({ params, onNavigate, initialPlugin, embedded
readyPluginRef.current = readyPlugin;
hostContextRef.current = hostContext;
const workspaceActions = useMemo<PluginPageWorkspaceActions | undefined>(() => {
if (!pluginId || !serverId) return undefined;
if (!pluginId) return undefined;
return {
refreshWorkspace: async () => {
const response = await platformApiClient.listGamePlugins();
const plugin = response.items.find((candidate) => candidate.id === pluginId);
if (!plugin) {
throw new Error("未找到已注册的插件声明。");
}
readyPluginRef.current = plugin;
setState({ status: "ready", plugin });
return plugin.fileWorkspace;
},
requestFile: async (fileKey) => {
const plugin = readyPluginRef.current;
const context = hostContextRef.current;
if (!serverId) {
return { status: "denied", message: "插件页面没有绑定服务器,无法读取文件。" };
}
if (!plugin || !context) {
return { status: "denied", message: "插件页面上下文尚未就绪。" };
}
@@ -92,6 +105,9 @@ export function PluginPageHostPage({ params, onNavigate, initialPlugin, embedded
},
getFileSnapshot: async (fileKey) => {
const plugin = readyPluginRef.current;
if (!serverId) {
return { serverInstanceId: "", pluginId, key: fileKey, state: "unavailable", reason: "插件页面没有绑定服务器,无法读取文件快照。" };
}
if (!plugin) {
return { serverInstanceId: serverId, pluginId, key: fileKey, state: "unavailable", reason: "插件页面上下文尚未就绪。" };
}
@@ -113,6 +129,9 @@ export function PluginPageHostPage({ params, onNavigate, initialPlugin, embedded
writeFile: async (fileKey, content, options) => {
const plugin = readyPluginRef.current;
const context = hostContextRef.current;
if (!serverId) {
return { status: "denied", message: "插件页面没有绑定服务器,无法写入文件。" };
}
if (!plugin || !context) {
return { status: "denied", message: "插件页面上下文尚未就绪。" };
}