分离store逻辑
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
const { userApis: defaultUserApis } = require('../config')
|
||||
const Store = require('electron-store')
|
||||
const getStore = require('@common/store')
|
||||
|
||||
let userApis
|
||||
const electronStore_userApi = new Store({
|
||||
name: 'userApi',
|
||||
})
|
||||
|
||||
exports.getUserApis = () => {
|
||||
const electronStore_userApi = getStore('userApi')
|
||||
if (userApis) return userApis
|
||||
userApis = electronStore_userApi.get('userApis')
|
||||
if (!userApis) {
|
||||
@@ -31,7 +29,7 @@ exports.importApi = script => {
|
||||
script,
|
||||
}
|
||||
userApis.push(apiInfo)
|
||||
electronStore_userApi.set('userApis', userApis)
|
||||
getStore('userApi').set('userApis', userApis)
|
||||
return apiInfo
|
||||
}
|
||||
|
||||
@@ -42,5 +40,5 @@ exports.removeApi = ids => {
|
||||
ids.splice(index, 1)
|
||||
}
|
||||
}
|
||||
electronStore_userApi.set('userApis', userApis)
|
||||
getStore('userApi').set('userApis', userApis)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
+6
-10
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user