Skip to content

Commit e0dd9ce

Browse files
committed
Close terminal window on exit code 0 (#21)
1 parent 4b98208 commit e0dd9ce

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ const createConnection = async (core, proc, win, term, fit) => {
7979
});
8080

8181
ws.on('message', (ev) => {
82-
if (!pinged) {
82+
if (pinged) {
83+
const message = JSON.parse(ev.data);
84+
if (message.action === 'exit' && message.event.exitCode === 0) {
85+
win.close();
86+
}
87+
} else {
8388
pinged = true;
8489
pid = parseInt(ev.data, 10);
8590

server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ const createTerminal = (core, ws, options = {}, args = []) => {
7474
}
7575
};
7676

77+
term.onExit((ev) => {
78+
try {
79+
// This is a workaround for ping wrapper
80+
ws.send(JSON.stringify({action: 'exit', event: ev}));
81+
} catch (e) {
82+
console.warn(e);
83+
}
84+
})
85+
7786
term.onData((data) => {
7887
try {
7988
// This is a workaround for ping wrapper

0 commit comments

Comments
 (0)