-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.js
53 lines (42 loc) · 1.3 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const packageInfos = require('./package.json');
const logger = require('electron-log');
const NeDB = require('nedb');
const path = require('path');
const fs = require('fs');
logger.transports.file.level = 'error';
logger.transports.console.level = 'debug';
const DBDir = path.join(getUserHome(), `.${packageInfos.name}`);
try {
fs.accessSync(DBDir);
} catch (err) {
fs.mkdirSync(DBDir);
}
/**
* Get Home folder for current user
* @return {string} User home folder path
*/
function getUserHome() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
const clipboardDB = new NeDB(
{filename: path.join(DBDir, '/.clipboarddbv2'), autoload: true});
const settingsDB = new NeDB(
{filename: path.join(DBDir, '/.clipboarddbprefv2'), autoload: true});
settingsDB.ensureIndex({fieldName: 'key', unique: true}, function(err) {
if (err) console.error(err);
});
clipboardDB.ensureIndex({fieldName: 'updated_at'}, function(err) {
if (err) console.error(err);
});
clipboardDB.ensureIndex({fieldName: 'hash'}, function(err) {
if (err) console.error(err);
});
module.exports = {
logger: logger,
packageInfos: packageInfos,
DBDir: DBDir,
clipboardDB: clipboardDB,
settingsDB: settingsDB,
appName: packageInfos.name,
isDevelopment: process.env.ENV === 'development',
};