From 50ab62f1032aa90fdb30ee34cc0acd1ad7d1109f Mon Sep 17 00:00:00 2001 From: idranme Date: Wed, 7 Aug 2024 21:39:26 +0800 Subject: [PATCH] opt: config --- src/renderer/index.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 2cdc9a6..9cf9b97 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -1,4 +1,3 @@ -/// import { CheckVersion } from '../common/types' import { SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect } from './components' // @ts-ignore @@ -26,22 +25,24 @@ function initSideBar() { }) } +function isEmpty(value: unknown) { + return value === undefined || value === null || value === '' +} + async function onSettingWindowCreated(view: Element) { window.llonebot.log('setting window created') initSideBar() - const isEmpty = (value: any) => value === undefined || value === null || value === '' let config = await window.llonebot.getConfig() let ob11Config = { ...config.ob11 } + const setConfig = (key: string, value: any) => { const configKey = key.split('.') - if (key.indexOf('ob11') === 0) { if (configKey.length === 2) ob11Config[configKey[1]] = value else ob11Config[key] = value } else { if (configKey.length === 2) config[configKey[0]][configKey[1]] = value else config[key] = value - if (!['heartInterval', 'token', 'ffmpeg'].includes(key)) { window.llonebot.setConfig(false, config) } @@ -65,7 +66,7 @@ async function onSettingWindowCreated(view: Element) { ]), SettingList([ SettingItem( - '是否启用 LLOneBot, 重启QQ后生效', + '是否启用 LLOneBot, 重启 QQ 后生效', null, SettingSwitch('enableLLOB', config.enableLLOB, { 'control-display-id': 'config-enableLLOB' }), )] @@ -160,21 +161,21 @@ async function onSettingWindowCreated(view: Element) { SettingSelect( [ { text: '消息段', value: 'array' }, - { text: 'CQ码', value: 'string' }, + { text: 'CQ 码', value: 'string' }, ], 'ob11.messagePostFormat', config.ob11.messagePostFormat, ), ), SettingItem( - 'ffmpeg 路径,发送语音、视频需要,同时保证ffprobe和ffmpeg在一起', - ` 下载地址 , 路径:${ + 'FFmpeg 路径,发送语音、视频需要', + `可点此下载, 路径: ${ !isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定' - }`, - SettingButton('选择ffmpeg', 'config-ffmpeg-select'), + }, 需保证 FFprobe 和 FFmpeg 在一起`, + SettingButton('选择 FFmpeg', 'config-ffmpeg-select'), ), SettingItem( - '音乐卡片签名地址', + '音乐卡片签名 URL 地址', null, `
`, 'config-musicSignUrl',