You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
8 years ago
|
'use strict'
|
||
|
|
||
8 years ago
|
var CONFIG_FILE = '.remix.config'
|
||
6 years ago
|
const EventEmitter = require('events')
|
||
8 years ago
|
|
||
|
function Config (storage) {
|
||
|
this.items = {}
|
||
7 years ago
|
this.unpersistedItems = {}
|
||
6 years ago
|
this.events = new EventEmitter()
|
||
8 years ago
|
|
||
|
// load on instantiation
|
||
8 years ago
|
try {
|
||
|
var config = storage.get(CONFIG_FILE)
|
||
|
if (config) {
|
||
|
this.items = JSON.parse(config)
|
||
|
}
|
||
|
} catch (exception) {
|
||
8 years ago
|
}
|
||
|
|
||
|
this.exists = function (key) {
|
||
|
return this.items[key] !== undefined
|
||
|
}
|
||
|
|
||
|
this.get = function (key) {
|
||
8 years ago
|
this.ensureStorageUpdated(key)
|
||
8 years ago
|
return this.items[key]
|
||
|
}
|
||
|
|
||
|
this.set = function (key, content) {
|
||
|
this.items[key] = content
|
||
8 years ago
|
try {
|
||
|
storage.set(CONFIG_FILE, JSON.stringify(this.items))
|
||
6 years ago
|
this.events.emit(key + '_changed', content)
|
||
8 years ago
|
} catch (exception) {
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
this.ensureStorageUpdated = function (key) {
|
||
|
if (key === 'currentFile') {
|
||
7 years ago
|
if (this.items[key] && this.items[key] !== '' &&
|
||
7 years ago
|
this.items[key].indexOf('config/') !== 0 &&
|
||
7 years ago
|
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 &&
|
||
7 years ago
|
this.items[key].indexOf('ipfs/') !== 0 &&
|
||
|
this.items[key].indexOf('http/') !== 0 &&
|
||
|
this.items[key].indexOf('https/') !== 0) {
|
||
8 years ago
|
this.items[key] = 'browser/' + this.items[key]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
this.getUnpersistedProperty = function (key) {
|
||
|
return this.unpersistedItems[key]
|
||
|
}
|
||
|
|
||
6 years ago
|
// TODO: this only used for *one* property "doNotShowTransactionConfirmationAgain"
|
||
|
// and can be removed once it's refactored away in txRunner
|
||
7 years ago
|
this.setUnpersistedProperty = function (key, value) {
|
||
|
this.unpersistedItems[key] = value
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
module.exports = Config
|