mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 11:52:07 +08:00
Merge branch 'pic'
# Conflicts: # app/service/storage.js
This commit is contained in:
53
app/service/storage.js
Normal file
53
app/service/storage.js
Normal file
@@ -0,0 +1,53 @@
|
||||
'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;
|
||||
Reference in New Issue
Block a user