mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: config hot update
This commit is contained in:
parent
c837e970df
commit
39fda24799
@ -1,6 +1,5 @@
|
|||||||
export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
|
export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
|
||||||
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
||||||
export const CHANNEL_SET_CONFIG_CONFIRMED = 'llonebot_set_config_confirmed'
|
|
||||||
export const CHANNEL_LOG = 'llonebot_log'
|
export const CHANNEL_LOG = 'llonebot_log'
|
||||||
export const CHANNEL_ERROR = 'llonebot_error'
|
export const CHANNEL_ERROR = 'llonebot_error'
|
||||||
export const CHANNEL_UPDATE = 'llonebot_update'
|
export const CHANNEL_UPDATE = 'llonebot_update'
|
||||||
|
@ -50,7 +50,7 @@ export class ConfigUtil {
|
|||||||
token: '',
|
token: '',
|
||||||
enableLocalFile2Url: false,
|
enableLocalFile2Url: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
log: false,
|
log: true,
|
||||||
autoDeleteFile: false,
|
autoDeleteFile: false,
|
||||||
autoDeleteFileSecond: 60,
|
autoDeleteFileSecond: 60,
|
||||||
musicSignUrl: '',
|
musicSignUrl: '',
|
||||||
|
@ -15,8 +15,7 @@ import {
|
|||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE
|
||||||
CHANNEL_SET_CONFIG_CONFIRMED
|
|
||||||
} from '../common/channels'
|
} from '../common/channels'
|
||||||
import { startHook } from '../ntqqapi/hook'
|
import { startHook } from '../ntqqapi/hook'
|
||||||
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
||||||
@ -35,7 +34,6 @@ import {
|
|||||||
NTQQWebApi,
|
NTQQWebApi,
|
||||||
NTQQWindowApi
|
NTQQWindowApi
|
||||||
} from '../ntqqapi/api'
|
} from '../ntqqapi/api'
|
||||||
import { mkdir } from 'node:fs/promises'
|
|
||||||
import { existsSync, mkdirSync } from 'node:fs'
|
import { existsSync, mkdirSync } from 'node:fs'
|
||||||
|
|
||||||
declare module 'cordis' {
|
declare module 'cordis' {
|
||||||
@ -56,6 +54,29 @@ function onLoad() {
|
|||||||
mkdirSync(LOG_DIR)
|
mkdirSync(LOG_DIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!existsSync(TEMP_DIR)) {
|
||||||
|
mkdirSync(TEMP_DIR)
|
||||||
|
}
|
||||||
|
|
||||||
|
const dbDir = path.join(DATA_DIR, 'database')
|
||||||
|
if (!existsSync(dbDir)) {
|
||||||
|
mkdirSync(dbDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ctx = new Context()
|
||||||
|
|
||||||
|
ctx.plugin(NTQQFileApi)
|
||||||
|
ctx.plugin(NTQQFileCacheApi)
|
||||||
|
ctx.plugin(NTQQFriendApi)
|
||||||
|
ctx.plugin(NTQQGroupApi)
|
||||||
|
ctx.plugin(NTQQMsgApi)
|
||||||
|
ctx.plugin(NTQQUserApi)
|
||||||
|
ctx.plugin(NTQQWebApi)
|
||||||
|
ctx.plugin(NTQQWindowApi)
|
||||||
|
ctx.plugin(Database)
|
||||||
|
|
||||||
|
let started = false
|
||||||
|
|
||||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async () => {
|
ipcMain.handle(CHANNEL_CHECK_VERSION, async () => {
|
||||||
return checkNewVersion()
|
return checkNewVersion()
|
||||||
})
|
})
|
||||||
@ -114,7 +135,9 @@ function onLoad() {
|
|||||||
if (!ask) {
|
if (!ask) {
|
||||||
getConfigUtil().setConfig(config)
|
getConfigUtil().setConfig(config)
|
||||||
log('配置已更新', config)
|
log('配置已更新', config)
|
||||||
checkFfmpeg(config.ffmpeg).then()
|
if (started) {
|
||||||
|
ctx.parallel('llob/config-updated', config)
|
||||||
|
}
|
||||||
resolve(true)
|
resolve(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -131,7 +154,9 @@ function onLoad() {
|
|||||||
if (result.response === 0) {
|
if (result.response === 0) {
|
||||||
getConfigUtil().setConfig(config)
|
getConfigUtil().setConfig(config)
|
||||||
log('配置已更新', config)
|
log('配置已更新', config)
|
||||||
checkFfmpeg(config.ffmpeg).then()
|
if (started) {
|
||||||
|
ctx.parallel('llob/config-updated', config)
|
||||||
|
}
|
||||||
resolve(true)
|
resolve(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -146,37 +171,28 @@ function onLoad() {
|
|||||||
log(arg)
|
log(arg)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function start() {
|
const intervalId = setInterval(() => {
|
||||||
|
const self = Object.assign(selfInfo, {
|
||||||
|
uin: globalThis.authData?.uin,
|
||||||
|
uid: globalThis.authData?.uid,
|
||||||
|
online: true
|
||||||
|
})
|
||||||
|
if (self.uin) {
|
||||||
|
clearInterval(intervalId)
|
||||||
log('process pid', process.pid)
|
log('process pid', process.pid)
|
||||||
|
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
if (!existsSync(TEMP_DIR)) {
|
|
||||||
await mkdir(TEMP_DIR)
|
|
||||||
}
|
|
||||||
const dbDir = path.join(DATA_DIR, 'database')
|
|
||||||
if (!existsSync(dbDir)) {
|
|
||||||
await mkdir(dbDir)
|
|
||||||
}
|
|
||||||
const ctx = new Context()
|
|
||||||
ctx.plugin(Log, {
|
ctx.plugin(Log, {
|
||||||
enable: config.log!,
|
enable: config.log!,
|
||||||
filename: logFileName
|
filename: logFileName
|
||||||
})
|
})
|
||||||
ctx.plugin(NTQQFileApi)
|
|
||||||
ctx.plugin(NTQQFileCacheApi)
|
|
||||||
ctx.plugin(NTQQFriendApi)
|
|
||||||
ctx.plugin(NTQQGroupApi)
|
|
||||||
ctx.plugin(NTQQMsgApi)
|
|
||||||
ctx.plugin(NTQQUserApi)
|
|
||||||
ctx.plugin(NTQQWebApi)
|
|
||||||
ctx.plugin(NTQQWindowApi)
|
|
||||||
ctx.plugin(Core, config)
|
|
||||||
ctx.plugin(Database)
|
|
||||||
ctx.plugin(SQLiteDriver, {
|
ctx.plugin(SQLiteDriver, {
|
||||||
path: path.join(dbDir, `${selfInfo.uin}.db`)
|
path: path.join(dbDir, `${selfInfo.uin}.db`)
|
||||||
})
|
})
|
||||||
ctx.plugin(Store, {
|
ctx.plugin(Store, {
|
||||||
msgCacheExpire: config.msgCacheExpire! * 1000
|
msgCacheExpire: config.msgCacheExpire! * 1000
|
||||||
})
|
})
|
||||||
|
ctx.plugin(Core, config)
|
||||||
if (config.ob11.enable) {
|
if (config.ob11.enable) {
|
||||||
ctx.plugin(OneBot11Adapter, {
|
ctx.plugin(OneBot11Adapter, {
|
||||||
...config.ob11,
|
...config.ob11,
|
||||||
@ -194,22 +210,10 @@ function onLoad() {
|
|||||||
ffmpeg: config.ffmpeg,
|
ffmpeg: config.ffmpeg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ctx.start()
|
|
||||||
llonebotError.otherError = ''
|
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG_CONFIRMED, (event, config: LLOBConfig) => {
|
|
||||||
ctx.parallel('llob/config-updated', config)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const intervalId = setInterval(() => {
|
ctx.start()
|
||||||
const self = Object.assign(selfInfo, {
|
started = true
|
||||||
uin: globalThis.authData?.uin,
|
llonebotError.otherError = ''
|
||||||
uid: globalThis.authData?.uid,
|
|
||||||
online: true
|
|
||||||
})
|
|
||||||
if (self.uin) {
|
|
||||||
clearInterval(intervalId)
|
|
||||||
start()
|
|
||||||
}
|
}
|
||||||
}, 600)
|
}, 600)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE,
|
||||||
CHANNEL_SET_CONFIG_CONFIRMED,
|
|
||||||
} from './common/channels'
|
} from './common/channels'
|
||||||
|
|
||||||
const { contextBridge } = require('electron')
|
const { contextBridge } = require('electron')
|
||||||
@ -24,8 +23,7 @@ const llonebot = {
|
|||||||
return ipcRenderer.invoke(CHANNEL_UPDATE)
|
return ipcRenderer.invoke(CHANNEL_UPDATE)
|
||||||
},
|
},
|
||||||
setConfig: async (ask: boolean, config: Config) => {
|
setConfig: async (ask: boolean, config: Config) => {
|
||||||
const isSuccess = await ipcRenderer.invoke(CHANNEL_SET_CONFIG, ask, config)
|
return ipcRenderer.invoke(CHANNEL_SET_CONFIG, ask, config)
|
||||||
if (isSuccess) ipcRenderer.send(CHANNEL_SET_CONFIG_CONFIRMED, config)
|
|
||||||
},
|
},
|
||||||
getConfig: async (): Promise<Config> => {
|
getConfig: async (): Promise<Config> => {
|
||||||
return ipcRenderer.invoke(CHANNEL_GET_CONFIG)
|
return ipcRenderer.invoke(CHANNEL_GET_CONFIG)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user