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