分离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
+3 -7
View File
@@ -1,12 +1,8 @@
const Store = require('electron-store')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc')
const getStore = require('@common/store')
const electronStore_data = new Store({
name: 'data',
})
mainHandle(ipcMainWindowNames.get_data, async(event, path) => electronStore_data.get(path))
mainHandle(ipcMainWindowNames.get_data, async(event, path) => getStore('data').get(path))
mainOn(ipcMainWindowNames.save_data, (event, { path, data }) => electronStore_data.set(path, data))
mainOn(ipcMainWindowNames.save_data, (event, { path, data }) => getStore('data').set(path, data))
+9 -8
View File
@@ -1,10 +1,8 @@
const Store = require('electron-store')
const { mainSend, NAMES: { mainWindow: ipcMainWindowNames }, mainOn, mainHandle } = require('../../common/ipc')
const { mainWindow: MAIN_WINDOW_EVENT_NAME, hotKey: HOT_KEY_EVENT_NAME } = require('../events/_name')
const getStore = require('@common/store')
const electronStore_hotKey = new Store({
name: 'hotKey',
})
// const { registerHotkey, unRegisterHotkey } = require('../modules/hotKey/utils')
// mainHandle(ipcMainWindowNames.set_hot_key_config, async(event, { action, data }) => {
@@ -19,10 +17,13 @@ const electronStore_hotKey = new Store({
// }
// })
mainHandle(ipcMainWindowNames.get_hot_key, async() => ({
local: electronStore_hotKey.get('local'),
global: electronStore_hotKey.get('global'),
}))
mainHandle(ipcMainWindowNames.get_hot_key, async() => {
const electronStore_hotKey = getStore('hotKey')
return {
local: electronStore_hotKey.get('local'),
global: electronStore_hotKey.get('global'),
}
})
mainOn(ipcMainWindowNames.quit, () => global.lx_event.mainWindow.quit())
mainOn(ipcMainWindowNames.min_toggle, () => global.lx_event.mainWindow.toggleMinimize())
+5 -19
View File
@@ -1,38 +1,24 @@
const Store = require('electron-store')
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames }, mainHandle } = require('../../common/ipc')
const getStore = require('@common/store')
let electronStore_list
let electronStore_downloadList
mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) => {
if (!electronStore_list) {
electronStore_list = new Store({
name: 'playList',
clearInvalidConfig: !isIgnoredError,
})
}
if (!electronStore_downloadList) {
electronStore_downloadList = new Store({
name: 'downloadList',
})
}
const electronStore_list = getStore('playList', isIgnoredError)
return {
defaultList: electronStore_list.get('defaultList'),
loveList: electronStore_list.get('loveList'),
userList: electronStore_list.get('userList'),
downloadList: electronStore_downloadList.get('list'),
downloadList: getStore('downloadList').get('list'),
}
})
const handleSaveList = ({ defaultList, loveList, userList }) => {
if (!electronStore_list) return
let data = {}
if (defaultList != null) data.defaultList = defaultList
if (loveList != null) data.loveList = loveList
if (userList != null) data.userList = userList
electronStore_list.set(data)
getStore('playList').set(data)
}
mainOn(ipcMainWindowNames.save_playlist, (event, { type, data }) => {
switch (type) {
@@ -40,7 +26,7 @@ mainOn(ipcMainWindowNames.save_playlist, (event, { type, data }) => {
handleSaveList(data)
break
case 'downloadList':
electronStore_downloadList && electronStore_downloadList.set('list', data)
getStore('downloadList').set('list', data)
break
}
})