mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: reverse ws restart
This commit is contained in:
parent
dd03e384ce
commit
bc49bf520c
@ -77,7 +77,7 @@ export class ConfigUtil {
|
|||||||
|
|
||||||
setConfig(config: Config) {
|
setConfig(config: Config) {
|
||||||
this.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,
|
private checkOldConfig(currentConfig: Config | OB11Config,
|
||||||
|
@ -108,6 +108,7 @@ function onLoad() {
|
|||||||
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
|
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
|
||||||
error = error.replace("\n\n", "\n")
|
error = error.replace("\n\n", "\n")
|
||||||
error = error.trim();
|
error = error.trim();
|
||||||
|
log("查询llonebot错误信息", error);
|
||||||
return error;
|
return error;
|
||||||
})
|
})
|
||||||
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
|
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
|
||||||
@ -116,7 +117,9 @@ function onLoad() {
|
|||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask: boolean, config: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask: boolean, config: Config) => {
|
||||||
if (!ask) {
|
if (!ask) {
|
||||||
setConfig(config).then();
|
setConfig(config).then().catch(e => {
|
||||||
|
log("保存设置失败", e.stack)
|
||||||
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dialog.showMessageBox(mainWindow, {
|
dialog.showMessageBox(mainWindow, {
|
||||||
@ -128,7 +131,9 @@ function onLoad() {
|
|||||||
detail: 'LLOneBot配置已更改,是否保存?'
|
detail: 'LLOneBot配置已更改,是否保存?'
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
if (result.response === 0) {
|
if (result.response === 0) {
|
||||||
setConfig(config).then();
|
setConfig(config).then().catch(e => {
|
||||||
|
log("保存设置失败", e.stack)
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
@ -4,10 +4,10 @@ import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
|||||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
import {llonebotError} from "../common/data";
|
import {llonebotError} from "../common/data";
|
||||||
import {getConfigUtil} from "../common/config";
|
import {getConfigUtil} from "../common/config";
|
||||||
import {checkFfmpeg} from "../common/utils";
|
import {checkFfmpeg, log} from "../common/utils";
|
||||||
|
|
||||||
export async function setConfig(config: Config) {
|
export async function setConfig(config: Config) {
|
||||||
let oldConfig = getConfigUtil().getConfig();
|
let oldConfig = {...(getConfigUtil().getConfig())};
|
||||||
getConfigUtil().setConfig(config)
|
getConfigUtil().setConfig(config)
|
||||||
if (config.ob11.httpPort != oldConfig.ob11.httpPort && config.ob11.enableHttp) {
|
if (config.ob11.httpPort != oldConfig.ob11.httpPort && config.ob11.enableHttp) {
|
||||||
ob11HTTPServer.restart(config.ob11.httpPort);
|
ob11HTTPServer.restart(config.ob11.httpPort);
|
||||||
@ -42,15 +42,19 @@ export async function setConfig(config: Config) {
|
|||||||
if (config.ob11.enableWsReverse) {
|
if (config.ob11.enableWsReverse) {
|
||||||
// 判断反向ws地址有变化
|
// 判断反向ws地址有变化
|
||||||
if (config.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
if (config.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
||||||
|
log("反向ws地址有变化, 重启反向ws服务")
|
||||||
ob11ReverseWebsockets.restart();
|
ob11ReverseWebsockets.restart();
|
||||||
} else {
|
} else {
|
||||||
for (const newHost of config.ob11.wsHosts) {
|
for (const newHost of config.ob11.wsHosts) {
|
||||||
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
||||||
|
log("反向ws地址有变化, 重启反向ws服务")
|
||||||
ob11ReverseWebsockets.restart();
|
ob11ReverseWebsockets.restart();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log("old config", oldConfig)
|
||||||
|
log("配置已更新", config)
|
||||||
checkFfmpeg(config.ffmpeg).then()
|
checkFfmpeg(config.ffmpeg).then()
|
||||||
}
|
}
|
@ -63,6 +63,7 @@ export function unregisterWsEventSender(ws: WebSocketClass) {
|
|||||||
|
|
||||||
export function postWsEvent(event: PostEventType) {
|
export function postWsEvent(event: PostEventType) {
|
||||||
for (const ws of eventWSList) {
|
for (const ws of eventWSList) {
|
||||||
|
log(ws)
|
||||||
new Promise(() => {
|
new Promise(() => {
|
||||||
wsReply(ws, event);
|
wsReply(ws, event);
|
||||||
}).then()
|
}).then()
|
||||||
|
@ -128,8 +128,13 @@ class OB11ReverseWebsockets {
|
|||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
for (let rws of rwsList) {
|
for (let rws of rwsList) {
|
||||||
rws.stop();
|
try {
|
||||||
|
rws.stop();
|
||||||
|
}catch (e) {
|
||||||
|
log("反向ws关闭:", e.stack)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
rwsList.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
restart() {
|
restart() {
|
||||||
|
@ -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) {
|
async function onSettingWindowCreated(view: Element) {
|
||||||
window.llonebot.log("setting window created");
|
window.llonebot.log("setting window created");
|
||||||
|
aprilFoolsEgg()
|
||||||
const isEmpty = (value: any) => value === undefined || value === null || value === '';
|
const isEmpty = (value: any) => value === undefined || value === null || value === '';
|
||||||
let config = await window.llonebot.getConfig();
|
let config = await window.llonebot.getConfig();
|
||||||
let ob11Config = {...config.ob11};
|
let ob11Config = {...config.ob11};
|
||||||
@ -182,13 +195,16 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
const showError = async () => {
|
const showError = async () => {
|
||||||
await (new Promise((res) => setTimeout(() => res(true), 1000)));
|
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 errCodeDom = errDom.querySelector('code');
|
||||||
const errMsg = await window.llonebot.getError();
|
const errMsg = await window.llonebot.getError();
|
||||||
|
|
||||||
if (!errMsg) return;
|
if (!errMsg){
|
||||||
|
errDom.classList.remove('show');
|
||||||
errDom.classList.add('show');
|
}
|
||||||
|
else {
|
||||||
|
errDom.classList.add('show');
|
||||||
|
}
|
||||||
errCodeDom.innerHTML = errMsg;
|
errCodeDom.innerHTML = errMsg;
|
||||||
}
|
}
|
||||||
showError().then();
|
showError().then();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user