Explorar o código

dev: handle pty close

Return to phoenix shell when a pty stream is closed by twisp.

Pipes in phoenix with commands from the emulator do not appear to be
working properly, but something in there is working.
KernelDeimos hai 8 meses
pai
achega
4589ed95be

+ 10 - 1
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 () {

+ 5 - 2
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;
     }
 }

+ 12 - 0
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,