mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-25 09:51:28 +00:00
feat: Implement custom window controls and theme management for Electron app
This commit is contained in:
7 files changed
+243
-23
No files matched your search
+64
-7
@@ -251,24 +251,49 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
}
|
||||
}, [fontSize, terminalTheme, isVisible]);
|
||||
|
||||
// Debounced fit for resize operations - wait until resize ends
|
||||
useEffect(() => {
|
||||
if (!containerRef.current || !fitAddonRef.current) return;
|
||||
|
||||
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
safeFit();
|
||||
// Clear previous timeout
|
||||
if (resizeTimeout) {
|
||||
clearTimeout(resizeTimeout);
|
||||
}
|
||||
// Wait 150ms after last resize event before fitting
|
||||
resizeTimeout = setTimeout(() => {
|
||||
safeFit();
|
||||
}, 150);
|
||||
});
|
||||
|
||||
observer.observe(containerRef.current);
|
||||
return () => observer.disconnect();
|
||||
return () => {
|
||||
if (resizeTimeout) clearTimeout(resizeTimeout);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [isVisible]);
|
||||
|
||||
useEffect(() => {
|
||||
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const handler = () => {
|
||||
// Defer slightly to allow layout to settle after window resize.
|
||||
requestAnimationFrame(() => safeFit());
|
||||
// Clear previous timeout
|
||||
if (resizeTimeout) {
|
||||
clearTimeout(resizeTimeout);
|
||||
}
|
||||
// Wait 150ms after last resize event before fitting
|
||||
resizeTimeout = setTimeout(() => {
|
||||
safeFit();
|
||||
}, 150);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handler);
|
||||
return () => window.removeEventListener('resize', handler);
|
||||
return () => {
|
||||
if (resizeTimeout) clearTimeout(resizeTimeout);
|
||||
window.removeEventListener('resize', handler);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const startSSH = async (term: GhosttyTerminal) => {
|
||||
@@ -310,7 +335,23 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
|
||||
disposeDataRef.current = window.nebula.onSessionData(id, (chunk) => {
|
||||
term.write(chunk);
|
||||
if (!hasConnectedRef.current) updateStatus('connected');
|
||||
if (!hasConnectedRef.current) {
|
||||
updateStatus('connected');
|
||||
// Trigger fit after connection to ensure proper terminal size
|
||||
setTimeout(() => {
|
||||
if (fitAddonRef.current) {
|
||||
try {
|
||||
fitAddonRef.current.fit();
|
||||
// Send updated size to remote
|
||||
if (sessionRef.current && window.nebula?.resizeSession) {
|
||||
window.nebula.resizeSession(sessionRef.current, term.cols, term.rows);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Post-connect fit failed", err);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
|
||||
disposeExitRef.current = window.nebula.onSessionExit(id, (evt) => {
|
||||
@@ -362,7 +403,23 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
sessionRef.current = id;
|
||||
disposeDataRef.current = window.nebula?.onSessionData(id, (chunk) => {
|
||||
term.write(chunk);
|
||||
if (!hasConnectedRef.current) updateStatus('connected');
|
||||
if (!hasConnectedRef.current) {
|
||||
updateStatus('connected');
|
||||
// Trigger fit after connection to ensure proper terminal size
|
||||
setTimeout(() => {
|
||||
if (fitAddonRef.current) {
|
||||
try {
|
||||
fitAddonRef.current.fit();
|
||||
// Send updated size to remote
|
||||
if (sessionRef.current && window.nebula?.resizeSession) {
|
||||
window.nebula.resizeSession(sessionRef.current, term.cols, term.rows);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Post-connect fit failed", err);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
disposeExitRef.current = window.nebula?.onSessionExit(id, (evt) => {
|
||||
updateStatus('disconnected');
|
||||
|
||||
+67
-2
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { TerminalSquare, Shield, Folder, LayoutGrid, Plus, Bell, User, Sun, Moon, X } from 'lucide-react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { TerminalSquare, Shield, Folder, LayoutGrid, Plus, Bell, User, Sun, Moon, X, Minus, Square, Copy } from 'lucide-react';
|
||||
import { TerminalSession, Workspace } from '../types';
|
||||
import { Button } from './ui/button';
|
||||
import { cn } from '../lib/utils';
|
||||
@@ -34,6 +34,68 @@ const sessionStatusDot = (status: TerminalSession['status']) => {
|
||||
return <span className={cn("inline-block h-2 w-2 rounded-full shadow-[0_0_0_2px_rgba(0,0,0,0.35)]", tone)} />;
|
||||
};
|
||||
|
||||
// Custom window controls for Windows/Linux (frameless window)
|
||||
const WindowControls: React.FC = () => {
|
||||
const [isMaximized, setIsMaximized] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Check initial maximized state
|
||||
window.nebula?.windowIsMaximized?.().then(setIsMaximized);
|
||||
|
||||
// Listen for window resize to update maximized state
|
||||
const handleResize = () => {
|
||||
window.nebula?.windowIsMaximized?.().then(setIsMaximized);
|
||||
};
|
||||
window.addEventListener('resize', handleResize);
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, []);
|
||||
|
||||
const handleMinimize = () => {
|
||||
window.nebula?.windowMinimize?.();
|
||||
};
|
||||
|
||||
const handleMaximize = async () => {
|
||||
const result = await window.nebula?.windowMaximize?.();
|
||||
setIsMaximized(result ?? false);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
window.nebula?.windowClose?.();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center app-no-drag">
|
||||
<button
|
||||
onClick={handleMinimize}
|
||||
className="h-10 w-12 flex items-center justify-center text-muted-foreground hover:bg-foreground/10 hover:text-foreground transition-all duration-150"
|
||||
title="Minimize"
|
||||
>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={handleMaximize}
|
||||
className="h-10 w-12 flex items-center justify-center text-muted-foreground hover:bg-foreground/10 hover:text-foreground transition-all duration-150"
|
||||
title={isMaximized ? "Restore" : "Maximize"}
|
||||
>
|
||||
{isMaximized ? (
|
||||
// Restore icon (two overlapping squares)
|
||||
<Copy size={14} />
|
||||
) : (
|
||||
// Maximize icon (single square)
|
||||
<Square size={14} />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="h-10 w-12 flex items-center justify-center text-muted-foreground hover:bg-red-500 hover:text-white transition-all duration-150"
|
||||
title="Close"
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const TopTabs: React.FC<TopTabsProps> = ({
|
||||
theme,
|
||||
isVaultActive,
|
||||
@@ -167,7 +229,10 @@ export const TopTabs: React.FC<TopTabsProps> = ({
|
||||
{theme === 'dark' ? <Sun size={16} /> : <Moon size={16} />}
|
||||
</Button>
|
||||
</div>
|
||||
{/* Custom window controls for Windows/Linux */}
|
||||
{!isMacClient && <WindowControls />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user