序启动时对数据文件做读取校验,数据出现损坏时自动备份损坏的数据

pull/495/head
lyswhut 2021-03-14 02:06:35 +08:00
parent b1ccdeb0d3
commit 8171fcd346
5 changed files with 13 additions and 8 deletions

View File

@ -2,7 +2,10 @@
- 新增启动参数`-dhmkh`此参数将禁用Chromium的Hardware Media Key Handling特性用于解决漫步者部分型号耳机与本程序冲突导致耳机意外关机的问题
### 优化
- 程序启动时对数据文件做读取校验数据出现损坏时自动备份损坏的数据若出现数据读取错误的弹窗并出现我的列表丢失时可到GitHub或加群反馈
### 修复
- 修复备份与恢复功能在恢复数据时某些设置不立即生效的问题

View File

@ -10,6 +10,7 @@ const stores = {}
* 获取 Store 对象
* @param {*} name store
* @param {*} isIgnoredError 是否忽略错误
* @param {*} isShowErrorAlert 是否显示错误弹窗
* @returns Store
*/
module.exports = (name, isIgnoredError = true, isShowErrorAlert = true) => {
@ -25,13 +26,13 @@ module.exports = (name, isIgnoredError = true, isShowErrorAlert = true) => {
const backPath = path.join(app.getPath('userData'), name + '.json.bak')
fs.copyFileSync(path.join(app.getPath('userData'), name + '.json'), backPath)
shell.showItemInFolder(backPath)
if (isShowErrorAlert) {
dialog.showMessageBoxSync({
type: 'error',
message: name + ' data load error',
detail: `We have helped you back up the old ${name} file to: ${backPath}\nYou can try to repair and restore it manually\n\nError detail: ${error.message}`,
})
shell.showItemInFolder(backPath)
}

View File

@ -123,9 +123,10 @@ exports.mergeSetting = (setting, version) => {
/**
* 初始化设置
* @param {*} setting
* @param {*} isShowErrorAlert
*/
exports.initSetting = () => {
const electronStore_list = getStore('playList')
exports.initSetting = isShowErrorAlert => {
const electronStore_list = getStore('playList', true, isShowErrorAlert)
const electronStore_config = getStore('config')
const electronStore_downloadList = getStore('downloadList')

View File

@ -34,10 +34,10 @@ exports.saveAppHotKeyConfig = config => {
exports.updateSetting = (settings) => {
objectDeepMerge(global.appSetting, settings)
getStore('config').set('setting', global.appSetting)
exports.initSetting()
exports.initSetting(false)
}
exports.initSetting = () => {
const info = initSetting()
exports.initSetting = (isShowErrorAlert = true) => {
const info = initSetting(isShowErrorAlert)
global.appSetting = info.setting
global.appSettingVersion = info.version
}

View File

@ -33,6 +33,6 @@
"source_alias_all": "聚合大会",
"load_list_file_error_title": "播放列表数据加载错误",
"load_list_file_error_title": "播放列表数据加载错误建议到GitHub或加群反馈",
"load_list_file_error_detail": "我们已经帮你把旧的列表文件备份到{path}\n它以 JSON 格式存储,你可以尝试手动修复并恢复它\n\n错误详情{detail}"
}