diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/remote/RemoteJSExecutor.java b/doric-android/devkit/src/main/java/pub/doric/devkit/remote/RemoteJSExecutor.java index 6db72af6..33b6dbaa 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/remote/RemoteJSExecutor.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/remote/RemoteJSExecutor.java @@ -120,6 +120,11 @@ public class RemoteJSExecutor { } public void injectGlobalJSObject(String name, JavaValue javaValue) { + webSocket.send(new JSONBuilder().put("cmd", "injectGlobalJSObject") + .put("name", name) + .put("type", javaValue.getType()) + .put("value", javaValue.getValue()).toString() + ); } public JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) { diff --git a/doric-js/bundle/doric-vm.js b/doric-js/bundle/doric-vm.js index 9c7a66e3..f188286c 100644 --- a/doric-js/bundle/doric-vm.js +++ b/doric-js/bundle/doric-vm.js @@ -3752,14 +3752,6 @@ let global$2 = new Function('return this')(); global$2.doric = doric; global$2.context = jsObtainContext(contextId); global$2.Entry = jsObtainEntry(contextId); -global$2.Environment = { - 'platform': 'debugger', - 'platformVersion': '1.0', - 'appName': '', - 'appVersion': '', - 'screenWidth': 0, - 'screenHeight': 0 -}; // dev kit client const devClient = new WebSocketClient('ws://localhost:7777'); devClient.on('open', function open() { @@ -3778,6 +3770,31 @@ debugServer.on('connection', function connection(ws) { ws.on('message', function incoming(message) { let messageObject = JSON.parse(message); switch (messageObject.cmd) { + case "injectGlobalJSObject": + console.log(messageObject.name); + let type = messageObject.type; + let value = messageObject.value; + let arg; + if (type.type === 0) { + arg = null; + } + else if (type === 1) { + arg = parseFloat(value); + } + else if (type === 2) { + arg = (value == 'true'); + } + else if (type === 3) { + arg = value.toString(); + } + else if (type === 4) { + arg = JSON.parse(value); + } + else if (type === 5) { + arg = JSON.parse(value); + } + Reflect.set(global$2, messageObject.name, arg); + break; case "injectGlobalJSFunction": console.log(messageObject.name); Reflect.set(global$2, messageObject.name, function () { diff --git a/doric-js/index.debug.ts b/doric-js/index.debug.ts index f971f09b..47711f4e 100644 --- a/doric-js/index.debug.ts +++ b/doric-js/index.debug.ts @@ -25,15 +25,6 @@ global.doric = doric global.context = doric.jsObtainContext(contextId) global.Entry = doric.jsObtainEntry(contextId) -global.Environment = { - 'platform': 'debugger', - 'platformVersion': '1.0', - 'appName': '', - 'appVersion': '', - 'screenWidth': 0, - 'screenHeight': 0 -} - // dev kit client const devClient = new WebSocketClient('ws://localhost:7777') devClient.on('open', function open() { @@ -53,6 +44,27 @@ debugServer.on('connection', function connection(ws) { ws.on('message', function incoming(message: string) { let messageObject = JSON.parse(message) switch (messageObject.cmd) { + case "injectGlobalJSObject": + console.log(messageObject.name) + let type = messageObject.type + let value = messageObject.value + + let arg + if (type.type === 0) { + arg = null + } else if (type === 1) { + arg = parseFloat(value) + } else if (type === 2) { + arg = (value == 'true') + } else if (type === 3) { + arg = value.toString() + } else if (type === 4) { + arg = JSON.parse(value) + } else if (type === 5) { + arg = JSON.parse(value) + } + Reflect.set(global, messageObject.name, arg) + break case "injectGlobalJSFunction": console.log(messageObject.name) Reflect.set(global, messageObject.name, function () { diff --git a/doric-js/lib/index.debug.js b/doric-js/lib/index.debug.js index 0fd07a04..5abb7633 100644 --- a/doric-js/lib/index.debug.js +++ b/doric-js/lib/index.debug.js @@ -24,14 +24,6 @@ let global = new Function('return this')(); global.doric = doric; global.context = doric.jsObtainContext(contextId); global.Entry = doric.jsObtainEntry(contextId); -global.Environment = { - 'platform': 'debugger', - 'platformVersion': '1.0', - 'appName': '', - 'appVersion': '', - 'screenWidth': 0, - 'screenHeight': 0 -}; // dev kit client const devClient = new WebSocketClient('ws://localhost:7777'); devClient.on('open', function open() { @@ -50,6 +42,31 @@ debugServer.on('connection', function connection(ws) { ws.on('message', function incoming(message) { let messageObject = JSON.parse(message); switch (messageObject.cmd) { + case "injectGlobalJSObject": + console.log(messageObject.name); + let type = messageObject.type; + let value = messageObject.value; + let arg; + if (type.type === 0) { + arg = null; + } + else if (type === 1) { + arg = parseFloat(value); + } + else if (type === 2) { + arg = (value == 'true'); + } + else if (type === 3) { + arg = value.toString(); + } + else if (type === 4) { + arg = JSON.parse(value); + } + else if (type === 5) { + arg = JSON.parse(value); + } + Reflect.set(global, messageObject.name, arg); + break; case "injectGlobalJSFunction": console.log(messageObject.name); Reflect.set(global, messageObject.name, function () {