Merge pull request #63 from devchat-ai/fix-server-config
Fix server config
This commit is contained in:
commit
1f86b7d72e
@ -59,11 +59,15 @@ class MessageUtil {
|
|||||||
throw new Error('Missing required field: command');
|
throw new Error('Missing required field: command');
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlers = this.handlers[message.command];
|
if (process.env.platform === "idea") {
|
||||||
if (handlers) {
|
IdeaBridge.handleMessage(message)
|
||||||
handlers.forEach((handler: (arg0: { command: string | number } & Record<string, any>) => any) =>
|
} else {
|
||||||
handler(message)
|
const handlers = this.handlers[message.command];
|
||||||
);
|
if (handlers) {
|
||||||
|
handlers.forEach((handler: (arg0: { command: string | number } & Record<string, any>) => any) =>
|
||||||
|
handler(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ const JStoIdea = {
|
|||||||
readServerConfigBase: () => {
|
readServerConfigBase: () => {
|
||||||
// 获取完整的用户设置
|
// 获取完整的用户设置
|
||||||
const params = {
|
const params = {
|
||||||
action: "getServerSetting/request",
|
action: "getServerSettings/request",
|
||||||
metadata: {
|
metadata: {
|
||||||
callback: "IdeaToJSMessage",
|
callback: "IdeaToJSMessage",
|
||||||
},
|
},
|
||||||
@ -323,20 +323,18 @@ const JStoIdea = {
|
|||||||
payload: data,
|
payload: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("ready to call java: ", JSON.stringify(params));
|
|
||||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||||
},
|
},
|
||||||
|
|
||||||
writeServerConfigBase: (data) => {
|
writeServerConfigBase: (data) => {
|
||||||
const params = {
|
const params = {
|
||||||
action: "updateServerSetting/request",
|
action: "updateServerSettings/request",
|
||||||
metadata: {
|
metadata: {
|
||||||
callback: "IdeaToJSMessage",
|
callback: "IdeaToJSMessage",
|
||||||
},
|
},
|
||||||
payload: data,
|
payload: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("ready to call java: ", JSON.stringify(params));
|
|
||||||
window.JSJavaBridge.callJava(JSON.stringify(params));
|
window.JSJavaBridge.callJava(JSON.stringify(params));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -349,7 +347,6 @@ class IdeaBridge {
|
|||||||
this.handle = {};
|
this.handle = {};
|
||||||
// 注册全局的回调函数,用于接收来自 IDEA 的消息
|
// 注册全局的回调函数,用于接收来自 IDEA 的消息
|
||||||
window.IdeaToJSMessage = (res: any) => {
|
window.IdeaToJSMessage = (res: any) => {
|
||||||
console.info("IdeaToJSMessage get res: ", res);
|
|
||||||
switch (res.action) {
|
switch (res.action) {
|
||||||
case "updateSetting/response":
|
case "updateSetting/response":
|
||||||
this.resviceUpdateSetting(res);
|
this.resviceUpdateSetting(res);
|
||||||
@ -384,6 +381,9 @@ class IdeaBridge {
|
|||||||
case "getSetting/response":
|
case "getSetting/response":
|
||||||
this.resviceSettings(res);
|
this.resviceSettings(res);
|
||||||
break;
|
break;
|
||||||
|
case "getServerSettings/response":
|
||||||
|
this.resviceServerSettings(res);
|
||||||
|
break;
|
||||||
case "listTopics/response":
|
case "listTopics/response":
|
||||||
this.resviceTopicList(res);
|
this.resviceTopicList(res);
|
||||||
break;
|
break;
|
||||||
@ -561,6 +561,19 @@ class IdeaBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleMessage(message: { command: string | number } & Record<string, any>) {
|
||||||
|
if (!('command' in message)) {
|
||||||
|
throw new Error('Missing required field: command');
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageType = message.command
|
||||||
|
if (this.handle[messageType]) {
|
||||||
|
this.handle[messageType].forEach((handler) => {
|
||||||
|
handler(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(message: any) {
|
sendMessage(message: any) {
|
||||||
// 根据 command 分发到不同的方法·
|
// 根据 command 分发到不同的方法·
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
|
@ -111,10 +111,6 @@ const Config = observer(() => {
|
|||||||
const [current, setCurrent] = useState("");
|
const [current, setCurrent] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
MessageUtil.registerHandler("updateSetting", (data) => {
|
|
||||||
// 保存后的回调
|
|
||||||
MessageUtil.handleMessage({ command: "reloadConfig" });
|
|
||||||
});
|
|
||||||
if (router.currentRoute !== "config") {return;}
|
if (router.currentRoute !== "config") {return;}
|
||||||
const modelArray = config.modelsTemplate.map((item) => ({
|
const modelArray = config.modelsTemplate.map((item) => ({
|
||||||
value: item.name,
|
value: item.name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user