diff --git a/core/client.js b/core/client.js index d2e34c1b..60318d7e 100644 --- a/core/client.js +++ b/core/client.js @@ -16,8 +16,7 @@ let gOriginalInput; let kErrorColor = "#dc322f"; let kStatusColor = "#fff"; -/* Functions that server-side app code can call through app.setDocument()-style - * calls. */ +/* Functions that server-side app code can call through the app object. */ const k_api = { setDocument: {args: ['content'], func: api_setDocument}, postMessage: {args: ['message'], func: api_postMessage}, @@ -25,6 +24,7 @@ const k_api = { localStorageSet: {args: ['key', 'value'], func: api_localStorageSet}, localStorageGet: {args: ['key'], func: api_localStorageGet}, requestPermission: {args: ['permission', 'id'], func: api_requestPermission}, + print: {args: ['...'], func: api_print}, }; window.addEventListener("keydown", function(event) { @@ -500,7 +500,11 @@ function api_requestPermission(permission, id) { }); } -function receive(message) { +function api_print() { + console.log('app>', ...arguments); +} + +function _receive_websocket_message(message) { if (message && message.action == "session") { setStatusMessage("🟢 Executing...", kStatusColor); gCredentials = message.credentials; @@ -520,8 +524,6 @@ function receive(message) { } } else if (message && message.action == "ping") { send({action: "pong"}); - } else if (message && message.action == "print") { - console.log('app>', ...message.args); } else if (message && message.action == "stats") { let now = new Date().getTime(); for (let key of Object.keys(message.stats)) { @@ -839,7 +841,7 @@ function connectSocket(path) { })); } gSocket.onmessage = function(event) { - receive(JSON.parse(event.data)); + _receive_websocket_message(JSON.parse(event.data)); } gSocket.onclose = function(event) { const k_codes = { diff --git a/core/core.js b/core/core.js index eb5bd6bc..48919692 100644 --- a/core/core.js +++ b/core/core.js @@ -268,7 +268,7 @@ async function getProcessBlob(blobId, key, options) { } } process.task.onPrint = function(args) { - process.app.send({action: 'print', args: args}); + imports.app.print(...args); }; process.task.onError = function(error) { try {