forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsCache.js
47 lines (34 loc) · 1.16 KB
/
settingsCache.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
'use strict';
const Store = require('electron-store');
const store = new Store();
const FC = require('./fc');
var settingsCache = (function() {
let publicScope = {};
let privateScope = {};
const SETTINGS_KEY = 'settings';
privateScope.getSetingKey = function(settingName) {
return FC.CONFIG.target + '_' + FC.CONFIG.flightControllerVersion + '_' + FC.CONFIG.buildInfo + '_' + settingName;
}
publicScope.flush = function() {
store.delete(SETTINGS_KEY);
console.log('Settings cache flushed');
};
publicScope.get = function(settingName) {
let settings = store.get(SETTINGS_KEY, null);
if (settings === null) {
return undefined;
}
let setting = settings[privateScope.getSetingKey(settingName)];
return setting;
};
publicScope.set = function(settingName, value) {
let settings = store.get(SETTINGS_KEY, null);
if (settings === null) {
settings = {};
}
settings[privateScope.getSetingKey(settingName)] = value;
store.set(SETTINGS_KEY, settings);
};
return publicScope;
}());
module.exports = settingsCache;