fix: reverse ws restart

This commit is contained in:
linyuchen 2024-03-30 19:11:20 +08:00
parent dd03e384ce
commit bc49bf520c
6 changed files with 41 additions and 10 deletions

View File

@ -77,7 +77,7 @@ export class ConfigUtil {
setConfig(config: Config) {
this.config = config;
fsPromise.writeFile(this.configPath, JSON.stringify(config, null, 2), "utf-8").then()
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
}
private checkOldConfig(currentConfig: Config | OB11Config,

View File

@ -108,6 +108,7 @@ function onLoad() {
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
error = error.replace("\n\n", "\n")
error = error.trim();
log("查询llonebot错误信息", error);
return error;
})
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
@ -116,7 +117,9 @@ function onLoad() {
})
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask: boolean, config: Config) => {
if (!ask) {
setConfig(config).then();
setConfig(config).then().catch(e => {
log("保存设置失败", e.stack)
});
return
}
dialog.showMessageBox(mainWindow, {
@ -128,7 +131,9 @@ function onLoad() {
detail: 'LLOneBot配置已更改是否保存'
}).then(result => {
if (result.response === 0) {
setConfig(config).then();
setConfig(config).then().catch(e => {
log("保存设置失败", e.stack)
});
} else {
}
}).catch(err => {

View File

@ -4,10 +4,10 @@ import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
import {llonebotError} from "../common/data";
import {getConfigUtil} from "../common/config";
import {checkFfmpeg} from "../common/utils";
import {checkFfmpeg, log} from "../common/utils";
export async function setConfig(config: Config) {
let oldConfig = getConfigUtil().getConfig();
let oldConfig = {...(getConfigUtil().getConfig())};
getConfigUtil().setConfig(config)
if (config.ob11.httpPort != oldConfig.ob11.httpPort && config.ob11.enableHttp) {
ob11HTTPServer.restart(config.ob11.httpPort);
@ -42,15 +42,19 @@ export async function setConfig(config: Config) {
if (config.ob11.enableWsReverse) {
// 判断反向ws地址有变化
if (config.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
log("反向ws地址有变化, 重启反向ws服务")
ob11ReverseWebsockets.restart();
} else {
for (const newHost of config.ob11.wsHosts) {
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
log("反向ws地址有变化, 重启反向ws服务")
ob11ReverseWebsockets.restart();
break;
}
}
}
}
log("old config", oldConfig)
log("配置已更新", config)
checkFfmpeg(config.ffmpeg).then()
}

View File

@ -63,6 +63,7 @@ export function unregisterWsEventSender(ws: WebSocketClass) {
export function postWsEvent(event: PostEventType) {
for (const ws of eventWSList) {
log(ws)
new Promise(() => {
wsReply(ws, event);
}).then()

View File

@ -128,8 +128,13 @@ class OB11ReverseWebsockets {
stop() {
for (let rws of rwsList) {
rws.stop();
try {
rws.stop();
}catch (e) {
log("反向ws关闭:", e.stack)
}
}
rwsList.length = 0;
}
restart() {

View File

@ -6,8 +6,21 @@ import StyleRaw from './style.css?raw';
// 打开设置界面时触发
function aprilFoolsEgg(){
let today = new Date()
if(today.getMonth() === 1 && today.getDate() === 1){
console.log("超时空猫猫!!!")
document.querySelectorAll(".nav-item.liteloader").forEach((node) => {
if (node.textContent.startsWith("LLOneBot")) {
node.querySelector(".name").innerHTML = "ChronoCat";
}
})
}
}
async function onSettingWindowCreated(view: Element) {
window.llonebot.log("setting window created");
aprilFoolsEgg()
const isEmpty = (value: any) => value === undefined || value === null || value === '';
let config = await window.llonebot.getConfig();
let ob11Config = {...config.ob11};
@ -182,13 +195,16 @@ async function onSettingWindowCreated(view: Element) {
const showError = async () => {
await (new Promise((res) => setTimeout(() => res(true), 1000)));
const errDom = doc.querySelector('#llonebot-error');
const errDom = document.querySelector('#llonebot-error') || doc.querySelector('#llonebot-error');
const errCodeDom = errDom.querySelector('code');
const errMsg = await window.llonebot.getError();
if (!errMsg) return;
errDom.classList.add('show');
if (!errMsg){
errDom.classList.remove('show');
}
else {
errDom.classList.add('show');
}
errCodeDom.innerHTML = errMsg;
}
showError().then();