Pārlūkot izejas kodu

Merge branch 'pic'

# Conflicts:
#	app/service/storage.js
gaoshuaixing 5 gadi atpakaļ
vecāks
revīzija
7a6e1325bb
1 mainītis faili ar 53 papildinājumiem un 0 dzēšanām
  1. 53 0
      app/service/storage.js

+ 53 - 0
app/service/storage.js

@@ -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;