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
{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
{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 @@ 修改后需要重启应用
+
+