feat: sidebar saves state across mobile swtich, guacd hosts not migraitng passwords, terminal wrong size

This commit is contained in:
LukeGus
2026-05-26 17:48:19 -05:00
parent 5c2c9c179e
commit 0fe3f8d126
5 changed files with 75 additions and 125 deletions
+3
View File
@@ -1587,11 +1587,14 @@ router.get(
vncPort: hosts.vncPort, vncPort: hosts.vncPort,
telnetPort: hosts.telnetPort, telnetPort: hosts.telnetPort,
rdpUser: hosts.rdpUser, rdpUser: hosts.rdpUser,
rdpPassword: hosts.rdpPassword,
rdpDomain: hosts.rdpDomain, rdpDomain: hosts.rdpDomain,
rdpSecurity: hosts.rdpSecurity, rdpSecurity: hosts.rdpSecurity,
rdpIgnoreCert: hosts.rdpIgnoreCert, rdpIgnoreCert: hosts.rdpIgnoreCert,
vncUser: hosts.vncUser, vncUser: hosts.vncUser,
vncPassword: hosts.vncPassword,
telnetUser: hosts.telnetUser, telnetUser: hosts.telnetUser,
telnetPassword: hosts.telnetPassword,
ownerId: hosts.userId, ownerId: hosts.userId,
isShared: sql<boolean>`${hostAccess.id} IS NOT NULL AND ${hosts.userId} != ${userId}`, isShared: sql<boolean>`${hostAccess.id} IS NOT NULL AND ${hosts.userId} != ${userId}`,
+7 -2
View File
@@ -146,9 +146,14 @@ export function AppShell({
const isMobile = useIsMobile(); const isMobile = useIsMobile();
// Close the sidebar when switching to mobile (it becomes a sheet overlay) const sidebarOpenBeforeMobile = useRef(sidebarOpen);
useEffect(() => { useEffect(() => {
if (isMobile) setSidebarOpen(false); if (isMobile) {
sidebarOpenBeforeMobile.current = sidebarOpen;
setSidebarOpen(false);
} else {
setSidebarOpen(sidebarOpenBeforeMobile.current);
}
}, [isMobile]); }, [isMobile]);
useEffect(() => { useEffect(() => {
+8 -18
View File
@@ -2015,14 +2015,14 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
}); });
fitAddonRef.current?.fit(); fitAddonRef.current?.fit();
if (terminal.cols < 10 || terminal.rows < 3) { // Double-rAF ensures layout is fully settled (fonts, flexbox, etc.) before
// committing the fitted size, preventing the "terminal too short" glitch.
requestAnimationFrame(() => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
fitAddonRef.current?.fit(); fitAddonRef.current?.fit();
setIsFitted(true); setIsFitted(true);
}); });
} else { });
setIsFitted(true);
}
const element = xtermRef.current; const element = xtermRef.current;
const handleContextMenu = (e: MouseEvent) => { const handleContextMenu = (e: MouseEvent) => {
@@ -2475,26 +2475,16 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
return; return;
} }
if (terminal.cols < 10 || terminal.rows < 3) {
requestAnimationFrame(() => {
if (terminal.cols > 0 && terminal.rows > 0) {
setIsConnecting(true); setIsConnecting(true);
fitAddonRef.current?.fit(); fitAddonRef.current?.fit();
requestAnimationFrame(() => {
requestAnimationFrame(() => {
fitAddonRef.current?.fit();
if (terminal.cols > 0 && terminal.rows > 0) {
scheduleNotify(terminal.cols, terminal.rows); scheduleNotify(terminal.cols, terminal.rows);
connectToHost(terminal.cols, terminal.rows); connectToHost(terminal.cols, terminal.rows);
} }
}); });
return;
}
setIsConnecting(true);
fitAddonRef.current?.fit();
requestAnimationFrame(() => {
fitAddonRef.current?.fit();
if (terminal.cols > 0 && terminal.rows > 0) {
scheduleNotify(terminal.cols, terminal.rows);
connectToHost(terminal.cols, terminal.rows);
}
}); });
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [terminal, hostConfig.id, isVisible, isConnected, isConnecting]); }, [terminal, hostConfig.id, isVisible, isConnected, isConnecting]);
+1 -3
View File
@@ -94,15 +94,13 @@ export function HostShareModal({
return ( return (
<div className="absolute inset-0 z-20 flex flex-col bg-sidebar"> <div className="absolute inset-0 z-20 flex flex-col bg-sidebar">
{/* Header */} {/* Header */}
<div className="flex items-center gap-2 px-3 py-2 shrink-0 border-b border-border text-xs text-muted-foreground hover:text-foreground">
<button <button
onClick={onClose} onClick={onClose}
className="flex items-center gap-2 hover:text-foreground transition-colors" className="flex items-center gap-2 px-3 py-2 shrink-0 border-b border-border text-xs text-muted-foreground hover:text-foreground transition-colors w-full text-left"
> >
<ArrowLeft className="size-3.5 shrink-0" /> <ArrowLeft className="size-3.5 shrink-0" />
<span>{t("hosts.shareHostTitle", { name: host?.name ?? "" })}</span> <span>{t("hosts.shareHostTitle", { name: host?.name ?? "" })}</span>
</button> </button>
</div>
{/* Scrollable content */} {/* Scrollable content */}
<div className="flex flex-col flex-1 min-h-0 overflow-y-auto p-3 gap-3"> <div className="flex flex-col flex-1 min-h-0 overflow-y-auto p-3 gap-3">
+27 -73
View File
@@ -1,6 +1,5 @@
import { useRef, useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useVirtualizer } from "@tanstack/react-virtual";
import { import {
Box, Box,
Check, Check,
@@ -344,10 +343,9 @@ export function HostItem({
e.stopPropagation(); e.stopPropagation();
onOpenTab("rdp"); onOpenTab("rdp");
}} }}
className="flex items-center gap-1.5 px-2.5 h-6 rounded text-xs font-medium text-muted-foreground/70 hover:text-foreground hover:bg-muted-foreground/10 transition-colors border border-border/40" className="flex items-center justify-center size-7 rounded text-muted-foreground/50 hover:text-foreground hover:bg-muted-foreground/10 transition-colors"
> >
<Monitor className="size-3" /> <Monitor className="size-3.5" />
RDP
</button> </button>
)} )}
{host.enableVnc && ( {host.enableVnc && (
@@ -357,10 +355,9 @@ export function HostItem({
e.stopPropagation(); e.stopPropagation();
onOpenTab("vnc"); onOpenTab("vnc");
}} }}
className="flex items-center gap-1.5 px-2.5 h-6 rounded text-xs font-medium text-muted-foreground/70 hover:text-foreground hover:bg-muted-foreground/10 transition-colors border border-border/40" className="flex items-center justify-center size-7 rounded text-muted-foreground/50 hover:text-foreground hover:bg-muted-foreground/10 transition-colors"
> >
<Monitor className="size-3" /> <Monitor className="size-3.5" />
VNC
</button> </button>
)} )}
{host.enableTelnet && ( {host.enableTelnet && (
@@ -370,10 +367,9 @@ export function HostItem({
e.stopPropagation(); e.stopPropagation();
onOpenTab("telnet"); onOpenTab("telnet");
}} }}
className="flex items-center gap-1.5 px-2.5 h-6 rounded text-xs font-medium text-muted-foreground/70 hover:text-foreground hover:bg-muted-foreground/10 transition-colors border border-border/40" className="flex items-center justify-center size-7 rounded text-muted-foreground/50 hover:text-foreground hover:bg-muted-foreground/10 transition-colors"
> >
<Terminal className="size-3" /> <Terminal className="size-3.5" />
Telnet
</button> </button>
)} )}
{onEditHost && ( {onEditHost && (
@@ -582,7 +578,6 @@ export function HostItem({
export function FolderItem({ export function FolderItem({
folder, folder,
depth = 0, depth = 0,
flat = false,
onOpenTab, onOpenTab,
onEditHost, onEditHost,
onShareHost, onShareHost,
@@ -600,7 +595,6 @@ export function FolderItem({
}: { }: {
folder: HostFolder; folder: HostFolder;
depth?: number; depth?: number;
flat?: boolean;
onOpenTab: (host: Host, type: TabType) => void; onOpenTab: (host: Host, type: TabType) => void;
onEditHost?: (host: Host) => void; onEditHost?: (host: Host) => void;
onShareHost?: (host: Host) => void; onShareHost?: (host: Host) => void;
@@ -645,8 +639,7 @@ export function FolderItem({
<span className="text-muted-foreground/40">/{total}</span> <span className="text-muted-foreground/40">/{total}</span>
</span> </span>
</button> </button>
{/* Children are rendered as separate virtual rows when flat=true */} {isOpen && (
{!flat && isOpen && (
<div className="border-l border-border/40 ml-[30px]"> <div className="border-l border-border/40 ml-[30px]">
{folder.children.map((child, i) => {folder.children.map((child, i) =>
isFolder(child) ? ( isFolder(child) ? (
@@ -716,7 +709,6 @@ export function SidebarTree({
loading?: boolean; loading?: boolean;
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const scrollRef = useRef<HTMLDivElement>(null);
const [openFolders, setOpenFolders] = useState<Set<string>>(new Set()); const [openFolders, setOpenFolders] = useState<Set<string>>(new Set());
const [selectedHostIds, setSelectedHostIds] = useState<Set<string>>( const [selectedHostIds, setSelectedHostIds] = useState<Set<string>>(
new Set(), new Set(),
@@ -790,13 +782,6 @@ export function SidebarTree({
visibleRows.map((r, i) => [r.item, i]), visibleRows.map((r, i) => [r.item, i]),
); );
const virtualizer = useVirtualizer({
count: visibleRows.length,
getScrollElement: () => scrollRef.current,
estimateSize: () => 52,
overscan: 8,
});
if (loading) { if (loading) {
return ( return (
<div className="relative flex flex-col flex-1 min-h-0"> <div className="relative flex flex-col flex-1 min-h-0">
@@ -824,7 +809,7 @@ export function SidebarTree({
return ( return (
<div className="relative flex flex-col flex-1 min-h-0"> <div className="relative flex flex-col flex-1 min-h-0">
<div className="flex-1 min-h-0 overflow-y-auto" ref={scrollRef}> <div className="flex-1 min-h-0 overflow-y-auto">
{visibleRows.length === 0 ? ( {visibleRows.length === 0 ? (
<div className="flex flex-col items-center justify-center py-12 text-center px-4"> <div className="flex flex-col items-center justify-center py-12 text-center px-4">
<Server className="size-8 text-muted-foreground/20 mb-2" /> <Server className="size-8 text-muted-foreground/20 mb-2" />
@@ -833,37 +818,11 @@ export function SidebarTree({
</span> </span>
</div> </div>
) : ( ) : (
<div children.map((child, i) =>
style={{ isFolder(child) ? (
height: `${virtualizer.getTotalSize()}px`,
position: "relative",
}}
>
{virtualizer.getVirtualItems().map((vItem) => {
const { item, depth } = visibleRows[vItem.index];
const stripeIndex = stripeMap.get(item) ?? 0;
const indentPx = depth * 16;
return (
<div
key={vItem.key}
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
transform: `translateY(${vItem.start}px)`,
}}
>
<div
style={
depth > 0 ? { paddingLeft: `${indentPx}px` } : undefined
}
>
{isFolder(item) ? (
<FolderItem <FolderItem
folder={item} key={i}
flat={true} folder={child}
depth={depth}
onOpenTab={onOpenTab} onOpenTab={onOpenTab}
onEditHost={onEditHost} onEditHost={onEditHost}
onShareHost={onShareHost} onShareHost={onShareHost}
@@ -881,30 +840,25 @@ export function SidebarTree({
/> />
) : ( ) : (
<HostItem <HostItem
host={item} key={i}
onOpenTab={(type) => onOpenTab(item, type)} host={child}
onEditHost={() => onEditHost(item)} onOpenTab={(type) => onOpenTab(child, type)}
onShareHost={ onEditHost={() => onEditHost(child)}
onShareHost ? () => onShareHost(item) : undefined onShareHost={onShareHost ? () => onShareHost(child) : undefined}
} onDelete={() => handleDeleteHost(child)}
onDelete={() => handleDeleteHost(item)} onDuplicate={() => handleDuplicateHost(child)}
onDuplicate={() => handleDuplicateHost(item)}
query={query} query={query}
stripeIndex={stripeIndex} stripeIndex={stripeMap.get(child) ?? 0}
selectionMode={selectionMode} selectionMode={selectionMode}
selected={selectedHostIds.has(item.id)} selected={selectedHostIds.has(child.id)}
onToggleSelect={() => toggleSelect(item.id)} onToggleSelect={() => toggleSelect(child.id)}
isMenuOpen={openMenuHostId === item.id} isMenuOpen={openMenuHostId === child.id}
onMenuOpenChange={(open) => onMenuOpenChange={(open) =>
setOpenMenuHostId(open ? item.id : null) setOpenMenuHostId(open ? child.id : null)
} }
/> />
)} ),
</div> )
</div>
);
})}
</div>
)} )}
</div> </div>