mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 09:16:29 +00:00
* chore: 移除死代码并修复架构分层违规 - 删除未使用的 ACP 模块 (infrastructure/ai/acp/) - 删除未使用的 AI 组件 (ExecutionPlan, PermissionDialog) - 将 syncPayload.ts 从 domain 移至 application 层,修复分层违规 - 移除未使用的导出 (useSecurityState, useProviderStatus, GitHubAuthState, getAgentCommandLabel, ImageAttachment, HotkeyActions) - 收窄 Electron bridge module.exports,移除未使用的导出函数 - 将仅内部使用的函数/类型取消导出 (isSupportedLocale, SyncDashboard) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 二次审查清理 — 移除更多死代码和架构违规 - 移除未使用的 ConversationEmptyState 组件和类型 - 移除未使用的 PromptInputSelect 系列组件 (5 个导出) - 移除 global.d.ts 中残留的 SMBConfig 类型和 cloudSyncSmb* 方法声明 - 移除 useAutoSync.ts 中未使用的 toast 导入 (同时修复 application→components 反向依赖) - 清理因删除而产生的多余 import Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 消除直接 localStorage 访问,提取 safeSend 共享工具 localStorage 集中化: - 新增 storageKeys 常量: SIDE_PANEL_WIDTH, PF_RECONNECT_CANCEL, DEBUG_HOTKEYS, DEBUG_UPDATE_DEMO - TerminalLayer/SettingsApplicationTab/App.tsx/useUpdateCheck 改用 localStorageAdapter - CloudSyncManager 内部方法改用 localStorageAdapter - portForwardingService 改用 localStorageAdapter + 集中 key safeSend 去重: - 新增 electron/bridges/ipcUtils.cjs 共享模块 - sshBridge/sftpBridge/portForwardingBridge/sshAuthHelper/aiBridge 统一引用 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 终审清理 — 移除未使用的 require 和废弃类型别名 - 移除 sftpBridge.cjs 中未使用的 require("node:net") - 移除 aiBridge.cjs 中未使用的 require("node:path") - 移除 types.ts 中已废弃的 ChatMessageImage 类型别名 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: 修复 ESLint 错误 — 组件不再直接导入 infrastructure - 新增 useStoredNumber hook,TerminalLayer 通过 hook 访问侧边栏宽度 - SettingsApplicationTab 的 isUpdateDemoMode 改为从 useUpdateCheck hook 传入 - 移除 useCloudSync.ts 中未使用的 CloudSyncManager 导入和 GitHubAuthState 接口 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: 提取 notification port,消除 application 层对 components 的依赖 将 toast 通知抽象为 application/notification.ts 端口, UI 层通过 setNotify 注入实现,useAutoSync 改用 notify 接口。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import React, { useCallback } from "react";
|
|
import type { PortForwardingRule } from "../../../domain/models";
|
|
import type { SyncPayload } from "../../../domain/sync";
|
|
import { buildSyncPayload, applySyncPayload } from "../../../application/syncPayload";
|
|
import type { SyncableVaultData } from "../../../application/syncPayload";
|
|
import { STORAGE_KEY_PORT_FORWARDING } from "../../../infrastructure/config/storageKeys";
|
|
import { localStorageAdapter } from "../../../infrastructure/persistence/localStorageAdapter";
|
|
import { getEffectiveKnownHosts } from "../../../infrastructure/syncHelpers";
|
|
import { CloudSyncSettings } from "../../CloudSyncSettings";
|
|
import { SettingsTabContent } from "../settings-ui";
|
|
|
|
export default function SettingsSyncTab(props: {
|
|
vault: SyncableVaultData;
|
|
portForwardingRules: PortForwardingRule[];
|
|
importDataFromString: (data: string) => void;
|
|
importPortForwardingRules: (rules: PortForwardingRule[]) => void;
|
|
clearVaultData: () => void;
|
|
onSettingsApplied?: () => void;
|
|
}) {
|
|
const {
|
|
vault,
|
|
portForwardingRules,
|
|
importDataFromString,
|
|
importPortForwardingRules,
|
|
clearVaultData,
|
|
onSettingsApplied,
|
|
} = props;
|
|
|
|
const onBuildPayload = useCallback((): SyncPayload => {
|
|
// If hook state is empty but localStorage has data, the async store
|
|
// initialization hasn't finished yet. Read from localStorage directly
|
|
// to avoid uploading empty arrays and overwriting the remote snapshot.
|
|
let effectiveRules = portForwardingRules;
|
|
if (effectiveRules.length === 0) {
|
|
const stored = localStorageAdapter.read<PortForwardingRule[]>(
|
|
STORAGE_KEY_PORT_FORWARDING,
|
|
);
|
|
if (stored && Array.isArray(stored) && stored.length > 0) {
|
|
// Strip transient per-device fields (status, error, lastUsedAt)
|
|
// that setGlobalRules persists to localStorage but shouldn't be
|
|
// included in the cloud sync snapshot.
|
|
effectiveRules = stored.map(({ status: _status, error: _error, ...rest }) => ({
|
|
...rest,
|
|
status: "inactive" as const,
|
|
error: undefined,
|
|
lastUsedAt: undefined,
|
|
}));
|
|
}
|
|
}
|
|
|
|
const effectiveKnownHosts = getEffectiveKnownHosts(vault.knownHosts);
|
|
|
|
return buildSyncPayload({ ...vault, knownHosts: effectiveKnownHosts }, effectiveRules);
|
|
}, [vault, portForwardingRules]);
|
|
|
|
const onApplyPayload = useCallback(
|
|
(payload: SyncPayload) => {
|
|
applySyncPayload(payload, {
|
|
importVaultData: importDataFromString,
|
|
importPortForwardingRules,
|
|
onSettingsApplied,
|
|
});
|
|
},
|
|
[importDataFromString, importPortForwardingRules, onSettingsApplied],
|
|
);
|
|
|
|
const clearAllLocalData = useCallback(() => {
|
|
clearVaultData();
|
|
importPortForwardingRules([]);
|
|
}, [clearVaultData, importPortForwardingRules]);
|
|
|
|
return (
|
|
<SettingsTabContent value="sync">
|
|
<CloudSyncSettings
|
|
onBuildPayload={onBuildPayload}
|
|
onApplyPayload={onApplyPayload}
|
|
onClearLocalData={clearAllLocalData}
|
|
/>
|
|
</SettingsTabContent>
|
|
);
|
|
}
|