From 61b6db8a94f0d345df6dfb808e30f40aad751402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 22 Feb 2024 17:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E9=85=8D=E7=BD=AE=20=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E8=8E=B7=E5=8F=96=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E9=85=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config.js | 19 +++++++++ packages/gui/src/view/pages/setting.vue | 57 +++++++++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 8ad2ad3c..00f66f19 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -111,6 +111,25 @@ const configApi = { return {} }, + readRemoteConfigStr () { + if (get().app.remoteConfig.enabled !== true) { + return '{}' + } + try { + const path = _getRemoteSavePath() + if (fs.existsSync(path)) { + log.info('读取远程配置文件内容:', path) + const file = fs.readFileSync(path) + return file.toString() + } else { + log.warn('远程配置文件不存在:', path) + } + } catch (e) { + log.warn('远程配置内容读取失败:', e) + } + + return '{}' + }, /** * 保存自定义的 config * @param newConfig diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue index fa8a7636..85297af7 100644 --- a/packages/gui/src/view/pages/setting.vue +++ b/packages/gui/src/view/pages/setting.vue @@ -35,6 +35,13 @@ <a-form-item label="远程配置地址" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-input v-model="config.app.remoteConfig.url"></a-input> </a-form-item> + <a-form-item label="重载远程配置" :label-col="labelCol" :wrapper-col="wrapperCol"> + <a-button :disabled="config.app.remoteConfig.enabled === false" :loading="reloadLoading" icon="sync" @click="reloadRemoteConfig()">重载远程配置</a-button> + <div class="form-help"> + 注意,部分远程配置文件所在站点,修改内容后可能需要等待一段时间才能生效。 + <br/>如果重载远程配置后发现下载的还是修改前的内容,请稍等片刻再重试。 + </div> + </a-form-item> <a-form-item label="首页提示" :label-col="labelCol" :wrapper-col="wrapperCol"> <a-radio-group v-model="config.app.showShutdownTip" default-value="true" button-style="solid"> @@ -84,7 +91,8 @@ export default { mixins: [Plugin], data () { return { - key: 'app' + key: 'app', + reloadLoading: false } }, created () { @@ -100,17 +108,48 @@ export default { this.$api.autoStart.enabled(this.config.app.autoStart.enabled) this.saveConfig() }, - async onRemoteConfigEnabledChange () { - this.saveConfig() - if (this.config.app.remoteConfig.enabled === true) { - await this.$api.config.startAutoDownloadRemoteConfig() - } else { - this.$api.config.reload() - } + async reloadAndRestart () { + this.$api.config.reload() if (this.status.server.enabled || this.status.proxy.enabled) { await this.$api.proxy.restart() - this.$api.server.restart() + await this.$api.server.restart() + this.$message.info('代理服务和系统代理重启成功') + } else { + this.$message.info('代理服务和系统代理未启动,无需重启') } + }, + async onRemoteConfigEnabledChange () { + await this.saveConfig() + if (this.config.app.remoteConfig.enabled === true) { + this.reloadLoading = true + this.$message.info('开始下载远程配置') + await this.$api.config.downloadRemoteConfig() + this.$message.info('下载远程配置成功,开始重启代理服务和系统代理') + await this.reloadAndRestart() + this.reloadLoading = false + } else { + this.$message.info('开始重启代理服务和系统代理') + await this.reloadAndRestart() + } + }, + async reloadRemoteConfig () { + this.reloadLoading = true + + const remoteConfig = {} + + await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old = ret }) + await this.$api.config.downloadRemoteConfig() + await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.new = ret }) + + if (remoteConfig.old === remoteConfig.new) { + this.$message.info('远程配置没有变化,不做任何处理。') + this.$message.info('如果您确实修改了远程配置,请稍等片刻再重试!') + } else { + this.$message.info('获取到了最新的远程配置,开始重启代理服务和系统代理') + await this.reloadAndRestart() + } + + this.reloadLoading = false } } }