Final preparations for release. Fixed auto resizing bug when smaller terminal size.
This commit is contained in:
@@ -6,6 +6,7 @@ import { CssVarsProvider } from "@mui/joy";
|
|||||||
import theme from "./theme";
|
import theme from "./theme";
|
||||||
import TabList from "./TabList.jsx";
|
import TabList from "./TabList.jsx";
|
||||||
import Launchpad from "./Launchpad.jsx";
|
import Launchpad from "./Launchpad.jsx";
|
||||||
|
import { Debounce } from './Utils';
|
||||||
import TermixIcon from "./images/termix_icon.png";
|
import TermixIcon from "./images/termix_icon.png";
|
||||||
import RocketIcon from './images/launchpad_rocket.png';
|
import RocketIcon from './images/launchpad_rocket.png';
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ function App() {
|
|||||||
}, [splitTabIds, activeTab, terminals]);
|
}, [splitTabIds, activeTab, terminals]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = () => {
|
const handleResize = Debounce(() => {
|
||||||
terminals.forEach((terminal) => {
|
terminals.forEach((terminal) => {
|
||||||
if (
|
if (
|
||||||
(terminal.id === activeTab || splitTabIds.includes(terminal.id)) &&
|
(terminal.id === activeTab || splitTabIds.includes(terminal.id)) &&
|
||||||
@@ -59,7 +60,7 @@ function App() {
|
|||||||
terminal.terminalRef.resizeTerminal();
|
terminal.terminalRef.resizeTerminal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}, 100);
|
||||||
|
|
||||||
window.addEventListener("resize", handleResize);
|
window.addEventListener("resize", handleResize);
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ function App() {
|
|||||||
setActiveTab(nextId);
|
setActiveTab(nextId);
|
||||||
setNextId(nextId + 1);
|
setNextId(nextId + 1);
|
||||||
setIsAddHostHidden(true);
|
setIsAddHostHidden(true);
|
||||||
setForm({ name: "", ip: "", user: "", password: "", rsaKey: "", port: 22, authMethod: "password" });
|
setForm({ name: "", ip: "", user: "", password: "", rsaKey: "", port: 22, authMethod: "Select Auth" });
|
||||||
} else {
|
} else {
|
||||||
alert("Please fill out all fields.");
|
alert("Please fill out all fields.");
|
||||||
}
|
}
|
||||||
@@ -198,7 +199,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Terminal Views */}
|
{/* Terminal Views */}
|
||||||
<div className={`relative p-4 ${getLayoutStyle()}`}>
|
<div className={`relative p-4 terminal-container ${getLayoutStyle()}`}>
|
||||||
{terminals.map((terminal) => (
|
{terminals.map((terminal) => (
|
||||||
<div
|
<div
|
||||||
key={terminal.id}
|
key={terminal.id}
|
||||||
|
|||||||
@@ -18,26 +18,20 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
|
|||||||
|
|
||||||
if (!parentContainer || !isVisible) return;
|
if (!parentContainer || !isVisible) return;
|
||||||
|
|
||||||
// Force a reflow to ensure the container's dimensions are up-to-date
|
|
||||||
void parentContainer.offsetHeight;
|
void parentContainer.offsetHeight;
|
||||||
|
|
||||||
// Use a small delay to ensure the DOM has fully updated
|
|
||||||
setTimeout(() => {
|
|
||||||
const parentWidth = parentContainer.clientWidth;
|
const parentWidth = parentContainer.clientWidth;
|
||||||
const parentHeight = parentContainer.clientHeight;
|
const parentHeight = parentContainer.clientHeight - 16;
|
||||||
|
|
||||||
terminalContainer.style.width = `${parentWidth}px`;
|
terminalContainer.style.width = `${parentWidth}px`;
|
||||||
terminalContainer.style.height = `${parentHeight}px`;
|
terminalContainer.style.height = `${parentHeight}px`;
|
||||||
|
|
||||||
// Fit the terminal to the container
|
|
||||||
fitAddon.current.fit();
|
fitAddon.current.fit();
|
||||||
|
|
||||||
// Notify the backend of the new terminal size
|
|
||||||
if (socketRef.current && terminalInstance.current) {
|
if (socketRef.current && terminalInstance.current) {
|
||||||
const { cols, rows } = terminalInstance.current;
|
const { cols, rows } = terminalInstance.current;
|
||||||
socketRef.current.emit("resize", { cols, rows });
|
socketRef.current.emit("resize", { cols, rows });
|
||||||
}
|
}
|
||||||
}, 10); // Small delay to ensure proper DOM updates
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
@@ -61,7 +55,6 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
terminalInstance.current.loadAddon(fitAddon.current);
|
terminalInstance.current.loadAddon(fitAddon.current);
|
||||||
|
|
||||||
terminalInstance.current.open(terminalRef.current);
|
terminalInstance.current.open(terminalRef.current);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -119,6 +112,21 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible }, ref) => {
|
|||||||
}
|
}
|
||||||
}, [isVisible]);
|
}, [isVisible]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const terminalContainer = terminalRef.current;
|
||||||
|
if (!terminalContainer) return;
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(() => {
|
||||||
|
resizeTerminal();
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(terminalContainer);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
observer.disconnect();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={terminalRef}
|
ref={terminalRef}
|
||||||
|
|||||||
7
src/Utils.jsx
Normal file
7
src/Utils.jsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export const Debounce = (func, wait) => {
|
||||||
|
let timeout;
|
||||||
|
return (...args) => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => func.apply(this, args), wait);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -8,3 +8,12 @@
|
|||||||
background-color: #4a5568;
|
background-color: #4a5568;
|
||||||
margin: 0 8px;
|
margin: 0 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.terminal-container {
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminal-container > div {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user