File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 11import fs from 'fs'
2- import { _CfgPath } from '../data/system/pluginConstants.js'
2+ import { _CfgPath , _DataPath } from '../data/system/pluginConstants.js'
33import kuroLogger from './logger.js'
44
55class ConfigReader {
@@ -11,6 +11,10 @@ class ConfigReader {
1111
1212 readConfig ( ) {
1313 try {
14+ if ( ! fs . existsSync ( this . filePath ) ) {
15+ const defaultConfigPath = _DataPath + '/system/default_config.json'
16+ fs . writeFileSync ( this . filePath , fs . readFileSync ( defaultConfigPath ) , 'utf8' )
17+ }
1418 const data = fs . readFileSync ( this . filePath , 'utf8' )
1519 const configObject = JSON . parse ( data )
1620 return configObject
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import fs from 'fs'
33import path from 'path'
44import { dataPath } from '../data/system/pluginConstants.js'
55import config from './config.js'
6+ import { sleepAsync } from '../model/utils.js'
67
78class Logger {
89 constructor (
@@ -104,7 +105,12 @@ class Logger {
104105}
105106
106107// 初始化全局日志记录器实例
107- const kuroLogger = new Logger ( config . getConfig ( ) . logger . logLevel || 'info' )
108+ const kuroLogger = new Logger ( config . getConfig ( ) ? .logger ? .logLevel || 'info' )
108109logger . info ( chalk . gray ( `[库洛插件][LOGGER] Logger initialized!` ) )
109110
111+ while ( typeof kuroLogger === 'undefined' || ! ( kuroLogger instanceof Logger ) ) {
112+ // 类尚未初始化,可以加入适当的延时以避免阻塞主线程
113+ // 例如:使用 setTimeout 或其他方式
114+ sleepAsync ( 100 )
115+ }
110116export default kuroLogger
You can’t perform that action at this time.
0 commit comments