Add pipe-watcher and manual refresh for hooks

Introduce a background pipe-watcher and per-PID operation serialization in HookManager to reliably detect and reconnect to SnowLuma pipes, reduce races, and remove the previous connect retry loop. Add new status 'connecting' and a refreshProcess API endpoint to force a probe/reconcile for a PID. Implement QqHookClient.listLivePipes() (and isClosed/probePipe updates) to enumerate live mojo pipes efficiently. Simplify client teardown logic and improve state transitions/logging. Update web UI: add a Refresh button, track inflight process ops, show connecting status and updated action messages. Update shared types to include the new 'connecting' status.
This commit is contained in:
手瓜一十雪 committed 2026-05-06 16:10:14 +08:00
1 parent 2e340f58a8
commit 4b02367a5f
6 files changed
+435 -138

No files matched your search

@@ -31,17 +31,20 @@ interface OverviewPageProps {
processList: HookProcessInfo[];
processLoadingPid: number | null;
processUnloadingPid: number | null;
processRefreshingPid: number | null;
processActionStatus: string;
systemInfo: SystemInfo | null;
onRefreshProcesses: () => void;
onRefreshSystem: () => void;
onLoadProcess: (pid: number) => Promise<void> | void;
onUnloadProcess: (pid: number) => Promise<void> | void;
onRefreshProcess: (pid: number) => Promise<void> | void;
}
const processStatusLabel: Record<HookProcessInfo['status'], string> = {
available: '可加载',
loading: '加载中',
connecting: '等待连接',
loaded: '等待登录',
online: '已在线',
error: '错误',
@@ -50,8 +53,9 @@ const processStatusLabel: Record<HookProcessInfo['status'], string> = {
function processBadgeVariant(status: HookProcessInfo['status']) {
if (status === 'online') return 'success' as const;
if (status === 'error' || status === 'disconnected') return 'destructive' as const;
if (status === 'loading' || status === 'loaded') return 'default' as const;
if (status === 'error') return 'destructive' as const;
if (status === 'disconnected') return 'destructive' as const;
if (status === 'loading' || status === 'connecting' || status === 'loaded') return 'default' as const;
return 'secondary' as const;
}
@@ -99,12 +103,14 @@ export function OverviewPage({
processList,
processLoadingPid,
processUnloadingPid,
processRefreshingPid,
processActionStatus,
systemInfo,
onRefreshProcesses,
onRefreshSystem,
onLoadProcess,
onUnloadProcess,
onRefreshProcess,
}: OverviewPageProps) {
const [confirm, setConfirm] = useState<
| { kind: 'load' | 'unload'; pid: number; name: string }
@@ -278,10 +284,13 @@ export function OverviewPage({
{processList.map((proc, idx) => {
const loading = processLoadingPid === proc.pid || proc.status === 'loading';
const unloading = processUnloadingPid === proc.pid;
const busy = loading || unloading;
const refreshing = processRefreshingPid === proc.pid;
const busy = loading || unloading || refreshing;
const isOnline = proc.status === 'online';
const canUnload =
proc.injected || proc.status === 'loaded' || isOnline || proc.status === 'disconnected';
const canUnload = proc.injected;
// Refresh is meaningful whenever a hook may exist (so the user
// can re-check the pipe and trigger a reconnect on demand).
const showRefresh = proc.injected || proc.status === 'connecting' || proc.status === 'disconnected';
return (
<motion.div
key={proc.pid}
@@ -328,26 +337,44 @@ export function OverviewPage({
</div>
)}
</div>
<Button
size="sm"
variant={canUnload ? 'outline' : 'default'}
disabled={busy}
onClick={() =>
setConfirm({
kind: canUnload ? 'unload' : 'load',
pid: proc.pid,
name: proc.name || `PID ${proc.pid}`,
})
}
className={cn(
'shrink-0',
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
<div className="flex shrink-0 items-center gap-1.5">
{showRefresh && (
<Button
size="icon"
variant="ghost"
disabled={busy}
aria-label={`刷新进程 ${proc.pid} 管道状态`}
title="刷新管道状态 / 重连"
onClick={() => onRefreshProcess(proc.pid)}
className="size-8 text-muted-foreground hover:text-foreground"
>
{refreshing ? (
<Loader2 className="size-3.5 animate-spin" />
) : (
<RefreshCw className="size-3.5" />
)}
</Button>
)}
>
{busy && <Loader2 className="size-3.5 animate-spin" />}
{!busy && canUnload && <Unplug className="size-3.5" />}
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
</Button>
<Button
size="sm"
variant={canUnload ? 'outline' : 'default'}
disabled={busy}
onClick={() =>
setConfirm({
kind: canUnload ? 'unload' : 'load',
pid: proc.pid,
name: proc.name || `PID ${proc.pid}`,
})
}
className={cn(
canUnload && 'text-destructive hover:bg-destructive/10 hover:text-destructive'
)}
>
{(loading || unloading) && <Loader2 className="size-3.5 animate-spin" />}
{!loading && !unloading && canUnload && <Unplug className="size-3.5" />}
{canUnload ? (unloading ? '卸载中' : '卸载') : loading ? '加载中' : '加载'}
</Button>
</div>
</motion.div>
);
})}