From 7b5e5ef2ed1067af721668087ec40cb2c47c160c Mon Sep 17 00:00:00 2001 From: PiEgg Date: Sat, 22 Aug 2020 22:15:46 +0800 Subject: [PATCH] :bug: Fix: shortKeyConfig maybe undefined ISSUES CLOSED: #557 --- src/main/migrate/index.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/migrate/index.ts b/src/main/migrate/index.ts index 0a1f86a..3dd1dab 100644 --- a/src/main/migrate/index.ts +++ b/src/main/migrate/index.ts @@ -1,9 +1,18 @@ import DB from '#/datastore' // from v2.1.2 const updateShortKeyFromVersion212 = (db: typeof DB, shortKeyConfig: IShortKeyConfigs | IOldShortKeyConfigs) => { - let needUpgrade = false + // #557 极端情况可能会出现配置不存在,需要重新写入 + if (shortKeyConfig === undefined) { + const defaultShortKeyConfig = { + enable: true, + key: 'CommandOrControl+Shift+P', + name: 'upload', + label: '快捷上传' + } + db.set('settings.shortKey[picgo:upload]', defaultShortKeyConfig) + return true + } if (shortKeyConfig.upload) { - needUpgrade = true // @ts-ignore shortKeyConfig['picgo:upload'] = { enable: true, @@ -12,13 +21,10 @@ const updateShortKeyFromVersion212 = (db: typeof DB, shortKeyConfig: IShortKeyCo label: '快捷上传' } delete shortKeyConfig.upload - } - if (needUpgrade) { db.set('settings.shortKey', shortKeyConfig) - return shortKeyConfig - } else { - return false + return true } + return false } export {