mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 00:50:44 +00:00
* Add local shell side panel auto-open settings with i18n support - Add settings to control side panel behavior for local shell sessions - Support auto-opening side panel when local shell is launched - Allow users to choose which pane (Files, SFTP, Scripts, etc.) opens by default - Add complete i18n translations for en, zh-CN, zh-TW, es, ru locales * fix: wire local shell side panel settings * fix: restore undefined check for local shell protocol detection Local shell sessions may have protocol=undefined, not just 'local'. Restore the original condition to auto-open sidebar for both cases. * fix: enable SFTP sidebar for local shell sessions Local shell now supports SFTP (for local file browsing). Update sftpAvailable to include local shell so the auto-open sidebar setting works correctly for PowerShell/bash sessions. * chore: bump version to 1.1.83-fork.1 Distinguish fork from upstream (1.1.83) and previous 0.0.0 dev version. * feat: show SFTP button in local shell toolbar Local shell sessions now display the 'Open SFTP' button in the toolbar, allowing users to browse local files via SFTP sidebar, consistent with the auto-open behavior added earlier. * feat: 本地Shell侧边栏支持追随终端目录功能 - 追随终端目录现在支持本地 POSIX shell(bash/zsh/fish) - 排除 PowerShell 和 cmd(因为它们的 cd 命令和路径格式不同) - 串口连接仍然不支持(它们根本没有 SFTP) - 定位路径到终端功能已支持本地 Shell(无需修改) * feat: support PowerShell and CMD in session restore - Accept Windows absolute paths (C:\...) in isRestoreCwdPathEligible - Add shell-specific cd commands: * PowerShell: Set-Location -LiteralPath with '' quote escaping * CMD: cd /d with "" quote escaping * bash/POSIX: cd -- with '\'' quote escaping - Remove PowerShell/CMD restrictions in cwd injection eligibility - Fix line terminator in SFTP locate path (use \r\n for Windows PTY) * fix: bound local shell panel preferences and synchronize settings --------- Co-authored-by: HHXXYY123 <HHXXYY123@outlook.com> Co-authored-by: binaricat <binaricat@users.noreply.github.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
201 lines
6.7 KiB
TypeScript
201 lines
6.7 KiB
TypeScript
import { useSyncExternalStore } from 'react';
|
|
|
|
import type { UILanguage } from '../../domain/models/connection';
|
|
import type { HotkeyScheme } from '../../domain/models/keyBindings';
|
|
import type { DynamicTabTitleMode } from '../../domain/models/terminal';
|
|
import type { HostClickBehavior } from '../../domain/hostClickBehavior';
|
|
import type { TerminalSidePanelAutoOpenTab } from '../../domain/terminalSidePanelAutoOpen';
|
|
|
|
type Listener = () => void;
|
|
|
|
export type SettingsChromeTheme = 'dark' | 'light' | 'system';
|
|
|
|
/**
|
|
* Chrome-facing settings slice. Keep this aligned with what AppView / TopTabs /
|
|
* HostTree actually read. Unrelated settings edits must not rebuild App chrome
|
|
* domain bags — leaves subscribe here instead of receiving the whole settings
|
|
* object through domain props.
|
|
*/
|
|
export type SettingsChromeSnapshot = {
|
|
theme: SettingsChromeTheme;
|
|
resolvedTheme: 'light' | 'dark';
|
|
lightUiThemeId: string;
|
|
darkUiThemeId: string;
|
|
uiLanguage: UILanguage;
|
|
windowOpacity: number;
|
|
tabBarPosition: 'top' | 'bottom';
|
|
showSftpTab: boolean;
|
|
showHostTreeSidebar: boolean;
|
|
showRecentHosts: boolean;
|
|
hostClickBehavior: HostClickBehavior;
|
|
showOnlyUngroupedHostsInRoot: boolean;
|
|
dynamicTabTitleMode: DynamicTabTitleMode;
|
|
disableTerminalFontZoom: boolean;
|
|
hotkeyScheme: HotkeyScheme;
|
|
shellOnlyTabNumberShortcuts: boolean;
|
|
showTabNumberBadges: boolean;
|
|
restoreTerminalCwd: boolean;
|
|
terminalSidePanelAutoOpen: boolean;
|
|
terminalSidePanelAutoOpenTab: TerminalSidePanelAutoOpenTab;
|
|
localShellSidePanelAutoOpen: boolean;
|
|
localShellSidePanelAutoOpenTab: TerminalSidePanelAutoOpenTab;
|
|
};
|
|
|
|
/**
|
|
* Setters chrome leaves need. Kept on a separate slot from the value snapshot:
|
|
* `useSettingsState` rebuilds these callbacks on its own cadence, and that must
|
|
* never invalidate the value snapshot.
|
|
*/
|
|
export type SettingsChromeActions = {
|
|
setTheme: (theme: SettingsChromeTheme) => void;
|
|
setWindowOpacity: (opacity: number) => void;
|
|
};
|
|
|
|
export const DEFAULT_SETTINGS_CHROME_SNAPSHOT: SettingsChromeSnapshot = Object.freeze({
|
|
theme: 'system',
|
|
resolvedTheme: 'dark',
|
|
lightUiThemeId: 'default',
|
|
darkUiThemeId: 'default',
|
|
uiLanguage: 'en',
|
|
windowOpacity: 1,
|
|
tabBarPosition: 'top',
|
|
showSftpTab: true,
|
|
showHostTreeSidebar: true,
|
|
showRecentHosts: true,
|
|
hostClickBehavior: 'connect',
|
|
showOnlyUngroupedHostsInRoot: false,
|
|
dynamicTabTitleMode: 'off',
|
|
disableTerminalFontZoom: false,
|
|
hotkeyScheme: 'pc',
|
|
shellOnlyTabNumberShortcuts: false,
|
|
showTabNumberBadges: true,
|
|
restoreTerminalCwd: true,
|
|
terminalSidePanelAutoOpen: false,
|
|
terminalSidePanelAutoOpenTab: 'ai',
|
|
localShellSidePanelAutoOpen: false,
|
|
localShellSidePanelAutoOpenTab: 'scripts',
|
|
} satisfies SettingsChromeSnapshot);
|
|
|
|
export function settingsChromeSnapshotsEqual(
|
|
a: SettingsChromeSnapshot,
|
|
b: SettingsChromeSnapshot,
|
|
): boolean {
|
|
return a.theme === b.theme
|
|
&& a.resolvedTheme === b.resolvedTheme
|
|
&& a.lightUiThemeId === b.lightUiThemeId
|
|
&& a.darkUiThemeId === b.darkUiThemeId
|
|
&& a.uiLanguage === b.uiLanguage
|
|
&& a.windowOpacity === b.windowOpacity
|
|
&& a.tabBarPosition === b.tabBarPosition
|
|
&& a.showSftpTab === b.showSftpTab
|
|
&& a.showHostTreeSidebar === b.showHostTreeSidebar
|
|
&& a.showRecentHosts === b.showRecentHosts
|
|
&& a.hostClickBehavior === b.hostClickBehavior
|
|
&& a.showOnlyUngroupedHostsInRoot === b.showOnlyUngroupedHostsInRoot
|
|
&& a.dynamicTabTitleMode === b.dynamicTabTitleMode
|
|
&& a.disableTerminalFontZoom === b.disableTerminalFontZoom
|
|
&& a.hotkeyScheme === b.hotkeyScheme
|
|
&& a.shellOnlyTabNumberShortcuts === b.shellOnlyTabNumberShortcuts
|
|
&& a.showTabNumberBadges === b.showTabNumberBadges
|
|
&& a.restoreTerminalCwd === b.restoreTerminalCwd
|
|
&& a.terminalSidePanelAutoOpen === b.terminalSidePanelAutoOpen
|
|
&& a.terminalSidePanelAutoOpenTab === b.terminalSidePanelAutoOpenTab
|
|
&& a.localShellSidePanelAutoOpen === b.localShellSidePanelAutoOpen
|
|
&& a.localShellSidePanelAutoOpenTab === b.localShellSidePanelAutoOpenTab;
|
|
}
|
|
|
|
class SettingsChromeStore {
|
|
private snapshot: SettingsChromeSnapshot = DEFAULT_SETTINGS_CHROME_SNAPSHOT;
|
|
private actions: SettingsChromeActions | null = null;
|
|
private listeners = new Set<Listener>();
|
|
private actionListeners = new Set<Listener>();
|
|
|
|
getSnapshot = (): SettingsChromeSnapshot => this.snapshot;
|
|
|
|
subscribe = (listener: Listener): (() => void) => {
|
|
this.listeners.add(listener);
|
|
return () => {
|
|
this.listeners.delete(listener);
|
|
};
|
|
};
|
|
|
|
setSnapshot(next: SettingsChromeSnapshot): void {
|
|
if (settingsChromeSnapshotsEqual(this.snapshot, next)) return;
|
|
this.snapshot = next;
|
|
for (const listener of this.listeners) {
|
|
listener();
|
|
}
|
|
}
|
|
|
|
getActions = (): SettingsChromeActions | null => this.actions;
|
|
|
|
subscribeActions = (listener: Listener): (() => void) => {
|
|
this.actionListeners.add(listener);
|
|
return () => {
|
|
this.actionListeners.delete(listener);
|
|
};
|
|
};
|
|
|
|
setActions(next: SettingsChromeActions | null): void {
|
|
if (this.actions === next) return;
|
|
this.actions = next;
|
|
for (const listener of this.actionListeners) {
|
|
listener();
|
|
}
|
|
}
|
|
}
|
|
|
|
export const settingsChromeStore = new SettingsChromeStore();
|
|
|
|
export function publishSettingsChromeSnapshot(
|
|
snapshot: SettingsChromeSnapshot,
|
|
): void {
|
|
settingsChromeStore.setSnapshot(snapshot);
|
|
}
|
|
|
|
export function getSettingsChromeSnapshot(): SettingsChromeSnapshot {
|
|
return settingsChromeStore.getSnapshot();
|
|
}
|
|
|
|
export function subscribeSettingsChrome(listener: Listener): () => void {
|
|
return settingsChromeStore.subscribe(listener);
|
|
}
|
|
|
|
export function registerSettingsChromeActions(
|
|
actions: SettingsChromeActions | null,
|
|
): void {
|
|
settingsChromeStore.setActions(actions);
|
|
}
|
|
|
|
export function getSettingsChromeActions(): SettingsChromeActions | null {
|
|
return settingsChromeStore.getActions();
|
|
}
|
|
|
|
export function subscribeSettingsChromeActions(listener: Listener): () => void {
|
|
return settingsChromeStore.subscribeActions(listener);
|
|
}
|
|
|
|
export function useSettingsChromeStore(): SettingsChromeSnapshot {
|
|
return useSyncExternalStore(
|
|
subscribeSettingsChrome,
|
|
getSettingsChromeSnapshot,
|
|
getSettingsChromeSnapshot,
|
|
);
|
|
}
|
|
|
|
const noopSetTheme: SettingsChromeActions['setTheme'] = () => {};
|
|
const noopSetWindowOpacity: SettingsChromeActions['setWindowOpacity'] = () => {};
|
|
|
|
/** Chrome setters, safe to call before `useSettingsState` has registered. */
|
|
export function useSettingsChromeActions(): SettingsChromeActions {
|
|
const actions = useSyncExternalStore(
|
|
subscribeSettingsChromeActions,
|
|
getSettingsChromeActions,
|
|
getSettingsChromeActions,
|
|
);
|
|
return {
|
|
setTheme: actions?.setTheme ?? noopSetTheme,
|
|
setWindowOpacity: actions?.setWindowOpacity ?? noopSetWindowOpacity,
|
|
};
|
|
}
|