diff --git a/App.tsx b/App.tsx index b76d6903e..2bcea7a1b 100755 --- a/App.tsx +++ b/App.tsx @@ -16,7 +16,7 @@ import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from ' import { Input } from './components/ui/input'; import { Label } from './components/ui/label'; import { ToastProvider } from './components/ui/toast'; -import { VaultView } from './components/VaultView'; +import { VaultView, VaultSection } from './components/VaultView'; import { cn } from './lib/utils'; import { Host, HostProtocol } from './types'; @@ -42,6 +42,8 @@ function App() { const [quickSearch, setQuickSearch] = useState(''); // Protocol selection dialog state for QuickSwitcher const [protocolSelectHost, setProtocolSelectHost] = useState(null); + // Navigation state for VaultView sections + const [navigateToSection, setNavigateToSection] = useState(null); const { theme, @@ -121,6 +123,8 @@ function App() { orphanSessions, orderedTabs, reorderTabs, + toggleBroadcast, + isBroadcastEnabled, } = useSessionState(); // isMacClient is used for window controls styling @@ -137,8 +141,8 @@ function App() { // Get the number key pressed (1-9) const num = parseInt(e.key, 10); if (num >= 1 && num <= 9) { - // Build complete tab list: vault + sessions/workspaces - const allTabs = ['vault', ...orderedTabs]; + // Build complete tab list: vault + sftp + sessions/workspaces + const allTabs = ['vault', 'sftp', ...orderedTabs]; if (num <= allTabs.length) { setActiveTabId(allTabs[num - 1]); } @@ -146,8 +150,8 @@ function App() { break; } case 'nextTab': { - // Build complete tab list: vault + sessions/workspaces - const allTabs = ['vault', ...orderedTabs]; + // Build complete tab list: vault + sftp + sessions/workspaces + const allTabs = ['vault', 'sftp', ...orderedTabs]; const currentId = activeTabStore.getActiveTabId(); const currentIdx = allTabs.indexOf(currentId); if (currentIdx !== -1 && allTabs.length > 0) { @@ -159,8 +163,8 @@ function App() { break; } case 'prevTab': { - // Build complete tab list: vault + sessions/workspaces - const allTabs = ['vault', ...orderedTabs]; + // Build complete tab list: vault + sftp + sessions/workspaces + const allTabs = ['vault', 'sftp', ...orderedTabs]; const currentId = activeTabStore.getActiveTabId(); const currentIdx = allTabs.indexOf(currentId); if (currentIdx !== -1 && allTabs.length > 0) { @@ -202,21 +206,24 @@ function App() { setIsQuickSwitcherOpen(true); break; case 'portForwarding': - // Navigate to vault and could open port forwarding section + // Navigate to vault and open port forwarding section setActiveTabId('vault'); + setNavigateToSection('port'); break; case 'snippets': - // Navigate to vault + // Navigate to vault and open snippets section setActiveTabId('vault'); + setNavigateToSection('snippets'); break; - case 'broadcast': - // TODO: Implement broadcast mode toggle - console.log('[Hotkey] Broadcast mode toggle requested'); - break; - case 'sidePanel': - // TODO: Implement side panel toggle - console.log('[Hotkey] Side panel toggle requested'); + case 'broadcast': { + // Toggle broadcast mode for the active workspace + const currentId = activeTabStore.getActiveTabId(); + const activeWs = workspaces.find(w => w.id === currentId); + if (activeWs) { + toggleBroadcast(activeWs.id); + } break; + } case 'splitHorizontal': { // Split current terminal horizontally (top/bottom) const currentId = activeTabStore.getActiveTabId(); @@ -280,7 +287,7 @@ function App() { break; } } - }, [orderedTabs, sessions, workspaces, setActiveTabId, closeSession, closeWorkspace, createLocalTerminal, splitSession, moveFocusInWorkspace]); + }, [orderedTabs, sessions, workspaces, setActiveTabId, closeSession, closeWorkspace, createLocalTerminal, splitSession, moveFocusInWorkspace, toggleBroadcast]); // Callback for terminal to invoke app-level hotkey actions const handleHotkeyAction = useCallback((action: string, e: KeyboardEvent) => { @@ -464,6 +471,8 @@ function App() { onUpdateKnownHosts={updateKnownHosts} onConvertKnownHost={convertKnownHostToHost} onRunSnippet={runSnippet} + navigateToSection={navigateToSection} + onNavigateToSectionHandled={() => setNavigateToSection(null)} /> @@ -498,6 +507,8 @@ function App() { onToggleWorkspaceViewMode={toggleWorkspaceViewMode} onSetWorkspaceFocusedSession={setWorkspaceFocusedSession} onSplitSession={splitSession} + isBroadcastEnabled={isBroadcastEnabled} + onToggleBroadcast={toggleBroadcast} /> diff --git a/application/state/useGlobalHotkeys.ts b/application/state/useGlobalHotkeys.ts index 92c0629e3..6406e9bc5 100644 --- a/application/state/useGlobalHotkeys.ts +++ b/application/state/useGlobalHotkeys.ts @@ -31,7 +31,6 @@ export interface HotkeyActions { // App features broadcast: () => void; - sidePanel: () => void; openLocal: () => void; } @@ -69,7 +68,6 @@ export const getAppLevelActions = (): Set => { 'splitVertical', 'moveFocus', 'broadcast', - 'sidePanel', 'openLocal', ]); }; @@ -198,9 +196,6 @@ export const useGlobalHotkeys = ({ case 'broadcast': currentActions.broadcast?.(); break; - case 'sidePanel': - currentActions.sidePanel?.(); - break; } }, [hotkeyScheme, keyBindings, isSettingsOpen]); diff --git a/application/state/useSessionState.ts b/application/state/useSessionState.ts index ee34f4700..28dbc2681 100644 --- a/application/state/useSessionState.ts +++ b/application/state/useSessionState.ts @@ -24,6 +24,8 @@ export const useSessionState = () => { const [workspaceRenameValue, setWorkspaceRenameValue] = useState(''); // Tab order: stores ordered list of tab IDs (orphan session IDs and workspace IDs) const [tabOrder, setTabOrder] = useState([]); + // Broadcast mode: stores workspace IDs that have broadcast enabled + const [broadcastWorkspaceIds, setBroadcastWorkspaceIds] = useState>(new Set()); const createLocalTerminal = useCallback(() => { const sessionId = crypto.randomUUID(); @@ -419,6 +421,24 @@ export const useSessionState = () => { const orphanSessions = useMemo(() => sessions.filter(s => !s.workspaceId), [sessions]); + // Toggle broadcast mode for a workspace + const toggleBroadcast = useCallback((workspaceId: string) => { + setBroadcastWorkspaceIds(prev => { + const next = new Set(prev); + if (next.has(workspaceId)) { + next.delete(workspaceId); + } else { + next.add(workspaceId); + } + return next; + }); + }, []); + + // Check if a workspace has broadcast enabled + const isBroadcastEnabled = useCallback((workspaceId: string) => { + return broadcastWorkspaceIds.has(workspaceId); + }, [broadcastWorkspaceIds]); + // Get ordered tabs: combines orphan sessions and workspaces in the custom order const orderedTabs = useMemo(() => { const allTabIds = [ @@ -498,6 +518,9 @@ export const useSessionState = () => { moveFocusInWorkspace, runSnippet, orphanSessions, + // Broadcast mode + toggleBroadcast, + isBroadcastEnabled, orderedTabs, reorderTabs, }; diff --git a/components/Terminal.tsx b/components/Terminal.tsx index cfefa0ba7..298ef7554 100644 --- a/components/Terminal.tsx +++ b/components/Terminal.tsx @@ -5,7 +5,7 @@ import { SearchAddon } from "@xterm/addon-search"; import { WebglAddon } from "@xterm/addon-webgl"; import { WebLinksAddon } from "@xterm/addon-web-links"; import "@xterm/xterm/css/xterm.css"; -import { Maximize2 } from "lucide-react"; +import { Maximize2, Radio } from "lucide-react"; import React, { memo, useEffect, useMemo, useRef, useState, useCallback } from "react"; import { logger } from "../lib/logger"; import { cn } from "../lib/utils"; @@ -80,6 +80,10 @@ interface TerminalProps { // Split actions onSplitHorizontal?: () => void; onSplitVertical?: () => void; + // Broadcast mode + isBroadcastEnabled?: boolean; + onToggleBroadcast?: () => void; + onBroadcastInput?: (data: string, sourceSessionId: string) => void; } // xterm.js doesn't need async initialization like ghostty-web @@ -113,6 +117,9 @@ const TerminalComponent: React.FC = ({ onCommandExecuted, onSplitHorizontal, onSplitVertical, + isBroadcastEnabled, + onToggleBroadcast, + onBroadcastInput, }) => { const CONNECTION_TIMEOUT = 12000; const containerRef = useRef(null); @@ -150,6 +157,12 @@ const TerminalComponent: React.FC = ({ keyBindingsRef.current = keyBindings; onHotkeyActionRef.current = onHotkeyAction; + // Refs for broadcast mode (to avoid stale closures) + const isBroadcastEnabledRef = useRef(isBroadcastEnabled); + const onBroadcastInputRef = useRef(onBroadcastInput); + isBroadcastEnabledRef.current = isBroadcastEnabled; + onBroadcastInputRef.current = onBroadcastInput; + const terminalBackend = useTerminalBackend(); const { resizeSession } = terminalBackend; @@ -630,6 +643,11 @@ const TerminalComponent: React.FC = ({ if (id) { terminalBackend.writeToSession(id, data); + // Broadcast input to other terminals in the same workspace + if (isBroadcastEnabledRef.current && onBroadcastInputRef.current) { + onBroadcastInputRef.current(data, sessionId); + } + // Track command input for shell history if (status === "connected" && onCommandExecuted) { // Handle control characters @@ -1839,6 +1857,23 @@ const TerminalComponent: React.FC = ({ />
+ {/* Broadcast button - only show in workspace mode */} + {inWorkspace && onToggleBroadcast && ( + + )} {/* Expand to focus mode button - only show in workspace split view mode */} {inWorkspace && !isFocusMode && onExpandToFocus && (
); diff --git a/components/VaultView.tsx b/components/VaultView.tsx index 23110c815..58589774d 100644 --- a/components/VaultView.tsx +++ b/components/VaultView.tsx @@ -18,7 +18,7 @@ import { Upload, Zap, } from "lucide-react"; -import React, { memo, useCallback, useMemo, useState } from "react"; +import React, { memo, useCallback, useEffect, useMemo, useState } from "react"; import { sanitizeHost } from "../domain/host"; import { cn } from "../lib/utils"; import { @@ -64,7 +64,7 @@ import { Label } from "./ui/label"; import { SortDropdown, SortMode } from "./ui/sort-dropdown"; import { TagFilterDropdown } from "./ui/tag-filter-dropdown"; -type VaultSection = "hosts" | "keys" | "snippets" | "port" | "knownhosts"; +export type VaultSection = "hosts" | "keys" | "snippets" | "port" | "knownhosts"; // Props without isActive - it's now subscribed internally interface VaultViewProps { @@ -89,6 +89,9 @@ interface VaultViewProps { onUpdateKnownHosts: (knownHosts: KnownHost[]) => void; onConvertKnownHost: (knownHost: KnownHost) => void; onRunSnippet?: (snippet: Snippet, targetHosts: Host[]) => void; + // Optional: navigate to a specific section on mount or when changed + navigateToSection?: VaultSection | null; + onNavigateToSectionHandled?: () => void; } const VaultViewInner: React.FC = ({ @@ -113,6 +116,8 @@ const VaultViewInner: React.FC = ({ onUpdateKnownHosts, onConvertKnownHost, onRunSnippet, + navigateToSection, + onNavigateToSectionHandled, }) => { const [currentSection, setCurrentSection] = useState("hosts"); const [search, setSearch] = useState(""); @@ -123,6 +128,14 @@ const VaultViewInner: React.FC = ({ const [newFolderName, setNewFolderName] = useState(""); const [targetParentPath, setTargetParentPath] = useState(null); + // Handle external navigation requests + useEffect(() => { + if (navigateToSection) { + setCurrentSection(navigateToSection); + onNavigateToSectionHandled?.(); + } + }, [navigateToSection, onNavigateToSectionHandled]); + // View mode, sorting, and tag filter state const [viewMode, setViewMode] = useState<"grid" | "list">("grid"); const [sortMode, setSortMode] = useState("az"); diff --git a/domain/models.ts b/domain/models.ts index 761cbc740..3235cd847 100755 --- a/domain/models.ts +++ b/domain/models.ts @@ -304,7 +304,6 @@ export const DEFAULT_KEY_BINDINGS: KeyBinding[] = [ { id: 'quick-switch', action: 'quickSwitch', label: 'Quick Switch', mac: '⌘ + J', pc: 'Ctrl + J', category: 'app' }, { id: 'snippets', action: 'snippets', label: 'Open Snippets', mac: '⌘ + Shift + S', pc: 'Ctrl + Alt + S', category: 'app' }, { id: 'broadcast', action: 'broadcast', label: 'Switch the Broadcast Mode', mac: '⌘ + B', pc: 'Ctrl + B', category: 'app' }, - { id: 'side-panel', action: 'sidePanel', label: 'Show Terminal Side-panel', mac: '⌘ + S', pc: 'Ctrl + S', category: 'app' }, ]; // Terminal appearance settings