/
settings.js
88 lines (76 loc) · 2.2 KB
/
settings.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import crypto from 'crypto';
import macaddress from 'macaddress';
import config from 'api/configuration';
import normalizePath from 'utils/normalizePath';
const settingsFileName = 'settings.json';
const defaultBackupDir = normalizePath(config.GetHomeDir() + '/NexusBackups');
const secret =
process.platform === 'darwin'
? process.env.USER + process.env.HOME + process.env.SHELL
: JSON.stringify(macaddress.networkInterfaces(), null, 2);
const defaultPassword = crypto
.createHmac('sha256', secret)
.update('pass')
.digest('hex');
export const defaultSettings = {
// App
locale: 'en',
minimizeOnClose: false,
autoUpdate: true,
sendUsageData: true,
fiatCurrency: 'USD',
minConfirmations: 3,
backupDirectory: defaultBackupDir,
devMode: false,
overviewDisplay: 'standard',
// Core
enableMining: false,
enableStaking: false,
verboseLevel: 2,
manualDaemon: false,
manualDaemonUser: 'rpcserver',
manualDaemonPassword: defaultPassword,
manualDaemonIP: '127.0.0.1',
manualDaemonPort: '9336',
manualDaemonDataDir: config.GetCoreDataDir(),
mapPortUsingUpnp: true,
socks4Proxy: false,
socks4ProxyIP: '127.0.0.1',
socks4ProxyPort: '9050',
detatchDatabaseOnShutdown: false,
// Style
renderGlobe: true,
// Hidden settings
acceptedAgreement: false,
experimentalWarningDisabled: false,
encryptionWarningDisabled: false,
bootstrapSuggestionDisabled: false,
windowWidth: 1020,
windowHeight: 700,
forkBlocks: 0,
};
function readSettings() {
return config.ReadJson(settingsFileName);
}
function writeSettings(settings) {
return config.WriteJson(settingsFileName, filterValidSettings(settings));
}
export function filterValidSettings(settings) {
const validSettings = {};
Object.keys(settings || {}).map(key => {
if (defaultSettings.hasOwnProperty(key)) {
validSettings[key] = settings[key];
} else {
console.error(`Invalid setting \`${key}\``);
}
});
return validSettings;
}
export function LoadSettings() {
const customSettings = readSettings();
return { ...defaultSettings, ...customSettings };
}
export function UpdateSettings(updates) {
const settings = readSettings();
return writeSettings({ ...settings, ...updates });
}