Sort discovered devices into a list where previously connected ones are sorted to the top of the array.
This commit is contained in:
parent
66d9af42b6
commit
c72d80c6a1
31
app/main.js
31
app/main.js
|
@ -42,10 +42,35 @@ var enumerateDevices = function (err, devices) {
|
|||
}, 1000)
|
||||
} else {
|
||||
log.info('Found ' + devices.length + ' USB devices', 'SERIAL', true, true)
|
||||
console.dir(devices)
|
||||
devices = favorDevices(devices)
|
||||
console.dir(devices)
|
||||
distinguishDevices(devices)
|
||||
}
|
||||
}
|
||||
|
||||
var favorDevices = function (devices) {
|
||||
const past = mcopy.settings.devices.filter(dev => {
|
||||
if (dev.arduino) {
|
||||
return dev
|
||||
}
|
||||
}).map(dev => {
|
||||
return dev.arduino
|
||||
})
|
||||
if (past.length === 0) {
|
||||
return devices
|
||||
}
|
||||
devices.sort((a, b) => {
|
||||
if (past.indexOf(a) !== -1 && past.indexOf(b) === -1) {
|
||||
return 1
|
||||
} else if (past.indexOf(a) === -1 && past.indexOf(b) !== -1) {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
})
|
||||
return devices
|
||||
}
|
||||
|
||||
var distinguishDevice = function (device, callback) {
|
||||
var connectCb = function (err, device) {
|
||||
if (err) {
|
||||
|
@ -361,17 +386,17 @@ cam.listen = function () {
|
|||
event.returnValue = true
|
||||
})
|
||||
ipcMain.on('intval', (event, arg) => {
|
||||
console.dir(arg)
|
||||
if (arg.connect) {
|
||||
cam.intval = new Intval(arg.url)
|
||||
/*cam.intval.connect((err, ms, state) => {
|
||||
cam.intval.connect((err, ms, state) => {
|
||||
if (err) {
|
||||
mainWindow.webContents.send('intval', { connected : false })
|
||||
log.info(`Cannot connect to ${arg.url}`, 'INTVAL', true, true)
|
||||
cam.intval = null
|
||||
} else {
|
||||
log.info()
|
||||
}
|
||||
})*/
|
||||
})
|
||||
} else if (arg.disconnect) {
|
||||
cam.intval = null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue