mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
Adds workspace broadcast mode with hotkey toggle
Implements a broadcast mode that lets users send terminal input to all sessions within a workspace. Introduces a hotkey to toggle broadcast for the active workspace and a UI indicator/button in the terminal header. Removes the unused side panel hotkey action. Updates tab navigation logic to accommodate new sections. Enables more efficient multi-session workflows by allowing synchronized input across terminals.
This commit is contained in:
1 parent
20843c0379
commit
a0f244b56b
7 files changed
+129
-26
No files matched your search
@@ -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<Host | null>(null);
|
||||
// Navigation state for VaultView sections
|
||||
const [navigateToSection, setNavigateToSection] = useState<VaultSection | null>(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)}
|
||||
/>
|
||||
</VaultViewContainer>
|
||||
|
||||
@@ -498,6 +507,8 @@ function App() {
|
||||
onToggleWorkspaceViewMode={toggleWorkspaceViewMode}
|
||||
onSetWorkspaceFocusedSession={setWorkspaceFocusedSession}
|
||||
onSplitSession={splitSession}
|
||||
isBroadcastEnabled={isBroadcastEnabled}
|
||||
onToggleBroadcast={toggleBroadcast}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ export interface HotkeyActions {
|
||||
|
||||
// App features
|
||||
broadcast: () => void;
|
||||
sidePanel: () => void;
|
||||
openLocal: () => void;
|
||||
}
|
||||
|
||||
@@ -69,7 +68,6 @@ export const getAppLevelActions = (): Set<string> => {
|
||||
'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]);
|
||||
|
||||
|
||||
@@ -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<string[]>([]);
|
||||
// Broadcast mode: stores workspace IDs that have broadcast enabled
|
||||
const [broadcastWorkspaceIds, setBroadcastWorkspaceIds] = useState<Set<string>>(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,
|
||||
};
|
||||
|
||||
+36
-1
@@ -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<TerminalProps> = ({
|
||||
onCommandExecuted,
|
||||
onSplitHorizontal,
|
||||
onSplitVertical,
|
||||
isBroadcastEnabled,
|
||||
onToggleBroadcast,
|
||||
onBroadcastInput,
|
||||
}) => {
|
||||
const CONNECTION_TIMEOUT = 12000;
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
@@ -150,6 +157,12 @@ const TerminalComponent: React.FC<TerminalProps> = ({
|
||||
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<TerminalProps> = ({
|
||||
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<TerminalProps> = ({
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-0.5 flex-shrink-0">
|
||||
{/* Broadcast button - only show in workspace mode */}
|
||||
{inWorkspace && onToggleBroadcast && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className={cn(
|
||||
"h-6 w-6 p-0 hover:bg-white/10",
|
||||
isBroadcastEnabled
|
||||
? "text-emerald-400 hover:text-emerald-300"
|
||||
: "text-white/70 hover:text-white"
|
||||
)}
|
||||
onClick={onToggleBroadcast}
|
||||
title={isBroadcastEnabled ? "Disable Broadcast Mode" : "Enable Broadcast Mode"}
|
||||
>
|
||||
<Radio size={12} />
|
||||
</Button>
|
||||
)}
|
||||
{/* Expand to focus mode button - only show in workspace split view mode */}
|
||||
{inWorkspace && !isFocusMode && onExpandToFocus && (
|
||||
<Button
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Circle, LayoutGrid, Server } from 'lucide-react';
|
||||
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useActiveTabId } from '../application/state/activeTabStore';
|
||||
import { useTerminalBackend } from '../application/state/useTerminalBackend';
|
||||
import { collectSessionIds } from '../domain/workspace';
|
||||
import { SplitDirection } from '../domain/workspace';
|
||||
import { KeyBinding, TerminalSettings } from '../domain/models';
|
||||
@@ -56,6 +57,9 @@ interface TerminalLayerProps {
|
||||
onToggleWorkspaceViewMode?: (workspaceId: string) => void;
|
||||
onSetWorkspaceFocusedSession?: (workspaceId: string, sessionId: string) => void;
|
||||
onSplitSession?: (sessionId: string, direction: SplitDirection) => void;
|
||||
// Broadcast mode
|
||||
isBroadcastEnabled?: (workspaceId: string) => boolean;
|
||||
onToggleBroadcast?: (workspaceId: string) => void;
|
||||
}
|
||||
|
||||
const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
@@ -85,6 +89,8 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
onToggleWorkspaceViewMode,
|
||||
onSetWorkspaceFocusedSession,
|
||||
onSplitSession,
|
||||
isBroadcastEnabled,
|
||||
onToggleBroadcast,
|
||||
}) => {
|
||||
// Subscribe to activeTabId from external store
|
||||
const activeTabId = useActiveTabId();
|
||||
@@ -121,6 +127,9 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
onCommandExecuted?.(command, hostId, hostLabel, sessionId);
|
||||
}, [onCommandExecuted]);
|
||||
|
||||
// Terminal backend for broadcast writes
|
||||
const terminalBackend = useTerminalBackend();
|
||||
|
||||
const [workspaceArea, setWorkspaceArea] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
|
||||
const workspaceOuterRef = useRef<HTMLDivElement>(null);
|
||||
const workspaceInnerRef = useRef<HTMLDivElement>(null);
|
||||
@@ -139,6 +148,21 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
const activeWorkspace = useMemo(() => workspaces.find(w => w.id === activeTabId), [workspaces, activeTabId]);
|
||||
const activeSession = useMemo(() => sessions.find(s => s.id === activeTabId), [sessions, activeTabId]);
|
||||
|
||||
// Handle broadcast input - write to all other sessions in the same workspace
|
||||
const handleBroadcastInput = useCallback((data: string, sourceSessionId: string) => {
|
||||
if (!activeWorkspace) return;
|
||||
|
||||
// Get all session IDs in this workspace
|
||||
const workspaceSessionIds = sessions
|
||||
.filter(s => s.workspaceId === activeWorkspace.id && s.id !== sourceSessionId)
|
||||
.map(s => s.id);
|
||||
|
||||
// Write to all other sessions
|
||||
for (const targetSessionId of workspaceSessionIds) {
|
||||
terminalBackend.writeToSession(targetSessionId, data);
|
||||
}
|
||||
}, [activeWorkspace, sessions, terminalBackend]);
|
||||
|
||||
// Pre-compute host lookup map for O(1) access
|
||||
const hostMap = useMemo(() => {
|
||||
const map = new Map<string, Host>();
|
||||
@@ -645,6 +669,9 @@ const TerminalLayerInner: React.FC<TerminalLayerProps> = ({
|
||||
onExpandToFocus={inActiveWorkspace && !isFocusMode && activeWorkspace ? () => onToggleWorkspaceViewMode?.(activeWorkspace.id) : undefined}
|
||||
onSplitHorizontal={onSplitSession ? () => onSplitSession(session.id, 'horizontal') : undefined}
|
||||
onSplitVertical={onSplitSession ? () => onSplitSession(session.id, 'vertical') : undefined}
|
||||
isBroadcastEnabled={inActiveWorkspace && activeWorkspace ? isBroadcastEnabled?.(activeWorkspace.id) : false}
|
||||
onToggleBroadcast={inActiveWorkspace && activeWorkspace ? () => onToggleBroadcast?.(activeWorkspace.id) : undefined}
|
||||
onBroadcastInput={inActiveWorkspace && activeWorkspace && isBroadcastEnabled?.(activeWorkspace.id) ? handleBroadcastInput : undefined}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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<VaultViewProps> = ({
|
||||
@@ -113,6 +116,8 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
|
||||
onUpdateKnownHosts,
|
||||
onConvertKnownHost,
|
||||
onRunSnippet,
|
||||
navigateToSection,
|
||||
onNavigateToSectionHandled,
|
||||
}) => {
|
||||
const [currentSection, setCurrentSection] = useState<VaultSection>("hosts");
|
||||
const [search, setSearch] = useState("");
|
||||
@@ -123,6 +128,14 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
|
||||
const [newFolderName, setNewFolderName] = useState("");
|
||||
const [targetParentPath, setTargetParentPath] = useState<string | null>(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<SortMode>("az");
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user