分离store逻辑

This commit is contained in:
lyswhut
2021-03-13 14:10:36 +08:00
parent a4d46fd501
commit c663cdbe0d
7 changed files with 68 additions and 82 deletions
+6 -10
View File
@@ -1,22 +1,18 @@
const Store = require('electron-store')
const { windowSizeList } = require('../../common/config')
const { objectDeepMerge, throttle, initSetting } = require('../../common/utils')
const getStore = require('@common/store')
exports.getWindowSizeInfo = ({ windowSizeId = 1 } = {}) => {
return windowSizeList.find(i => i.id === windowSizeId) || windowSizeList[0]
}
const electronStore_config = new Store({
name: 'config',
})
exports.getAppSetting = () => {
return electronStore_config.get('setting')
return getStore('config').get('setting')
}
const electronStore_hotKey = new Store({
name: 'hotKey',
})
exports.getAppHotKeyConfig = () => {
const electronStore_hotKey = getStore('hotKey')
return {
global: electronStore_hotKey.get('global'),
local: electronStore_hotKey.get('local'),
@@ -25,7 +21,7 @@ exports.getAppHotKeyConfig = () => {
const saveHotKeyConfig = throttle(config => {
for (const key of Object.keys(config)) {
global.appHotKey.config[key] = config[key]
electronStore_hotKey.set(key, config[key])
getStore('hotKey').set(key, config[key])
}
})
exports.saveAppHotKeyConfig = config => {
@@ -37,7 +33,7 @@ exports.saveAppHotKeyConfig = config => {
// })
exports.updateSetting = (settings) => {
objectDeepMerge(global.appSetting, settings)
electronStore_config.set('setting', global.appSetting)
getStore('config').set('setting', global.appSetting)
exports.initSetting()
}
exports.initSetting = () => {