fix: recover webview lazily and stop ws leak after render process ter… (#7410)

* fix: recover webview lazily and stop ws leak after render process termination

macOS 内存压力下 WKWebView 渲染进程可能被系统杀掉,导致:
1. 从托盘打开主窗口时白屏;
2. 前端无法清理 Mihomo WebSocket 订阅,孤儿订阅持续将 >1KB 的
   payload 写入 tauri ChannelDataIpcQueue 且无人取走,主进程内存
   以 ~150MB/h 持续增长。

注册 on_web_content_process_terminate 钩子:
- 立即清理全部 Mihomo WebSocket 订阅阻断泄漏(托盘速率任务会自动重连);
- 窗口可见时立即 reload 拉起渲染进程恢复页面;窗口隐藏/最小化时仅置位
  待重载标记,等用户下次打开窗口时再 reload——系统正是因内存压力才杀掉
  不可见窗口的渲染进程,立即重建既浪费内存也可能形成反复被杀的循环。

另修复 tray_event 配置为 tray_menu 时误报 invalid tray event 警告。

* fix: gate logging import to macos to satisfy clippy on other platforms
This commit is contained in:
GrainFull
2026-07-04 00:21:03 +00:00
committed by GitHub
parent 336bd9d735
commit 1f76c67afb
4 changed files with 101 additions and 1 deletions
+10
View File
@@ -218,6 +218,16 @@ impl WindowManager {
fn activate_window(window: &WebviewWindow<Wry>) -> WindowOperationResult {
logging!(info, Type::Window, "开始激活窗口");
// 关键步骤:渲染进程曾在窗口不可见时被系统终止(macOS 内存压力),
// 页面当前是死亡的白屏状态,显示窗口前先 reload 重新拉起渲染进程。
#[cfg(target_os = "macos")]
if crate::utils::resolve::window::take_webview_needs_reload() {
logging!(info, Type::Window, "渲染进程曾被系统终止,激活窗口前重载页面");
if let Err(e) = window.reload() {
logging!(warn, Type::Window, "重载页面失败: {}", e);
}
}
let mut operations_successful = true;
// 1. 如果窗口最小化,先取消最小化