|
@@ -145,7 +145,7 @@ async function findPorts(interfaceName) {
|
|
|
|
|
|
const { data, error, pythonError } = await iface.worker.send({ type: 'ports' })
|
|
const { data, error, pythonError } = await iface.worker.send({ type: 'ports' })
|
|
if (error) throw new Error(error)
|
|
if (error) throw new Error(error)
|
|
- if (typeof pythonError !== "undefined") throw new Error(pythonError)
|
|
|
|
|
|
+ if (pythonError) throw new Error(pythonError)
|
|
data.forEach(port => {
|
|
data.forEach(port => {
|
|
const id = port.name || port.device
|
|
const id = port.name || port.device
|
|
// Skip existing ports
|
|
// Skip existing ports
|
|
@@ -180,7 +180,7 @@ async function findOptions(interfaceName) {
|
|
const iface = state.interfaces.find(iface => iface.interfaceName === interfaceName)
|
|
const iface = state.interfaces.find(iface => iface.interfaceName === interfaceName)
|
|
const { data, error, pythonError } = await iface.worker.send({ type: 'options' })
|
|
const { data, error, pythonError } = await iface.worker.send({ type: 'options' })
|
|
if (error) throw new Error(error)
|
|
if (error) throw new Error(error)
|
|
- if (typeof pythonError !== "undefined") throw new Error(pythonError)
|
|
|
|
|
|
+ if (pythonError) throw new Error(pythonError)
|
|
iface.options.push(...data)
|
|
iface.options.push(...data)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -237,8 +237,8 @@ async function connect(parent, args, ctx, info) {
|
|
workerInfo: (parent, args, context, info) => workerInfo(pythonWorker, args, context, info)
|
|
workerInfo: (parent, args, context, info) => workerInfo(pythonWorker, args, context, info)
|
|
}
|
|
}
|
|
const connectionData = await connection.worker.send({ type: 'connect', device })
|
|
const connectionData = await connection.worker.send({ type: 'connect', device })
|
|
- if (spawnData.error) throw new Error(spawnData.error)
|
|
|
|
- if (spawnData.pythonError) throw new Error(spawnData.pythonError)
|
|
|
|
|
|
+ if (connectionData.error) throw new Error(connectionData.error)
|
|
|
|
+ if (connectionData.pythonError) throw new Error(connectionData.pythonError)
|
|
iface.connections.push(connection)
|
|
iface.connections.push(connection)
|
|
state.connections.push(connection)
|
|
state.connections.push(connection)
|
|
return connection
|
|
return connection
|
|
@@ -249,7 +249,7 @@ async function connectionCommand(parent, args, ctx, info) {
|
|
const connection = state.connections.find(connection => connection.id === connectionId)
|
|
const connection = state.connections.find(connection => connection.id === connectionId)
|
|
const { data, error, pythonError } = await connection.worker.send({ type, string, options })
|
|
const { data, error, pythonError } = await connection.worker.send({ type, string, options })
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
- if (typeof pythonError !== "undefined") throw new Error(pythonError)
|
|
|
|
|
|
+ if (pythonError) throw new Error(JSON.stringify(pythonError))
|
|
return data.response
|
|
return data.response
|
|
}
|
|
}
|
|
|
|
|
|
@@ -258,30 +258,32 @@ async function endWorker(parent, args, ctx, info) {
|
|
const { id } = args
|
|
const { id } = args
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
const { data, error, pythonError } = await connection.worker.end()
|
|
const { data, error, pythonError } = await connection.worker.end()
|
|
- console.log(data, error, pythonError)
|
|
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
- if (typeof pythonError !== "undefined") throw new Error(pythonError)
|
|
|
|
- return connection.workerInfo
|
|
|
|
|
|
+ if (pythonError.error !== 0) throw new Error(JSON.stringify(pythonError))
|
|
|
|
+ return connection.workerInfo()
|
|
}
|
|
}
|
|
|
|
|
|
-async function killWorker(parent, args, ctx, info) {
|
|
|
|
|
|
+async function spawnWorker(parent, args, ctx, info) {
|
|
const { id } = args
|
|
const { id } = args
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
- const { data, error, pythonError } = await connection.worker.kill()
|
|
|
|
|
|
+ const { data, error, pythonError } = await connection.worker.spawn()
|
|
console.log(data, error, pythonError)
|
|
console.log(data, error, pythonError)
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
if (error) throw new Error(JSON.stringify(error))
|
|
- if (typeof pythonError !== "undefined") throw new Error(pythonError)
|
|
|
|
- return connection.workerInfo
|
|
|
|
|
|
+ if (pythonError) throw new Error(JSON.stringify(pythonError))
|
|
|
|
+ const connectionData = await connection.worker.send({ type: 'connect', device: connection.device })
|
|
|
|
+ if (connectionData.error) throw new Error(connectionData.error)
|
|
|
|
+ if (connectionData.pythonError) throw new Error(connectionData.pythonError)
|
|
|
|
+ return connection.workerInfo()
|
|
}
|
|
}
|
|
|
|
|
|
-async function spawnWorker(parent, args, ctx, info) {
|
|
|
|
|
|
+async function killWorker(parent, args, ctx, info) {
|
|
const { id } = args
|
|
const { id } = args
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
const connection = state.connections.find(connection => connection.id === id)
|
|
- const { data, error, pythonError } = await connection.worker.spawn()
|
|
|
|
|
|
+ const { data, error, pythonError } = await connection.worker.kill()
|
|
console.log(data, error, pythonError)
|
|
console.log(data, error, pythonError)
|
|
- if (error) throw new Error(error)
|
|
|
|
- if (typeof pythonError !== "undefined") throw new Error(error)
|
|
|
|
- return connection.workerInfo
|
|
|
|
|
|
+ if (error) throw new Error(JSON.stringify(error))
|
|
|
|
+ if (pythonError) throw new Error(JSON.stringify(pythonError))
|
|
|
|
+ return connection.workerInfo()
|
|
}
|
|
}
|
|
|
|
|
|
const resolvers = {
|
|
const resolvers = {
|