Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: 恢复出厂设置功能优化:1)备份文件的同时,创建一个空的原配置文件;2)恢复出厂时,提示如何找回个性化配置。 #341

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/gui/src/bridge/update/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ function install (app, api) {
title: '发现新版本:v' + value.version,
cancelText: '暂不升级',
okText: '升级',
width: 650,
width: 700,
content: h => {
if (value.releaseNotes) {
const notes = []
if (typeof value.releaseNotes === 'string') {
const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n')
return <div>
<div>发布公告:<a onClick={openGithubUrl}>https://github.com/docmirror/dev-sidecar/releases</a></div>
<div>更新内容:</div>
<hr/>
<pre style="max-height:350px;font-family:auto">
{releaseNotes}
</pre>
Expand Down Expand Up @@ -186,15 +186,15 @@ function install (app, api) {
title: `新版本(v${value.version})已准备好,是否立即升级?`,
cancelText: '暂不升级',
okText: '立即升级',
width: 550,
width: 700,
content: h => {
if (value.releaseNotes) {
const notes = []
if (typeof value.releaseNotes === 'string') {
const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n')
return <div>
<div>发布公告:<a onClick={openGithubUrl}>https://github.com/docmirror/dev-sidecar/releases</a></div>
<div>更新内容:</div>
<hr/>
<pre style="max-height:350px;font-family:auto">
{releaseNotes}
</pre>
Expand Down
29 changes: 25 additions & 4 deletions packages/gui/src/view/pages/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
修改后需要重启应用
</div>
</a-form-item>
<hr/>
<a-form-item label="远程配置" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.app.remoteConfig.enabled" @change="onRemoteConfigEnabledChange">
启用远程配置
Expand All @@ -47,6 +48,7 @@
如果重载远程配置后发现下载的还是修改前的内容,请稍等片刻再重试。
</div>
</a-form-item>
<hr/>
<a-form-item label="主题设置" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-radio-group v-model="config.app.theme" default-value="light" button-style="solid">
<a-radio-button :value="'light'" title="light">
Expand Down Expand Up @@ -86,6 +88,7 @@
点击窗口右上角关闭按钮的效果
</div>
</a-form-item>
<hr/>
<a-form-item label="自动检查更新" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-radio-group v-model="config.app.autoChecked" default-value="light" button-style="solid">
<a-radio-button :value="true">
Expand Down Expand Up @@ -216,19 +219,37 @@ export default {
},
async restoreFactorySettings () {
this.$confirm({
title: '提示',
content: '确定要恢复出厂设置吗????????????——————————————————————警告:该功能将删除您的所有页面的个性化配置,并重载默认配置及远程配置(如果启用了的话),请谨慎操作!!!',
title: '确定要恢复出厂设置吗?',
width: 540,
content: h =>
<div class="restore-factory-settings">
<hr/>
<p>
<h3>操作警告:</h3>
<div>
该功能将备份您的所有页面的个性化配置,并重载<span>默认配置</span>及<span>远程配置</span>,请谨慎操作!!!
</div>
</p>
<hr/>
<p>
<h3>找回个性化配置方法:</h3>
<div>
备份文件路径:<span>~/.dev-sidecar/config.json.时间戳.bak.json</span><br/>
将该备份文件重命名为<span>config.json</span>,再重启软件即可恢复配置。
</div>
</p>
</div>,
cancelText: '取消',
okText: '确定',
onOk: async () => {
this.removeUserConfigLoading = true
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
},
Expand Down
21 changes: 21 additions & 0 deletions packages/gui/src/view/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}