feat: optimize config save logic
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
3f101ca250
commit
0776d0ddeb
@ -35,8 +35,6 @@ export class PluginCommandManager {
|
||||
|
||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
||||
cmds.forEach(cmd => {
|
||||
this.CommandManager.off(pluginInstance, cmd.name)
|
||||
})
|
||||
cmds.forEach(cmd => this.CommandManager.off(pluginInstance, cmd.name))
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ export class PluginConfigManager {
|
||||
saveConfig(plugin: plugin.Plugin) {
|
||||
let configs = getPluginConfigMetadata(plugin)
|
||||
for (let [_, config] of configs) {
|
||||
this.saveConfig0(plugin, config)
|
||||
config.autosave && this.saveConfig0(plugin, config)
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +102,6 @@ export class PluginConfigManager {
|
||||
|
||||
private saveConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
||||
try {
|
||||
if (metadata.readonly) { console.debug(`[${plugin.description.name}] Skip Save Config ${metadata.variable} Because it's readonly!`) }
|
||||
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
||||
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
|
||||
base.save(metadata.file, result)
|
||||
|
@ -77,6 +77,7 @@ export function config(metadata: interfaces.ConfigMetadata = {}) {
|
||||
metadata.variable = key
|
||||
metadata.version = metadata.version ?? 1
|
||||
metadata.format = metadata.format ?? 'yml'
|
||||
metadata.autosave = metadata.autosave ?? false
|
||||
metadata.filename = metadata.filename ?? metadata.name + '.' + metadata.format
|
||||
let previousMetadata = getPluginConfigMetadata(target)
|
||||
previousMetadata.set(metadata.name, metadata)
|
||||
|
@ -72,9 +72,9 @@ export namespace interfaces {
|
||||
*/
|
||||
format?: string
|
||||
/**
|
||||
* 是否为只读(关闭时将不会自动保存)
|
||||
* 自动保存 默认为 false
|
||||
*/
|
||||
readonly?: boolean
|
||||
autosave?: boolean
|
||||
/**
|
||||
* 配置文件名称
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user