-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adds fullscreen option to Desktop view #68
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
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aspect ratio of the desktop is changed once you exit fullscreen
Thanks for adding the fullscreen feature! I've reviewed the code and found a few issues that need to be addressed:
document.addEventListener('fullscreenchange', handleFullscreenChange);
// In the component: These changes should resolve the aspect ratio issues when exiting fullscreen mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to suggest a CSS transform-based solution for the desktop container's fullscreen functionality. Here's the implementation:
export const DesktopContainer: React.FC<DesktopContainerProps> = ({
children,
className = "",
status = "running",
}) => {
const vncContainerRef = useRef<HTMLDivElement>(null);
const [isFullscreen, setIsFullscreen] = useState(false);
useEffect(() => {
const handleFullscreenChange = () => {
setIsFullscreen(!!document.fullscreenElement);
};
document.addEventListener("fullscreenchange", handleFullscreenChange);
return () => {
document.removeEventListener("fullscreenchange", handleFullscreenChange);
};
}, []);
const handleFullScreen = async () => {
if (!vncContainerRef.current) return;
try {
if (!document.fullscreenElement) {
await vncContainerRef.current.requestFullscreen();
} else {
await document.exitFullscreen();
}
} catch (err) {
console.error("Fullscreen error:", err);
}
};
return (
<div className={cn(
"border-bytebot-bronze-light-7 flex w-full flex-col rounded-t-lg border-t border-r border-l",
className
)}>
{/* Header */}
<div className="flex items-center justify-between p-2 bg-gray-50">
{/* Status */}
<div className="flex items-center gap-2">
<div className={cn("h-2 w-2 rounded-full", {
"bg-green-500": status === "running",
"bg-yellow-500": status === "starting",
"bg-red-500": status === "error" || status === "stopped",
})} />
<span className="text-sm capitalize">{status}</span>
</div>
{/* Actions */}
<div className="flex items-center gap-2">
{children}
<button
onClick={handleFullScreen}
className={cn(
"px-4 py-2 rounded font-medium transition-colors",
"bg-gray-200 hover:bg-gray-300 text-gray-800",
"focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
)}
>
{isFullscreen ? "Exit Fullscreen" : "Fullscreen"}
</button>
</div>
</div>
{/* VNC Container */}
<div
ref={vncContainerRef}
className={cn(
"relative overflow-hidden bg-gray-900",
{
"h-[75vh]": !isFullscreen,
"fixed inset-0 z-50": isFullscreen
}
)}
>
{/* VNC Screen */}
<div className={cn(
"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",
"w-full h-full max-w-full max-h-full",
"transition-all duration-200 ease-in-out",
{
"aspect-[4/3] w-auto": !isFullscreen,
"w-screen h-screen": isFullscreen
}
)}>
{status === "running" && children}
</div>
</div>
</div>
);
};
Key improvements:
- Uses CSS transforms for reliable centering
- Maintains aspect ratio using CSS properties
- Adds smooth transitions between states
- Improves fullscreen handling with fixed positioning
- Cleans up component structure
This solution provides better reliability and maintainability while preserving the desired functionality.
adds a fullscreen option for vnc.