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)
devices = dev.favor(devices)
return dev.all(devices)
return await dev.all(devices)
}
dev.favor = function (devices) {
@ -253,7 +253,9 @@ dev.all = async function (devices) {
let c = {}
let p = {}
let l = {}
let all
let type
let d
dev.connected = {
projector : false,
@ -263,11 +265,7 @@ dev.all = async function (devices) {
let checklist = []
all = Promise.all(devices.map(async (device) => {
return new Promise(async (resolve, reject) => {
let type
let d
for (let device of devices) {
try {
type = await dev.distinguish(device)
} catch (err) {
@ -276,15 +274,12 @@ dev.all = async function (devices) {
}
try {
d = await dev.connectDevice(device, type)
await dev.connectDevice(device, type)
} catch (err) {
console.error(err)
return reject(err)
}
return d
})
}))
}
//done checking devices
@ -300,7 +295,7 @@ dev.all = async function (devices) {
if (mcopy.settings.camera.intval) {
c.intval = mcopy.settings.camera.intval
await delay(1000)
cam.connectIntval(null, { connect : true, url : c.intval })
awaitcam.connectIntval(null, { connect : true, url : c.intval })
}
if (!dev.connected.light) {
@ -331,10 +326,11 @@ dev.remember = function (which, device, type) {
};
dev.ready = function (projector, camera, light) {
console.log('HAPPNED')
mainWindow.webContents.send('ready', {
camera: camera,
projector: projector,
light: light,
camera,
projector,
light,
profile: mcopy.settings.profile
})
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) {
cam.intval = new Intval(arg.url)
cam.intval.connect((err, ms, state) => {
@ -541,12 +538,15 @@ cam.connectIntval = function (event, arg) {
settings.update('camera', { intval : arg.url })
settings.save()
dev.remember('intval', arg.url, 'camera')
}
return resolve(true)
})
} else if (arg.disconnect) {
cam.intval = null
return resolve(false)
}
})
}
cam.listen = function () {
@ -676,7 +676,7 @@ var init = async function () {
settings.restore()
mcopy.settings = settings.all()
await delay(1000)
await delay(2000)
await dev.enumerate()
}