escrcpy/electron/helpers/store.js

32 lines
663 B
JavaScript

import Store from 'electron-store'
import { isEqual } from 'lodash-es'
import { createProxy } from './index.js'
const appStore = new Store()
// appStore.onDidAnyChange((value) => {
// console.log('appStore.onDidAnyChange.value', value)
// })
// 如果没有数据则手动设置值,以保证配置文件生成成功
if (isEqual(appStore.store, {})) {
appStore.store = {}
}
export default {
...createProxy(appStore, [
'set',
'get',
'delete',
'clear',
'reset',
'has',
'onDidChange',
'onDidAnyChange',
'openInEditor',
]),
...appStore,
getAll: () => appStore.store,
setAll: value => (appStore.store = value),
}