| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
- const BaseService = require('./base');
- const path = require('path');
- const _ = require('lodash');
- const lowdb = require('lowdb');
- const FileSync = require('lowdb/adapters/FileSync');
- const storageKey = require('../const/storageKey');
- const fs = require('fs');
- const os = require('os');
- const storageDir = path.normalize(os.userInfo().homedir + '/electron-egg-storage/');
- class StorageService extends BaseService {
- /*
- * instance
- */
- instance(file = null) {
- if (!file) {
- file = path.normalize(storageDir +'db.json');
- }
- const isExist = fs.existsSync(file);
- if (!isExist) {
- return null;
- }
-
- const adapter = new FileSync(file);
- const db = lowdb(adapter);
-
- return db;
- }
- /*
- * getElectronIPCPort
- */
- getElectronIPCPort() {
- const key = storageKey.ELECTRON_IPC + '.port';
- const port = this.instance()
- .get(key)
- .value();
-
- return port;
- }
- /*
- * getStorageDir
- */
- getStorageDir() {
- return storageDir;
- }
- }
- module.exports = StorageService;
|