Skip to content

Commit

Permalink
fix resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Dec 6, 2023
1 parent 39c77d0 commit 8bd503d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions frontend/src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ async function fetchJSON(url: string | URL, options?: RequestInit) {
}

async function main() {
const { protocol, host } = new URL(__TWEETY_ORIGIN__ || window.location.origin)
const config = await fetchJSON(`${protocol}//${host}/config`) as Config
const origin = new URL(__TWEETY_ORIGIN__ || window.location.origin)
const config = await fetchJSON(new URL("/config", origin)) as Config
const lightTheme = await importTheme(config.theme || "Tomorrow")
const darkTheme = await importTheme(config.themeDark || config.theme || "Tomorrow Night")
const terminal = new Terminal({
Expand All @@ -42,8 +42,8 @@ async function main() {
terminal.open(document.getElementById("terminal")!);
fitAddon.fit();
const terminalID = nanoid();
const websocketProtocol = protocol === "https:" ? "wss" : "ws";
const websocketUrl = new URL(`${websocketProtocol}://${host}/pty/${terminalID}`)
const websocketProtocol = origin.protocol === "https:" ? "wss" : "ws";
const websocketUrl = new URL(`${websocketProtocol}://${origin.host}/pty/${terminalID}`)

websocketUrl.searchParams.set("cols", terminal.cols.toString())
websocketUrl.searchParams.set("rows", terminal.rows.toString())
Expand Down Expand Up @@ -88,7 +88,7 @@ async function main() {

terminal.onResize((size) => {
const { cols, rows } = size;
const url = `/resize/${terminalID}`;
const url = new URL(`/resize/${terminalID}`, origin);
fetch(url, {
method: "POST",
body: JSON.stringify({ cols, rows }),
Expand All @@ -104,9 +104,9 @@ async function main() {
terminal.options.theme = e.matches ? darkTheme : lightTheme;
});

// window.onbeforeunload = () => {
// ws.close();
// }
window.onbeforeunload = () => {
ws.close();
}

window.onfocus = () => {
terminal.focus();
Expand Down

0 comments on commit 8bd503d

Please sign in to comment.