Skip to content

Commit

Permalink
Add support for resizing the lab window
Browse files Browse the repository at this point in the history
Add observers to the JavaScript code to detect lab size changes
and send the new dimensions to the guacamole client.
  • Loading branch information
Maari Tamm committed Feb 3, 2025
1 parent 5b36637 commit 30746dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions hastexo/public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ function HastexoGuacamoleClient(configuration) {

onidle(pause) {
return pause;
},

sendSize(height, width) {
guac_client.sendSize(height, width);
}
}

Expand Down
9 changes: 9 additions & 0 deletions hastexo/public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ function HastexoXBlock(runtime, element, configuration) {
/* Show the terminal. */
$("#terminal").append(terminal_element);

// Observe the lab size in the browser and adjust when necessary
var lab = $('#terminal')[0];
const resizeObserver = new ResizeObserver(entries => {
for (const entry of entries) {
terminal_client.sendSize(entry.contentRect.width, entry.contentRect.height);
}
});
resizeObserver.observe(lab);

/* Disconnect on tab close. */
window.onunload = function() {
terminal_client.disconnect();
Expand Down
15 changes: 9 additions & 6 deletions hastexo/static/html/lab.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
terminal_element = terminal_client.getDisplay().getElement();
display.appendChild(terminal_element);

// Observe the lab size in the browser and adjust when necessary
var lab = document.getElementById('terminal');
const resizeObserver = new ResizeObserver(entries => {
for (const entry of entries) {
terminal_client.sendSize(entry.contentRect.width, entry.contentRect.height);
}
});
resizeObserver.observe(lab);

// Error handler
terminal_client.onerror = function(error) {
alert(error.message);
Expand Down Expand Up @@ -73,12 +82,6 @@
}
}

// reload the window on resize to reconnect with new
// height and width.
window.onresize = function() {
location.reload();
}

/* Disconnect on tab close. */
window.onunload = function() {
terminal_client.disconnect();
Expand Down

0 comments on commit 30746dd

Please sign in to comment.