Make print more of a standard RPC thing.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3959 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-08-14 16:58:26 +00:00
parent 3464f1d189
commit 4525ee9cca
2 changed files with 9 additions and 7 deletions

View File

@ -16,8 +16,7 @@ let gOriginalInput;
let kErrorColor = "#dc322f"; let kErrorColor = "#dc322f";
let kStatusColor = "#fff"; let kStatusColor = "#fff";
/* Functions that server-side app code can call through app.setDocument()-style /* Functions that server-side app code can call through the app object. */
* calls. */
const k_api = { const k_api = {
setDocument: {args: ['content'], func: api_setDocument}, setDocument: {args: ['content'], func: api_setDocument},
postMessage: {args: ['message'], func: api_postMessage}, postMessage: {args: ['message'], func: api_postMessage},
@ -25,6 +24,7 @@ const k_api = {
localStorageSet: {args: ['key', 'value'], func: api_localStorageSet}, localStorageSet: {args: ['key', 'value'], func: api_localStorageSet},
localStorageGet: {args: ['key'], func: api_localStorageGet}, localStorageGet: {args: ['key'], func: api_localStorageGet},
requestPermission: {args: ['permission', 'id'], func: api_requestPermission}, requestPermission: {args: ['permission', 'id'], func: api_requestPermission},
print: {args: ['...'], func: api_print},
}; };
window.addEventListener("keydown", function(event) { 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") { if (message && message.action == "session") {
setStatusMessage("🟢 Executing...", kStatusColor); setStatusMessage("🟢 Executing...", kStatusColor);
gCredentials = message.credentials; gCredentials = message.credentials;
@ -520,8 +524,6 @@ function receive(message) {
} }
} else if (message && message.action == "ping") { } else if (message && message.action == "ping") {
send({action: "pong"}); send({action: "pong"});
} else if (message && message.action == "print") {
console.log('app>', ...message.args);
} else if (message && message.action == "stats") { } else if (message && message.action == "stats") {
let now = new Date().getTime(); let now = new Date().getTime();
for (let key of Object.keys(message.stats)) { for (let key of Object.keys(message.stats)) {
@ -839,7 +841,7 @@ function connectSocket(path) {
})); }));
} }
gSocket.onmessage = function(event) { gSocket.onmessage = function(event) {
receive(JSON.parse(event.data)); _receive_websocket_message(JSON.parse(event.data));
} }
gSocket.onclose = function(event) { gSocket.onclose = function(event) {
const k_codes = { const k_codes = {

View File

@ -268,7 +268,7 @@ async function getProcessBlob(blobId, key, options) {
} }
} }
process.task.onPrint = function(args) { process.task.onPrint = function(args) {
process.app.send({action: 'print', args: args}); imports.app.print(...args);
}; };
process.task.onError = function(error) { process.task.onError = function(error) {
try { try {