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');
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user