feat: 优化WebSocket客户端 兼容1.7.10

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2021-11-04 09:07:48 +08:00
parent 476d98b9c7
commit 4ee300a22b
3 changed files with 63 additions and 24 deletions

View File

@ -92,16 +92,8 @@ export class PluginConfigManager {
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format })
} else {
configValue = configLoader.load(base.read(metadata.file)) || {}
if (defaultValue) {
let needSave = false
for (const key of Object.keys(defaultValue)) {
// 当配置文件不存在当前属性时才进行赋值
if (!Object.prototype.hasOwnProperty.call(configValue, key)) {
configValue[key] = defaultValue[key]
needSave = true
}
}
needSave && base.save(metadata.file, configLoader.dump(configValue))
if (defaultValue && this.setDefaultValue(configValue, defaultValue)) {
base.save(metadata.file, configLoader.dump(configValue))
}
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4).substr(0, 500)}`)
}
@ -112,6 +104,21 @@ export class PluginConfigManager {
}
}
private setDefaultValue(configValue, defaultValue) {
let needSave = false
for (const key of Object.keys(defaultValue)) {
// 当配置文件不存在当前属性时才进行赋值
if (!Object.prototype.hasOwnProperty.call(configValue, key)) {
configValue[key] = defaultValue[key]
needSave = true
} else if (Object.prototype.toString.call(configValue[key]) == "[object Object]") {
// 对象需要递归检测
needSave ||= this.setDefaultValue(configValue[key], defaultValue[key])
}
}
return needSave
}
private saveConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
try {
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)