Merge pull request #63 from devchat-ai/fix-server-config

Fix server config
This commit is contained in:
boob.yang 2024-06-15 21:44:03 +08:00 committed by GitHub
commit 1f86b7d72e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 14 deletions

View File

@ -59,11 +59,15 @@ class MessageUtil {
throw new Error('Missing required field: command');
}
const handlers = this.handlers[message.command];
if (handlers) {
handlers.forEach((handler: (arg0: { command: string | number } & Record<string, any>) => any) =>
handler(message)
);
if (process.env.platform === "idea") {
IdeaBridge.handleMessage(message)
} else {
const handlers = this.handlers[message.command];
if (handlers) {
handlers.forEach((handler: (arg0: { command: string | number } & Record<string, any>) => any) =>
handler(message)
);
}
}
}

View File

@ -305,7 +305,7 @@ const JStoIdea = {
readServerConfigBase: () => {
// 获取完整的用户设置
const params = {
action: "getServerSetting/request",
action: "getServerSettings/request",
metadata: {
callback: "IdeaToJSMessage",
},
@ -323,20 +323,18 @@ const JStoIdea = {
payload: data,
};
console.log("ready to call java: ", JSON.stringify(params));
window.JSJavaBridge.callJava(JSON.stringify(params));
},
writeServerConfigBase: (data) => {
const params = {
action: "updateServerSetting/request",
action: "updateServerSettings/request",
metadata: {
callback: "IdeaToJSMessage",
},
payload: data,
};
console.log("ready to call java: ", JSON.stringify(params));
window.JSJavaBridge.callJava(JSON.stringify(params));
},
};
@ -349,7 +347,6 @@ class IdeaBridge {
this.handle = {};
// 注册全局的回调函数,用于接收来自 IDEA 的消息
window.IdeaToJSMessage = (res: any) => {
console.info("IdeaToJSMessage get res: ", res);
switch (res.action) {
case "updateSetting/response":
this.resviceUpdateSetting(res);
@ -384,6 +381,9 @@ class IdeaBridge {
case "getSetting/response":
this.resviceSettings(res);
break;
case "getServerSettings/response":
this.resviceServerSettings(res);
break;
case "listTopics/response":
this.resviceTopicList(res);
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) {
// 根据 command 分发到不同的方法·
switch (message.command) {

View File

@ -111,10 +111,6 @@ const Config = observer(() => {
const [current, setCurrent] = useState("");
useEffect(() => {
MessageUtil.registerHandler("updateSetting", (data) => {
// 保存后的回调
MessageUtil.handleMessage({ command: "reloadConfig" });
});
if (router.currentRoute !== "config") {return;}
const modelArray = config.modelsTemplate.map((item) => ({
value: item.name,