From 64178893e4ae0daa919b8cf411c7532b46b4eb37 Mon Sep 17 00:00:00 2001 From: venti1112 <3788365896@qq.com> Date: Wed, 6 May 2026 18:09:31 +0800 Subject: [PATCH] fix: show uninstall failure notification in WebUI Previous behavior: when an uninstall operation failed, the system did not provide any error feedback to the user and would simply reconnect during a polling check. Fixed behavior: if an uninstall fails, a failure notification is now displayed in the WebUI, informing the user that the uninstall has failed. --- packages/core/src/hook/hook-manager.ts | 17 ++++++++++++-- packages/webui/src/App.tsx | 31 +++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/packages/core/src/hook/hook-manager.ts b/packages/core/src/hook/hook-manager.ts index 795e2707..664427a1 100644 --- a/packages/core/src/hook/hook-manager.ts +++ b/packages/core/src/hook/hook-manager.ts @@ -204,11 +204,24 @@ export class HookManager { log.info('SnowLuma unloaded from PID=%d via unloadModuleManual', pid); } + // Clear injection state first state.injected = false; state.injectResult = null; state.method = ''; state.uin = '0'; - state.status = 'available'; + + // Verify unload succeeded by checking if pipe still exists + const livePipes = await QqHookClient.listLivePipes(); + if (livePipes.has(pid)) { + // Pipe still exists - unload failed, but let watcher handle reconnection + state.error = 'DLL卸载失败:命名管道仍然存在,watcher将自动重连'; + state.status = 'connecting'; // Let watcher pick it up and reconnect + log.warn('unload verification failed: PID=%d pipe still exists after unloadModuleManual, watcher will reconnect', pid); + } else { + // Successfully unloaded + state.status = 'available'; + state.error = ''; + } } catch (error) { state.status = 'error'; state.error = error instanceof Error ? error.message : String(error); @@ -311,7 +324,7 @@ export class HookManager { state.name = proc.name || state.name; state.path = proc.path || state.path; } - // Auto-detect hooks that survived a SnowLuma restart. + // Auto-detect hooks that survived a SnowLuma restart or failed unload. for (const pid of livePipes) { const state = this.ensureState(pid); if (!state.injected) { diff --git a/packages/webui/src/App.tsx b/packages/webui/src/App.tsx index 875d7ad1..0d866066 100644 --- a/packages/webui/src/App.tsx +++ b/packages/webui/src/App.tsx @@ -8,6 +8,7 @@ import { ConfigPage } from '@/components/pages/config-page'; import { LogsPage } from '@/components/pages/logs-page'; import { SettingsPage } from '@/components/pages/settings-page'; import { ChangePasswordPage, type PasswordRule } from '@/components/pages/change-password-page'; +import { ConfirmDialog } from '@/components/confirm-dialog'; import type { Page } from '@/components/layout/sidebar'; import type { HookProcessInfo, OneBotConfig, QQInfo, SystemInfo } from '@/types'; @@ -41,6 +42,7 @@ function AppInner() { const [processUnloadingPid, setProcessUnloadingPid] = useState(null); const [processRefreshingPid, setProcessRefreshingPid] = useState(null); const [processActionStatus, setProcessActionStatus] = useState(''); + const [unloadFailedAlert, setUnloadFailedAlert] = useState<{ pid: number; error: string } | null>(null); // Tracks PIDs with an in-flight load/unload/refresh request so the UI can // collapse spam-clicks instead of firing a second concurrent request. const inflightProcessOps = useRef(new Set()); @@ -256,7 +258,15 @@ function AppInner() { const res = await fetchApi(`/api/processes/${pid}/unload`, { method: 'POST' }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.message || data.error || '卸载失败'); - setProcessActionStatus(`已从进程 ${pid} 卸载`); + + // Check if unload actually failed (pipe still exists) + if (data.process?.status === 'connecting' && data.process?.error) { + setUnloadFailedAlert({ pid, error: data.process.error }); + setProcessActionStatus(`进程 ${pid} 卸载失败`); + } else { + setProcessActionStatus(`已从进程 ${pid} 卸载`); + } + await refreshProcesses(); } catch (e) { setProcessActionStatus(`卸载失败:${(e as Error).message}`); @@ -376,6 +386,25 @@ function AppInner() { {active === 'settings' && } )} + + !open && setUnloadFailedAlert(null)} + title="卸载失败" + description={ + unloadFailedAlert ? ( + <> +

进程 {unloadFailedAlert.pid} 的 SnowLuma DLL 卸载失败。

+

{unloadFailedAlert.error}

+

+ 系统将继续尝试重新连接该进程。如需彻底卸载,请重启 QQ 进程。 +

+ + ) : null + } + confirmText="知道了" + onConfirm={() => setUnloadFailedAlert(null)} + /> ); }