diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 29b83cfa..8ad2ad3c 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -124,18 +124,24 @@ const configApi = { defConfig = mergeApi.doMerge(defConfig, configApi.readRemoteConfig()) } - // 计算新配置与默认配置(启用远程配置时,含远程配置)的差异,并保存到 config.json5 中 + // 计算新配置与默认配置(启用远程配置时,含远程配置)的差异,并保存到 config.json 中 const diffConfig = mergeApi.doDiff(defConfig, newConfig) const configPath = _getConfigPath() fs.writeFileSync(configPath, JSON.stringify(diffConfig, null, '\t')) log.info('保存自定义配置文件成功:', configPath) - configApi.reload() - return diffConfig + + // 重载配置 + const allConfig = configApi.reload() + + return { + diffConfig, + allConfig + } }, doMerge: mergeApi.doMerge, doDiff: mergeApi.doDiff, /** - * 读取 config.json5 后,合并配置 + * 读取 config.json 后,合并配置 * @returns {*} */ reload () { diff --git a/packages/gui/src/view/components/settings.vue b/packages/gui/src/view/components/settings.vue index dd44fb6e..cfa78df8 100644 --- a/packages/gui/src/view/components/settings.vue +++ b/packages/gui/src/view/components/settings.vue @@ -190,7 +190,7 @@ export default { }, doSave () { return api.config.save(this.targetConfig).then(ret => { - this.$emit('change', ret) + this.$emit('change', ret.diffConfig) }) }, deleteDnsMapping (item, index) { diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js index e315558e..357b1c74 100644 --- a/packages/gui/src/view/mixins/plugin.js +++ b/packages/gui/src/view/mixins/plugin.js @@ -7,6 +7,7 @@ export default { }, data () { return { + key: undefined, config: undefined, status: {}, labelCol: { span: 4 }, @@ -31,10 +32,10 @@ export default { this.status = this.$status const config = await this.$api.config.reload() - this.$set(this, 'config', config) + this.setConfig(config) this.systemPlatform = await this.$api.info.getSystemPlatform() - console.log('config', this.config, this.systemPlatform) - // eslint-disable-next-line no-debugger + + this.printConfig() if (this.ready) { return this.ready(this.config) @@ -74,8 +75,11 @@ export default { }) }, saveConfig () { - return this.$api.config.save(this.config).then(() => { + return this.$api.config.save(this.config).then((ret) => { this.$message.info('设置已保存') + this.setConfig(ret.allConfig) + this.printConfig('after saveConfig(), ') + return ret }) }, getConfig (key) { @@ -85,6 +89,12 @@ export default { } return value }, + setConfig (newConfig) { + this.$set(this, 'config', newConfig) + }, + printConfig (prefix = '') { + console.log(`${prefix}${this.key} page config:`, this.config, this.systemPlatform) + }, getStatus (key) { const value = lodash.get(this.status, key) if (value == null) { diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue index f98c9d61..fa8a7636 100644 --- a/packages/gui/src/view/pages/setting.vue +++ b/packages/gui/src/view/pages/setting.vue @@ -100,9 +100,17 @@ export default { this.$api.autoStart.enabled(this.config.app.autoStart.enabled) this.saveConfig() }, - onRemoteConfigEnabledChange () { + async onRemoteConfigEnabledChange () { this.saveConfig() - this.$message.info('请重启加速服务') + if (this.config.app.remoteConfig.enabled === true) { + await this.$api.config.startAutoDownloadRemoteConfig() + } else { + this.$api.config.reload() + } + if (this.status.server.enabled || this.status.proxy.enabled) { + await this.$api.proxy.restart() + this.$api.server.restart() + } } } }