Files
Netcatty/application/state/sftp/useSftpTransferLifecycle.ts
T
bincxz d165e158f7 fix(sftp): unify transfer control under process-level TransferRuntime
Pause and resume now go through one process-level control plane that survives
panel/terminal close: TransferRuntime + soft latches/epochs/walk registry,
soft-then-hard resume, dual-epoch-safe progress, and no-owner soft control.
2026-07-26 21:27:01 +08:00

46 lines
1.4 KiB
TypeScript

import { useEffect, useLayoutEffect, useRef } from "react";
import { sftpTransferCenterStore } from "../sftpTransferCenterStore";
export function useWarmSftpTransferPool(params: {
hostIds: readonly string[];
activeHostId?: string;
warmTransferPoolForHost?: (hostId: string) => void | Promise<void>;
}) {
const warmRef = useRef(params.warmTransferPoolForHost);
warmRef.current = params.warmTransferPoolForHost;
const hostIdsKey = [...new Set([
...params.hostIds,
...(params.activeHostId ? [params.activeHostId] : []),
])].sort().join("\u0000");
useEffect(() => {
for (const hostId of hostIdsKey.split("\u0000").filter(Boolean)) {
void warmRef.current?.(hostId);
}
}, [hostIdsKey]);
}
export function useReportSftpTransferOwnerActivity(params: {
ownerId: string;
activeTransfersCount: number;
onActiveTransfersChange?: (count: number) => void;
}) {
const onChangeRef = useRef(params.onActiveTransfersChange);
onChangeRef.current = params.onActiveTransfersChange;
useLayoutEffect(() => {
onChangeRef.current?.(params.activeTransfersCount);
}, [params.activeTransfersCount]);
useEffect(() => () => {
const unfinished = sftpTransferCenterStore.getSnapshot().tasks.filter((task) => (
task.ownerId === params.ownerId
&& !task.parentTaskId
&& task.status !== "completed"
&& task.status !== "cancelled"
)).length;
onChangeRef.current?.(unfinished);
}, [params.ownerId]);
}