fix(wry): recover from WebView2 process failures

This commit is contained in:
jearhe authored and GitHub committed 2026-08-20 20:42:45 +08:00
1 parent d2e2270d84
commit b3acf1e558
10 files changed
+1474 -2

No files matched your search

+4
View File
@@ -9,6 +9,8 @@ mod startup_recovery;
#[cfg(all(not(target_os = "windows"), not(test)))]
#[path = "startup_recovery_noop.rs"]
mod startup_recovery;
#[cfg(any(target_os = "windows", test))]
mod webview2_recovery;
mod window_state_guard;
use commands::connection::AppState;
@@ -1485,6 +1487,8 @@ pub fn run() {
commands::ssh_prompt::install_ssh_notice_bridge(app.handle());
#[cfg(target_os = "macos")]
macos_app_delegate::install_dock_quit_handler(app.handle());
#[cfg(target_os = "windows")]
webview2_recovery::install(app.handle());
let startup_links = commands::deep_link::connection_deep_links_from_args(std::env::args().skip(1));
open_connection_deep_links(app.handle(), startup_links);
+17
View File
@@ -8,6 +8,8 @@ use std::time::Duration;
use tauri::Manager;
const STARTUP_LOG_FILE: &str = "startup.log";
#[cfg(target_os = "windows")]
const RUNTIME_RECOVERY_LOG_FILE: &str = "webview2-recovery.log";
const STARTUP_LOG_DIR_ENV: &str = "DBX_STARTUP_LOG_DIR";
const KEEP_STARTUP_LOG_ENV: &str = "DBX_KEEP_STARTUP_LOG";
#[cfg(target_os = "windows")]
@@ -166,6 +168,21 @@ fn write_line(path: &Path, line: &str) {
let _ = writeln!(file, "{line}");
}
/// Appends a runtime (post-startup) recovery event to a dedicated log file
/// (`webview2-recovery.log` next to `startup.log`).
///
/// Unlike the `log` facade, this is **not** gated by the desktop
/// `debug_logging_enabled` setting (`apply_debug_log_level` sets the global
/// `log::set_max_level` to `Off` in packaged builds by default), so packaged
/// Windows builds always record WebView2 process-failure recovery decisions
/// on affected devices. The `log`/`eprintln` channels are still used on top
/// of this in debug builds.
#[cfg(target_os = "windows")]
pub(crate) fn record_runtime_recovery_event(message: impl AsRef<str>) {
let Some(dir) = startup_log_dir() else { return };
write_line(&dir.join(RUNTIME_RECOVERY_LOG_FILE), &format_probe_line(message.as_ref()));
}
fn format_probe_line(message: &str) -> String {
format!("[{}][pid={}] {message}", chrono::Local::now().format("%Y-%m-%d %H:%M:%S%.3f"), std::process::id())
}
File diff suppressed because it is too large. Load diff