forked from XinFinOrg/XDCremix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
66 lines (56 loc) · 1.76 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
var CONFIG_FILE = '.remix.config'
const EventEmitter = require('events')
function Config (storage) {
this.items = {}
this.unpersistedItems = {}
this.events = new EventEmitter()
// load on instantiation
try {
var config = storage.get(CONFIG_FILE)
if (config) {
this.items = JSON.parse(config)
}
} catch (exception) {
}
this.exists = function (key) {
return this.items[key] !== undefined
}
this.get = function (key) {
this.ensureStorageUpdated(key)
return this.items[key]
}
this.set = function (key, content) {
this.items[key] = content
try {
storage.set(CONFIG_FILE, JSON.stringify(this.items))
this.events.emit(key + '_changed', content)
} catch (exception) {
}
}
this.ensureStorageUpdated = function (key) {
if (key === 'currentFile') {
if (this.items[key] && this.items[key] !== '' &&
this.items[key].indexOf('config/') !== 0 &&
this.items[key].indexOf('browser/') !== 0 &&
this.items[key].indexOf('localhost/') !== 0 &&
this.items[key].indexOf('swarm/') !== 0 &&
this.items[key].indexOf('gist/') !== 0 &&
this.items[key].indexOf('github/') !== 0 &&
this.items[key].indexOf('ipfs/') !== 0 &&
this.items[key].indexOf('http/') !== 0 &&
this.items[key].indexOf('https/') !== 0) {
this.items[key] = 'browser/' + this.items[key]
}
}
}
this.getUnpersistedProperty = function (key) {
return this.unpersistedItems[key]
}
// TODO: this only used for *one* property "doNotShowTransactionConfirmationAgain"
// and can be removed once it's refactored away in txRunner
this.setUnpersistedProperty = function (key, value) {
this.unpersistedItems[key] = value
}
}
module.exports = Config