debugger send back to switch js engine
This commit is contained in:
parent
98ae5a9d0e
commit
9d641e2602
@ -81,7 +81,7 @@ public class DoricDriver implements IDoricDriver {
|
|||||||
return AsyncCall.ensureRunInHandler(mUIHandler, callable);
|
return AsyncCall.ensureRunInHandler(mUIHandler, callable);
|
||||||
case INDEPENDENT:
|
case INDEPENDENT:
|
||||||
default:
|
default:
|
||||||
return AsyncCall.ensureRunIExecutor(mBridgeExecutor, callable);
|
return AsyncCall.ensureRunInExecutor(mBridgeExecutor, callable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class AsyncCall {
|
|||||||
return asyncResult;
|
return asyncResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> AsyncResult<T> ensureRunIExecutor(ExecutorService executorService, final Callable<T> callable) {
|
public static <T> AsyncResult<T> ensureRunInExecutor(ExecutorService executorService, final Callable<T> callable) {
|
||||||
final AsyncResult<T> asyncResult = new AsyncResult<>();
|
final AsyncResult<T> asyncResult = new AsyncResult<>();
|
||||||
executorService.execute(new Runnable() {
|
executorService.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,46 +1,45 @@
|
|||||||
const ws = require('nodejs-websocket')
|
const ws = require('nodejs-websocket')
|
||||||
const { exec, spawn } = require('child_process')
|
const { exec, spawn } = require('child_process')
|
||||||
|
|
||||||
|
var clientConnection = null
|
||||||
|
var debuggerConnection = null
|
||||||
|
|
||||||
const createServer = () => {
|
const createServer = () => {
|
||||||
let server = ws.createServer(connection => {
|
let server = ws.createServer(connection => {
|
||||||
console.log('connected', connection.key)
|
console.log('connected', connection.headers.host)
|
||||||
|
|
||||||
|
if (connection.headers.host.startsWith("localhost")) {
|
||||||
|
console.log("debugger " + connection.key + " attached to dev kit")
|
||||||
|
debuggerConnection = connection
|
||||||
|
|
||||||
|
clientConnection.sendText(JSON.stringify({
|
||||||
|
cmd: 'SWITCH_TO_DEBUG'
|
||||||
|
}), function() {
|
||||||
|
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log("client " + connection.key + " attached to dev kit")
|
||||||
|
}
|
||||||
|
|
||||||
connection.on('text', function (result) {
|
connection.on('text', function (result) {
|
||||||
console.log('text', result)
|
console.log('text', result)
|
||||||
let resultObject = JSON.parse(result)
|
let resultObject = JSON.parse(result)
|
||||||
switch(resultObject.cmd) {
|
switch(resultObject.cmd) {
|
||||||
case 'DEBUG':
|
case 'DEBUG':
|
||||||
|
clientConnection = connection
|
||||||
|
|
||||||
let contextId = resultObject.data.contextId
|
let contextId = resultObject.data.contextId
|
||||||
let projectHome = resultObject.data.projectHome
|
let projectHome = resultObject.data.projectHome
|
||||||
console.log(projectHome)
|
console.log(connection.key + " request debug, project home: " + projectHome)
|
||||||
{
|
|
||||||
const code = spawn('code', [projectHome, projectHome + "/src/Snake.ts"])
|
spawn('code', [projectHome, projectHome + "/src/Snake.ts"])
|
||||||
code.stdout.on('data', (data) => {
|
setTimeout(() => {
|
||||||
console.log(`stdout: ${data}`)
|
exec('osascript -e \'tell application "System Events"\ntell application "Visual Studio Code" to activate\nkey code 96\nend tell\'', (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(`stdout: ${err}`)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
}, 3000)
|
||||||
code.stderr.on('data', (data) => {
|
|
||||||
console.error(`stderr: ${data}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
code.on('close', (code) => {
|
|
||||||
console.log(`child process exited with code ${code}`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
{
|
|
||||||
setTimeout(() => {
|
|
||||||
exec('osascript -e \'tell application "System Events"\ntell application "Visual Studio Code" to activate\nkey code 96\nend tell\'', (err, stdout, stderr) => {
|
|
||||||
if (err) {
|
|
||||||
// node couldn't execute the command
|
|
||||||
console.log(`stdout: ${err}`)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the *entire* stdout and stderr (buffered)
|
|
||||||
console.log(`stdout: ${stdout}`);
|
|
||||||
console.log(`stderr: ${stderr}`);
|
|
||||||
})
|
|
||||||
}, 4000)
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -49,7 +48,7 @@ const createServer = () => {
|
|||||||
console.log('connect', code)
|
console.log('connect', code)
|
||||||
})
|
})
|
||||||
connection.on('close', function (code) {
|
connection.on('close', function (code) {
|
||||||
console.log('close', code)
|
console.log('close: code = ' + code, connection.key)
|
||||||
})
|
})
|
||||||
connection.on('error', function (code) {
|
connection.on('error', function (code) {
|
||||||
console.log('error', code)
|
console.log('error', code)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
import * as doric from './src/runtime/sandbox'
|
import * as doric from './src/runtime/sandbox'
|
||||||
import * as WebSocket from 'ws'
|
import * as WebSocket from 'ws'
|
||||||
|
const WebSocketClient = require('ws')
|
||||||
|
|
||||||
let global = new Function('return this')()
|
let global = new Function('return this')()
|
||||||
global.doric = doric
|
global.doric = doric
|
||||||
@ -22,9 +23,22 @@ const contextId = "1"
|
|||||||
global.context = doric.jsObtainContext(contextId)
|
global.context = doric.jsObtainContext(contextId)
|
||||||
global.Entry = doric.jsObtainEntry(contextId)
|
global.Entry = doric.jsObtainEntry(contextId)
|
||||||
|
|
||||||
const wss = new WebSocket.Server({ port: 2080 })
|
// dev kit client
|
||||||
wss.on('connection', function connection(ws) {
|
const devClient = new WebSocketClient('ws://localhost:7777')
|
||||||
console.log('Connected')
|
devClient.on('open', function open() {
|
||||||
|
console.log('dev kit connected on 7777')
|
||||||
|
})
|
||||||
|
devClient.on('message', function incoming(data: any) {
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
devClient.on('error', function incoming(error: any) {
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
// debug server
|
||||||
|
const debugServer = new WebSocket.Server({ port: 2080 })
|
||||||
|
debugServer.on('connection', function connection(ws) {
|
||||||
|
console.log('connected')
|
||||||
ws.on('message', function incoming(message: string) {
|
ws.on('message', function incoming(message: string) {
|
||||||
let messageObject = JSON.parse(message)
|
let messageObject = JSON.parse(message)
|
||||||
switch (messageObject.cmd) {
|
switch (messageObject.cmd) {
|
||||||
@ -79,7 +93,9 @@ wss.on('connection', function connection(ws) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
console.log('Start Server')
|
debugServer.on('listening', function connection(ws: WebSocket) {
|
||||||
|
console.log('debugger server started on 2080')
|
||||||
|
})
|
||||||
|
|
||||||
global.injectGlobal = (objName: string, obj: string) => {
|
global.injectGlobal = (objName: string, obj: string) => {
|
||||||
Reflect.set(global, objName, JSON.parse(obj))
|
Reflect.set(global, objName, JSON.parse(obj))
|
||||||
|
Reference in New Issue
Block a user