feat: optimize config save logic

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-10-31 11:40:38 +08:00
parent 3f101ca250
commit 0776d0ddeb
4 changed files with 5 additions and 7 deletions

View File

@ -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))
}
}

View File

@ -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)

View File

@ -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)

View File

@ -72,9 +72,9 @@ export namespace interfaces {
*/
format?: string
/**
* ()
* false
*/
readonly?: boolean
autosave?: boolean
/**
*
*/