Fix startup error, where spinner would be removed before fully connected

This commit is contained in:
mmcw-dev 2018-12-10 21:52:48 -05:00
parent deee2ba59f
commit f110718342
1 changed files with 48 additions and 48 deletions

View File

@ -71,7 +71,7 @@ dev.enumerate = async function () {
} }
log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true) log.info(`Found ${devices.length} USB devices`, 'SERIAL', true, true)
devices = dev.favor(devices) devices = dev.favor(devices)
return dev.all(devices) return await dev.all(devices)
} }
dev.favor = function (devices) { dev.favor = function (devices) {
@ -253,7 +253,9 @@ dev.all = async function (devices) {
let c = {} let c = {}
let p = {} let p = {}
let l = {} let l = {}
let all let type
let d
dev.connected = { dev.connected = {
projector : false, projector : false,
@ -263,28 +265,21 @@ dev.all = async function (devices) {
let checklist = [] let checklist = []
all = Promise.all(devices.map(async (device) => { for (let device of devices) {
return new Promise(async (resolve, reject) => { try {
let type type = await dev.distinguish(device)
let d } catch (err) {
console.error(err)
return reject(err)
}
try { try {
type = await dev.distinguish(device) await dev.connectDevice(device, type)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return reject(err) return reject(err)
} }
}
try {
d = await dev.connectDevice(device, type)
} catch (err) {
console.error(err)
return reject(err)
}
return d
})
}))
//done checking devices //done checking devices
@ -300,7 +295,7 @@ dev.all = async function (devices) {
if (mcopy.settings.camera.intval) { if (mcopy.settings.camera.intval) {
c.intval = mcopy.settings.camera.intval c.intval = mcopy.settings.camera.intval
await delay(1000) await delay(1000)
cam.connectIntval(null, { connect : true, url : c.intval }) awaitcam.connectIntval(null, { connect : true, url : c.intval })
} }
if (!dev.connected.light) { if (!dev.connected.light) {
@ -331,10 +326,11 @@ dev.remember = function (which, device, type) {
}; };
dev.ready = function (projector, camera, light) { dev.ready = function (projector, camera, light) {
console.log('HAPPNED')
mainWindow.webContents.send('ready', { mainWindow.webContents.send('ready', {
camera: camera, camera,
projector: projector, projector,
light: light, light,
profile: mcopy.settings.profile profile: mcopy.settings.profile
}) })
settings.update('camera', camera) settings.update('camera', camera)
@ -526,27 +522,31 @@ cam.exposure = function (exposure, id) {
}) })
} }
cam.connectIntval = function (event, arg) { cam.connectIntval = async function (event, arg) {
if (arg.connect) { return new Promise((resolve, reject) => {
cam.intval = new Intval(arg.url) if (arg.connect) {
cam.intval.connect((err, ms, state) => { cam.intval = new Intval(arg.url)
if (err) { cam.intval.connect((err, ms, state) => {
mainWindow.webContents.send('intval', { connected : false }) if (err) {
log.info(`Cannot connect to ${arg.url}`, 'INTVAL', true, true) mainWindow.webContents.send('intval', { connected : false })
cam.intval = null log.info(`Cannot connect to ${arg.url}`, 'INTVAL', true, true)
delete cam.intval cam.intval = null
} else { delete cam.intval
mainWindow.webContents.send('intval', { connected : true, url : arg.url, state : state }) } else {
log.info(`Connected to INTVAL3 @ ${arg.url}`, 'INTVAL', true, true) mainWindow.webContents.send('intval', { connected : true, url : arg.url, state : state })
settings.update('camera', { intval : arg.url }) log.info(`Connected to INTVAL3 @ ${arg.url}`, 'INTVAL', true, true)
settings.save() settings.update('camera', { intval : arg.url })
dev.remember('intval', arg.url, 'camera') settings.save()
dev.remember('intval', arg.url, 'camera')
}
return resolve(true)
})
} else if (arg.disconnect) {
cam.intval = null
return resolve(false)
}
})
}
})
} else if (arg.disconnect) {
cam.intval = null
}
} }
cam.listen = function () { cam.listen = function () {
@ -676,7 +676,7 @@ var init = async function () {
settings.restore() settings.restore()
mcopy.settings = settings.all() mcopy.settings = settings.all()
await delay(1000) await delay(2000)
await dev.enumerate() await dev.enumerate()
} }