Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set onbeforeunload to avoid losing the current terminal session with Ctrl+W #23

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ function startServer() {
}
}

sendPortUpdates();
async function init() {
if (process.env["XTERM_CONFIRM_BROWSER_EXIT"] === "true") {
ws.send(JSON.stringify({ action: "confirmExit" }));
}

sendPortUpdates();
}

init();
});

let clientForExternalMessages = null;
Expand Down
7 changes: 7 additions & 0 deletions src/lib/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export const initiateRemoteCommunicationChannelSocket = async (protocol: string)
output(`Port ${port} has been opened`, { formActions: [openUrlButton], reason: "info" });
break;
}
case "confirmExit": {
// Ask for confirmation before closing the current terminal session
window.onbeforeunload = (e: BeforeUnloadEvent) => {
e.preventDefault();
e.returnValue = "Are you sure you want to close the terminal?";
};
}
default:
console.debug("Unhandled message", messageData);
}
Expand Down