Remove detritus from file this is derived from

This commit is contained in:
mmcwilliams 2017-08-21 22:48:03 -04:00
parent 782484b7e9
commit 3057f95e97
1 changed files with 6 additions and 3 deletions

View File

@ -16,6 +16,7 @@ class wifi {
constructor () {
this._callback = () => {}
this._entry = null
this._ssid = null
}
list (callback) {
exec(iwlist, (err, stdout, stderr) => {
@ -28,7 +29,7 @@ class wifi {
let line
for (let l of lines) {
line = l.replace('ESSID:', '').trim()
if (line != '""') {
if (line !== '""') {
line = line.replace(quoteRe, '')
output.push(line)
}
@ -44,8 +45,9 @@ class wifi {
if (data.search(networkPattern) === -1) {
data += `\n${this._entry}`
} else {
data = data.replace(networkPattern, entry)
data = data.replace(networkPattern, this._entry)
}
this._entry = null
fs.writeFile(filePath, data, 'utf8', this._writeConfigCb)
}
_writeConfigCb (err) {
@ -69,12 +71,13 @@ class wifi {
return this._callback(err)
}
console.log('Wifi refreshed')
this._callback(null, { ssid : ssid, pwd : pwd.length })
//this._callback(null, { ssid : ssid, pwd : pwd.length })
this._callback = () => {}
}
setNetwork (ssid, pwd, callback) {
this._entry = `network={\n\tssid="${ssid}"\n\tpsk="${pwd}"\n}\n`
this._callback = callback
this._ssid = ssid
fs.readFile(filePath, 'utf8', this._readConfigCb)
}
getNetwork (callback) {