From 2125cea0745fe9476615235af10881fe39e0fadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 5 Sep 2024 13:30:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?optimize:=20=E6=81=A2=E5=A4=8D=E5=87=BA?= =?UTF-8?q?=E5=8E=82=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config.js | 24 +++++++++++++------ packages/gui/src/bridge/update/backend.js | 9 ++++++- packages/gui/src/bridge/update/front.js | 8 +++---- packages/gui/src/view/pages/setting.vue | 29 +++++++++++++++++++---- packages/gui/src/view/style/index.scss | 21 ++++++++++++++++ 5 files changed, 75 insertions(+), 16 deletions(-) diff --git a/packages/core/src/config.js b/packages/core/src/config.js index d32dba329..73f326fcc 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -84,11 +84,18 @@ const configApi = { return new Promise((resolve, reject) => { log.info('开始下载远程配置:', remoteConfigUrl) - const headers = {} + const headers = { + 'Cache-Control': 'no-cache' // 禁止使用缓存 + } if (remoteConfigUrl.startsWith('https://raw.githubusercontent.com/')) { headers['Server-Name'] = 'baidu.com' } - request(remoteConfigUrl, headers, (error, response, body) => { + + const options = { + url: remoteConfigUrl, + headers + } + request(options, (error, response, body) => { if (error) { log.error('下载远程配置失败, error:', error, ', response:', response, ', body:', body) reject(error) @@ -272,23 +279,26 @@ const configApi = { const configPath = _getConfigPath() if (fs.existsSync(configPath)) { // 读取 config.json 文件内容 - const fileStr = fs.readFileSync(configPath).toString().replace(/\s/g, '') + const fileOriginalStr = fs.readFileSync(configPath).toString() // 判断文件内容是否为空或空配置 - if (fileStr === '' || fileStr === '{}') { - fs.rmSync(configPath) + const fileStr = fileOriginalStr.replace(/\s/g, '') + if (fileStr.length < 5) { + fs.writeFileSync(configPath, '{}') return false // config.json 内容为空,或为空json } // 备份用户自定义配置文件 - fs.renameSync(configPath, configPath + '.bak' + new Date().getTime() + '.json') + fs.writeFileSync(`${configPath}.${Date.now()}.bak.json`, fileOriginalStr) + // 原配置文件内容设为空 + fs.writeFileSync(configPath, '{}') // 重新加载配置 configApi.load(null) return true // 删除并重新加载配置成功 } else { - return false // config.json 文件不存在或内容为配置 + return false // config.json 文件不存在 } }, resetDefault (key) { diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index 9fcae267b..f5b54744e 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -140,8 +140,15 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { // 检查更新 const releasesApiUrl = 'https://api.github.com/repos/docmirror/dev-sidecar/releases' + const options = { + url: releasesApiUrl, + headers: { + 'User-Agent': `DS/${curVersion}`, + 'Server-Name': 'baidu.com' + } + } async function checkForUpdatesFromGitHub () { - request(releasesApiUrl, { headers: { 'User-Agent': 'DS/' + curVersion, 'Server-Name': 'baidu.com' } }, (error, response, body) => { + request(options, (error, response, body) => { try { if (error) { log.error('检查更新失败:', error) diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js index f9330f1bd..60f137089 100644 --- a/packages/gui/src/bridge/update/front.js +++ b/packages/gui/src/bridge/update/front.js @@ -144,7 +144,7 @@ function install (app, api) { title: '发现新版本:v' + value.version, cancelText: '暂不升级', okText: '升级', - width: 650, + width: 700, content: h => { if (value.releaseNotes) { const notes = [] @@ -152,7 +152,7 @@ function install (app, api) { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') return
发布公告:https://github.com/docmirror/dev-sidecar/releases
-
更新内容:
+
                 {releaseNotes}
               
@@ -186,7 +186,7 @@ function install (app, api) { title: `新版本(v${value.version})已准备好,是否立即升级?`, cancelText: '暂不升级', okText: '立即升级', - width: 550, + width: 700, content: h => { if (value.releaseNotes) { const notes = [] @@ -194,7 +194,7 @@ function install (app, api) { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') return
发布公告:https://github.com/docmirror/dev-sidecar/releases
-
更新内容:
+
                 {releaseNotes}
               
diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue index 25865fbea..a0b0bdc05 100644 --- a/packages/gui/src/view/pages/setting.vue +++ b/packages/gui/src/view/pages/setting.vue @@ -24,6 +24,7 @@ 修改后需要重启应用
+
启用远程配置 @@ -47,6 +48,7 @@ 如果重载远程配置后发现下载的还是修改前的内容,请稍等片刻再重试。
+
@@ -86,6 +88,7 @@ 点击窗口右上角关闭按钮的效果 +
@@ -216,8 +219,26 @@ export default { }, async restoreFactorySettings () { this.$confirm({ - title: '提示', - content: '确定要恢复出厂设置吗????????????——————————————————————警告:该功能将删除您的所有页面的个性化配置,并重载默认配置及远程配置(如果启用了的话),请谨慎操作!!!', + title: '确定要恢复出厂设置吗?', + width: 540, + content: h => +
+
+

+

操作警告:

+
+ 该功能将备份您的所有页面的个性化配置,并重载默认配置远程配置,请谨慎操作!!! +
+

+
+

+

找回个性化配置方法:

+
+ 备份文件路径:~/.dev-sidecar/config.json.时间戳.bak.json
+ 将该备份文件重命名为config.json,再重启软件即可恢复配置。 +
+

+
, cancelText: '取消', okText: '确定', onOk: async () => { @@ -225,10 +246,10 @@ export default { const result = await this.$api.config.removeUserConfig() if (result) { this.config = await this.$api.config.get() - this.$message.success('恢复出厂配置成功,开始重启代理服务和系统代理') + this.$message.success('恢复出厂设置成功,开始重启代理服务和系统代理') await this.reloadConfigAndRestart() } else { - this.$message.info('已是出厂配置,无需恢复') + this.$message.info('已是出厂设置,无需恢复') } this.removeUserConfigLoading = false }, diff --git a/packages/gui/src/view/style/index.scss b/packages/gui/src/view/style/index.scss index 6e352c0c8..137c82216 100644 --- a/packages/gui/src/view/style/index.scss +++ b/packages/gui/src/view/style/index.scss @@ -63,4 +63,25 @@ ol{ .ant-radio-button-wrapper { margin-bottom: 3px; +} + +hr { + border-width: 1px 0 0 0; + margin: 10px 0 +} + +.ant-modal-content { + background-color: #fbfbfb; +} + +.restore-factory-settings { + div { + padding-left: 1em; + } + span { + display: inline-block; + background-color: #eee; + padding: 2px 5px; + margin: 0 5px 5px 5px; + } } \ No newline at end of file From edb4c1999f8d1fbb12e502863340fa82515de640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 5 Sep 2024 14:19:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=8F=E8=B0=83=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config.js | 7 +------ packages/gui/src/bridge/update/backend.js | 9 +-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 73f326fcc..edbde97bb 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -90,12 +90,7 @@ const configApi = { if (remoteConfigUrl.startsWith('https://raw.githubusercontent.com/')) { headers['Server-Name'] = 'baidu.com' } - - const options = { - url: remoteConfigUrl, - headers - } - request(options, (error, response, body) => { + request(remoteConfigUrl, { headers }, (error, response, body) => { if (error) { log.error('下载远程配置失败, error:', error, ', response:', response, ', body:', body) reject(error) diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index f5b54744e..9fcae267b 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -140,15 +140,8 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { // 检查更新 const releasesApiUrl = 'https://api.github.com/repos/docmirror/dev-sidecar/releases' - const options = { - url: releasesApiUrl, - headers: { - 'User-Agent': `DS/${curVersion}`, - 'Server-Name': 'baidu.com' - } - } async function checkForUpdatesFromGitHub () { - request(options, (error, response, body) => { + request(releasesApiUrl, { headers: { 'User-Agent': 'DS/' + curVersion, 'Server-Name': 'baidu.com' } }, (error, response, body) => { try { if (error) { log.error('检查更新失败:', error)