import React,{ useCallback,useEffect,useMemo,useState } from 'react'; import { useIsVaultActive } from './application/state/activeTabStore'; import { useSessionState } from './application/state/useSessionState'; import { useSettingsState } from './application/state/useSettingsState'; import { useVaultState } from './application/state/useVaultState'; import ProtocolSelectDialog from './components/ProtocolSelectDialog'; import { QuickSwitcher } from './components/QuickSwitcher'; import SettingsDialog from './components/SettingsDialog'; import { SftpView } from './components/SftpView'; import { TerminalLayer } from './components/TerminalLayer'; import { TopTabs } from './components/TopTabs'; import { Button } from './components/ui/button'; import { Dialog,DialogContent,DialogFooter,DialogHeader,DialogTitle } from './components/ui/dialog'; import { Input } from './components/ui/input'; import { Label } from './components/ui/label'; import { ToastProvider } from './components/ui/toast'; import { VaultView } from './components/VaultView'; import { cn } from './lib/utils'; import { Host,HostProtocol } from './types'; // Visibility container for VaultView - isolates isActive subscription const VaultViewContainer: React.FC<{ children: React.ReactNode }> = ({ children }) => { const isActive = useIsVaultActive(); const containerStyle: React.CSSProperties = isActive ? {} : { visibility: 'hidden', pointerEvents: 'none', position: 'absolute', zIndex: -1 }; return (
{children}
); }; function App() { console.log('[App] render'); const [isSettingsOpen, setIsSettingsOpen] = useState(false); const [isQuickSwitcherOpen, setIsQuickSwitcherOpen] = useState(false); const [quickSearch, setQuickSearch] = useState(''); // Protocol selection dialog state for QuickSwitcher const [protocolSelectHost, setProtocolSelectHost] = useState(null); const { theme, setTheme, primaryColor, setPrimaryColor, syncConfig, updateSyncConfig, terminalThemeId, setTerminalThemeId, currentTerminalTheme, } = useSettingsState(); const { hosts, keys, snippets, customGroups, snippetPackages, knownHosts, shellHistory, updateHosts, updateKeys, updateSnippets, updateSnippetPackages, updateCustomGroups, updateKnownHosts, addShellHistoryEntry, updateHostDistro, convertKnownHostToHost, exportData, importDataFromString, } = useVaultState(); const { sessions, workspaces, setActiveTabId, draggingSessionId, setDraggingSessionId, workspaceRenameTarget, workspaceRenameValue, setWorkspaceRenameValue, startWorkspaceRename, submitWorkspaceRename, resetWorkspaceRename, createLocalTerminal, connectToHost, closeSession, closeWorkspace, updateSessionStatus, createWorkspaceFromSessions, addSessionToWorkspace, updateSplitSizes, toggleWorkspaceViewMode, setWorkspaceFocusedSession, runSnippet, orphanSessions, orderedTabs, reorderTabs, } = useSessionState(); // isMacClient is used for window controls styling const isMacClient = typeof navigator !== 'undefined' && /Mac|Macintosh/.test(navigator.userAgent); useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape' && isQuickSwitcherOpen) { setIsQuickSwitcherOpen(false); } }; window.addEventListener('keydown', onKeyDown); return () => window.removeEventListener('keydown', onKeyDown); }, [isQuickSwitcherOpen]); const quickResults = useMemo(() => { const term = quickSearch.trim().toLowerCase(); const filtered = term ? hosts.filter(h => h.label.toLowerCase().includes(term) || h.hostname.toLowerCase().includes(term) || (h.group || '').toLowerCase().includes(term) ) : hosts; return filtered.slice(0, 8); }, [hosts, quickSearch]); const handleDeleteHost = useCallback((hostId: string) => { const target = hosts.find(h => h.id === hostId); const confirmed = window.confirm(`Delete host "${target?.label || hostId}"?`); if (!confirmed) return; updateHosts(hosts.filter(h => h.id !== hostId)); }, [hosts, updateHosts]); // Check if host has multiple protocols enabled const hasMultipleProtocols = useCallback((host: Host) => { let count = 0; // SSH is always available as base protocol (unless explicitly set to something else) if (host.protocol === 'ssh' || !host.protocol) count++; // Mosh adds another option if (host.moshEnabled) count++; // Telnet adds another option if (host.telnetEnabled) count++; // If protocol is explicitly telnet (not ssh), count it if (host.protocol === 'telnet' && !host.telnetEnabled) count++; return count > 1; }, []); // Handle host connect with protocol selection (used by QuickSwitcher) const handleHostConnectWithProtocolCheck = useCallback((host: Host) => { if (hasMultipleProtocols(host)) { setProtocolSelectHost(host); setIsQuickSwitcherOpen(false); setQuickSearch(''); } else { connectToHost(host); setIsQuickSwitcherOpen(false); setQuickSearch(''); } }, [hasMultipleProtocols, connectToHost]); // Handle protocol selection from dialog const handleProtocolSelect = useCallback((protocol: HostProtocol, port: number) => { if (protocolSelectHost) { const hostWithProtocol: Host = { ...protocolSelectHost, protocol: protocol === 'mosh' ? 'ssh' : protocol, port, moshEnabled: protocol === 'mosh', }; connectToHost(hostWithProtocol); setProtocolSelectHost(null); } }, [protocolSelectHost, connectToHost]); const handleToggleTheme = useCallback(() => { setTheme(prev => prev === 'dark' ? 'light' : 'dark'); }, [setTheme]); const handleOpenQuickSwitcher = useCallback(() => { setIsQuickSwitcherOpen(true); }, []); const handleOpenSettings = useCallback(() => { setIsSettingsOpen(true); }, []); const handleEndSessionDrag = useCallback(() => { setDraggingSessionId(null); }, [setDraggingSessionId]); return (
e.preventDefault()}>
updateHosts(hosts.map(h => h.id === host.id ? host : h))} onAddKnownHost={(kh) => updateKnownHosts([...knownHosts, kh])} onCommandExecuted={(command, hostId, hostLabel, sessionId) => { addShellHistoryEntry({ command, hostId, hostLabel, sessionId }); }} onCreateWorkspaceFromSessions={createWorkspaceFromSessions} onAddSessionToWorkspace={addSessionToWorkspace} onUpdateSplitSizes={updateSplitSizes} onSetDraggingSessionId={setDraggingSessionId} onToggleWorkspaceViewMode={toggleWorkspaceViewMode} onSetWorkspaceFocusedSession={setWorkspaceFocusedSession} />
{ setActiveTabId(tabId); setIsQuickSwitcherOpen(false); setQuickSearch(''); }} onCreateLocalTerminal={() => { createLocalTerminal(); setIsQuickSwitcherOpen(false); setQuickSearch(''); }} onCreateWorkspace={() => { // TODO: Implement workspace creation setIsQuickSwitcherOpen(false); }} onClose={() => { setIsQuickSwitcherOpen(false); setQuickSearch(''); }} /> { if (!open) { resetWorkspaceRename(); } }}> Rename workspace
setWorkspaceRenameValue(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') submitWorkspaceRename(); }} autoFocus placeholder="Workspace name" />
setIsSettingsOpen(false)} onImport={importDataFromString} exportData={exportData} theme={theme} onThemeChange={setTheme} primaryColor={primaryColor} onPrimaryColorChange={setPrimaryColor} syncConfig={syncConfig} onSyncConfigChange={updateSyncConfig} terminalThemeId={terminalThemeId} onTerminalThemeChange={setTerminalThemeId} /> {/* Protocol Select Dialog for QuickSwitcher */} {protocolSelectHost && ( setProtocolSelectHost(null)} /> )}
); } function AppWithProviders() { return ( ); } export default AppWithProviders;