feat(perf): v3.26.128 浏览器独立窗口空闲 30 分钟自动销毁(单个占 ~480MB)

This commit is contained in:
qiqi committed 2026-11-30 18:15:28 +08:00
1 parent d31e342c91
commit 9bcf6d7ff7
6 files changed
+37 -4

No files matched your search

+25
View File
@@ -1976,6 +1976,31 @@ pub fn run() {
// 没有历史几何时也要夹一次:默认尺寸可能大于当前屏幕(远程/小屏场景)
if let Some(w) = app.handle().get_window("main") { clamp_geom(&w, 1024, 640); }
build_tray(app.handle())?;
// v3.26.128:浏览器独立窗口的「空闲休眠」。
// 它每个实例都是一个独立 WebKit 进程(mac 实测 footprint 251MB / 整树 +480MB)。
// 用户切回画布后往往一直挂着 ⇒ 失焦满 30 分钟就销毁(地址栏/站点由插件在下次点开时重建)。
// 只看 is_focused,不做任何内容判断;关掉窗口后计数自动复位。
{
let app_idle = app.handle().clone();
std::thread::spawn(move || {
let mut last = std::time::Instant::now();
loop {
std::thread::sleep(std::time::Duration::from_secs(60));
match app_idle.get_webview_window("browser") {
Some(win) => {
let focused = win.is_focused().unwrap_or(false);
if focused {
last = std::time::Instant::now();
} else if last.elapsed().as_secs() >= 1800 {
let _ = win.close();
last = std::time::Instant::now();
}
}
None => { last = std::time::Instant::now(); }
}
}
});
}
// macOS 必须有应用菜单,否则 Cmd+C / Cmd+V / Cmd+X 根本不会进 WebView(Tauri 已知问题)
#[cfg(target_os = "macos")]
{