Fix SCUM file workbench interactions
This commit is contained in:
@@ -99,6 +99,8 @@ describe("PluginPageHostPage", () => {
|
||||
it("keeps file workspace callbacks stable across parent operational refreshes", () => {
|
||||
expect(hostSource).toContain("readyPluginRef.current = readyPlugin");
|
||||
expect(hostSource).toContain("hostContextRef.current = hostContext");
|
||||
expect(hostSource).toContain("refreshWorkspace: async ()");
|
||||
expect(hostSource).toContain("platformApiClient.listGamePlugins()");
|
||||
expect(hostSource).toContain("}, [pluginId, serverId]);");
|
||||
expect(hostSource).not.toContain("}, [hostContext, readyPlugin, serverId]);");
|
||||
});
|
||||
|
||||
@@ -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: "插件页面上下文尚未就绪。" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user