/
universal.js
113 lines (100 loc) · 2.89 KB
/
universal.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Settings functionalities that can be used by both
* renderer process and main process code
*/
import path from 'path';
import crypto from 'crypto';
import macaddress from 'macaddress';
import { homeDir, settingsFilePath, defaultCoreDataDir } from 'consts/paths';
import { readJson, writeJson } from 'utils/json';
const defaultBackupDir = path.join(homeDir, '/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: null,
minimizeOnClose: false,
autoUpdate: true,
sendUsageData: true,
fiatCurrency: 'USD',
minConfirmations: 3,
backupDirectory: defaultBackupDir,
devMode: false,
verifyModuleSource: true,
fakeTransactions: false,
overviewDisplay: 'standard',
displayFiatBalance: false,
// Core
enableMining: false,
enableStaking: true,
verboseLevel: 0,
avatarMode: true,
ipMineWhitelist: '',
coreDataDir: defaultCoreDataDir,
testnetIteration: 0,
manualDaemon: false,
manualDaemonUser: 'rpcserver',
manualDaemonPassword: defaultPassword,
manualDaemonIP: '127.0.0.1',
manualDaemonPort: '9336',
manualDaemonApiUser: 'apiserver',
manualDaemonApiPassword: defaultPassword,
manualDaemonApiIP: '127.0.0.1',
manualDaemonApiPort: '8080',
manualDaemonDataDir: defaultCoreDataDir,
// Style
renderGlobe: true,
addressStyle: 'segmented',
// Modules
disabledModules: [],
allowSymLink: false,
// Hidden settings
acceptedAgreement: false,
experimentalWarningDisabled: false,
encryptionWarningDisabled: false,
bootstrapSuggestionDisabled: false,
migrateSuggestionDisabled: false,
windowWidth: 1200,
windowHeight: 800,
windowX: undefined,
windowY: undefined,
forkBlocks: 0,
walletClean: false,
legacyMode: false,
tritiumModeNoticeDisabled: false,
clearPeers: false,
// If false, show Create new user modal instead of Login
// modal automatically when core is connected
firstCreateNewUserShown: false,
};
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;
}
function readSettings() {
return filterValidSettings(readJson(settingsFilePath));
}
function writeSettings(settings) {
return writeJson(settingsFilePath, filterValidSettings(settings));
}
export function loadSettingsFromFile() {
const customSettings = readSettings();
return { ...defaultSettings, ...customSettings };
}
export function updateSettingsFile(updates) {
const settings = readSettings();
return writeSettings({ ...settings, ...updates });
}