Skip to content

Commit 68c963d

Browse files
committed
Optimize: import backup file
1 parent 9ef65c4 commit 68c963d

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

public/_locales/en/messages.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@
427427
"desc_save_success": {
428428
"message": "is saved successfully"
429429
},
430+
"desc_import_config_success": {
431+
"message": "Imported the configuration successfully. The page will be refreshed in 2 seconds"
432+
},
433+
"desc_import_config_failed": {
434+
"message": "failed to Import the configuration. Please check the backup file"
435+
},
430436
"desc_save_failed": {
431437
"message": "is save Failed"
432438
},
@@ -488,7 +494,7 @@
488494
"message": "Requests monitoring is not enabled"
489495
},
490496
"feedback_request_failed": {
491-
"message": "Failed to get the content, Check your URL & the Content Format"
497+
"message": "Failed to get the content. Check your Url & the content format"
492498
},
493499
"feedback_reject_invalid": {
494500
"message": "Format to fill in: SCHEME[space]HOST:PORT. Suggestion: HTTPS 127.0.0.1:65432"

public/_locales/zh_CN/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@
427427
"desc_save_success": {
428428
"message": "保存成功"
429429
},
430+
"desc_import_config_success": {
431+
"message": "恢复配置成功,2s后刷新配置页面"
432+
},
433+
"desc_import_config_failed": {
434+
"message": "恢复配置失败,请检查备份文件"
435+
},
430436
"desc_save_failed": {
431437
"message": "保存失败"
432438
},

src/options/views/home/HomeDefault.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,22 @@ function handleImportConfig(event) {
3333
const file = event.target.files[0]
3434
const reader = new FileReader()
3535
reader.onload = async function (event) {
36-
const tmpObj = JSON.parse(event.target.result)
37-
tmpObj.config_autoSync = false
38-
tmpObj.status_proxyKey = 'direct'
39-
const result = await Browser.Storage.getLocalAll()
40-
console.log(Object.keys(result))
41-
await Browser.Storage.removeLocal(Object.keys(result))
42-
await Browser.Storage.setLocal(tmpObj)
43-
location.reload()
36+
try {
37+
const tmpObj = JSON.parse(event.target.result)
38+
tmpObj.config_autoSync = false
39+
tmpObj.status_proxyKey = 'direct'
40+
const result = await Browser.Storage.getLocalAll()
41+
console.log(Object.keys(result))
42+
await Browser.Storage.removeLocal(Object.keys(result))
43+
await Browser.Storage.setLocal(tmpObj)
44+
toast.info(Browser.I18n.getMessage('desc_import_config_success'))
45+
setTimeout(() => {
46+
location.reload()
47+
}, 2000)
48+
} catch (err) {
49+
toast.warning(Browser.I18n.getMessage('desc_import_config_failed'))
50+
console.log('Error: ', err)
51+
}
4452
}
4553
reader.readAsText(file)
4654
}

0 commit comments

Comments
 (0)