Fixed: userData path not found error

This commit is contained in:
Molunerfinn
2017-12-08 15:52:41 +08:00
parent d87501212f
commit cfa360bb09
4 changed files with 10 additions and 3 deletions

View File

@@ -2,11 +2,18 @@ import Datastore from 'lowdb'
import LodashId from 'lodash-id'
import FileSync from 'lowdb/adapters/FileSync'
import path from 'path'
import fs from 'fs-extra'
import { remote, app } from 'electron'
const APP = process.type === 'renderer' ? remote.app : app
const STORE_PATH = APP.getPath('userData')
if (process.type !== 'renderer') {
if (!fs.pathExistsSync(STORE_PATH)) {
fs.mkdirpSync(STORE_PATH)
}
}
const adapter = new FileSync(path.join(STORE_PATH, '/data.json'))
const db = Datastore(adapter)