diff --git a/src/emulator/src/main.js b/src/emulator/src/main.js index 55ace20fc..67f2daf55 100644 --- a/src/emulator/src/main.js +++ b/src/emulator/src/main.js @@ -91,8 +91,13 @@ puter.ui.on('connection', event => { conn.off('message', pty_on_first_message); console.log('[!!] message from connection', message); const pty = ptyMgr.getPTY({ - command: '/bin/bash' + command: message.command, }); + pty.on_close = () => { + conn.postMessage({ + $: 'pty.close', + }); + } console.log('setting up ptt with...', conn); const ptt = new XDocumentPTT(conn, { disableReader: true, @@ -185,6 +190,10 @@ window.onload = async function() console.log('stream id?', packet.streamId); const pty = this.stream_listeners_[packet.streamId]; pty.on_payload(packet.payload); + }, + [WispPacket.CLOSE.id]: function ({ packet }) { + const pty = this.stream_listeners_[packet.streamId]; + pty.on_close(); } }, on: function () { diff --git a/src/phoenix/src/puter-shell/providers/EmuCommandProvider.js b/src/phoenix/src/puter-shell/providers/EmuCommandProvider.js index 08a3ef676..4fbdade84 100644 --- a/src/phoenix/src/puter-shell/providers/EmuCommandProvider.js +++ b/src/phoenix/src/puter-shell/providers/EmuCommandProvider.js @@ -5,6 +5,7 @@ export class EmuCommandProvider { static AVAILABLE = { 'bash': '/bin/bash', 'htop': '/usr/bin/htop', + 'emu-sort': '/usr/bin/sort', }; static EMU_APP_NAME = 'test-emu'; @@ -93,6 +94,9 @@ export class EmuCommandProvider { } } } + if (message.$ === 'pty.close') { + app_close_promise.resolve(); + } }); // Repeatedly copy data from stdin to the child, while it's running. @@ -121,7 +125,6 @@ export class EmuCommandProvider { args: [], }); - const never_resolve = new TeePromise(); - await never_resolve; + await app_close_promise; } } diff --git a/src/puter-wisp/src/exports.js b/src/puter-wisp/src/exports.js index 88b502832..ae39724e1 100644 --- a/src/puter-wisp/src/exports.js +++ b/src/puter-wisp/src/exports.js @@ -223,6 +223,18 @@ const wisp_types = [ } } }, + { + id: 4, + label: 'CLOSE', + describe: ({ attributes }) => { + return `reason: ${attributes.code}`; + }, + getAttributes ({ payload }) { + return { + code: payload[0], + } + } + }, { // TODO: extension types should not be hardcoded here id: 0xf0,