OSDN Git Service

repath the bytomd data path.
[bytom/bytom-electron.git] / modules / settings.js
1 const { app } = require('electron')
2 const path = require('path')
3
4 import logger from './logger'
5
6 let instance = null
7
8 class Settings {
9   constructor() {
10     if (!instance) {
11       instance = this
12     }
13
14     return instance
15   }
16
17   init() {
18     const logLevel = { logLevel: 'info' }
19     const logFolder = { logFolder: path.join(this.userDataPath, 'logs') }
20     const loggerOptions = Object.assign('info', logLevel, logFolder)
21     logger.setup(loggerOptions)
22   }
23
24   get userDataPath() {
25     return app.getPath('userData')
26   }
27
28   get appDataPath() {
29     // Application Support/
30     return app.getPath('appData')
31   }
32
33   get userHomePath() {
34     return app.getPath('home')
35   }
36
37   get bytomdPath() {
38     return process.env.DEV?
39       path.join(__dirname, '../bytomd/bytomd-darwin_amd64'):
40       glob.sync( path.join(__dirname, '../bytomd/bytomd*'))
41   }
42
43   get bytomdDataPath(){
44     let bytomdDataPath
45     switch (process.platform){
46       case 'win32':
47         bytomdDataPath = `${app.getPath('appData')}/Bytom`
48         break
49       case 'darwin':
50         bytomdDataPath = `${app.getPath('home')}/Library/Application Support/Bytom`
51         break
52       case 'linux':
53         bytomdDataPath = `${app.getPath('home')}/.bytom`
54     }
55     return bytomdDataPath
56   }
57
58   constructUserDataPath(filePath) {
59     return path.join(this.userDataPath, filePath)
60   }
61 }
62
63 module.exports = new Settings()