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,11 +265,7 @@ 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) => {
let type
let d
try { try {
type = await dev.distinguish(device) type = await dev.distinguish(device)
} catch (err) { } catch (err) {
@ -276,15 +274,12 @@ dev.all = async function (devices) {
} }
try { try {
d = await dev.connectDevice(device, type) await dev.connectDevice(device, type)
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return reject(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,7 +522,8 @@ cam.exposure = function (exposure, id) {
}) })
} }
cam.connectIntval = function (event, arg) { cam.connectIntval = async function (event, arg) {
return new Promise((resolve, reject) => {
if (arg.connect) { if (arg.connect) {
cam.intval = new Intval(arg.url) cam.intval = new Intval(arg.url)
cam.intval.connect((err, ms, state) => { cam.intval.connect((err, ms, state) => {
@ -541,12 +538,15 @@ cam.connectIntval = function (event, arg) {
settings.update('camera', { intval : arg.url }) settings.update('camera', { intval : arg.url })
settings.save() settings.save()
dev.remember('intval', arg.url, 'camera') dev.remember('intval', arg.url, 'camera')
} }
return resolve(true)
}) })
} else if (arg.disconnect) { } else if (arg.disconnect) {
cam.intval = null cam.intval = null
return resolve(false)
} }
})
} }
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()
} }