fix: set webview2 path before initializing runtime (#14054)

* fix: set webview2 path before initializing runtime

* wrong current_exe function
This commit is contained in:
Fabian-Lars
2025-08-24 13:18:14 +02:00
committed by GitHub
parent 5f535b4150
commit 5349984064
2 changed files with 25 additions and 19 deletions

View File

@@ -0,0 +1,5 @@
---
tauri: patch:bug
---
Fixed an issue that caused the runtime WebView2 detection to fail for FixedRuntime installations.

View File

@@ -2165,6 +2165,26 @@ tauri::Builder::default()
},
};
// The env var must be set before the Runtime is created so that GetAvailableBrowserVersionString picks it up.
#[cfg(windows)]
{
if let crate::utils::config::WebviewInstallMode::FixedRuntime { path } =
&manager.config.bundle.windows.webview_install_mode
{
if let Some(exe_dir) = crate::utils::platform::current_exe()
.ok()
.and_then(|p| p.parent().map(|p| p.to_path_buf()))
{
std::env::set_var("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", exe_dir.join(path));
} else {
#[cfg(debug_assertions)]
eprintln!(
"failed to resolve resource directory; fallback to the installed Webview2 runtime."
);
}
}
}
#[cfg(any(windows, target_os = "linux"))]
let mut runtime = if self.runtime_any_thread {
R::new_any_thread(runtime_args)?
@@ -2242,25 +2262,6 @@ tauri::Builder::default()
app.manage(ChannelDataIpcQueue::default());
app.handle.plugin(crate::ipc::channel::plugin())?;
#[cfg(windows)]
{
if let crate::utils::config::WebviewInstallMode::FixedRuntime { path } =
&app.manager.config().bundle.windows.webview_install_mode
{
if let Ok(resource_dir) = app.path().resource_dir() {
std::env::set_var(
"WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",
resource_dir.join(path),
);
} else {
#[cfg(debug_assertions)]
eprintln!(
"failed to resolve resource directory; fallback to the installed Webview2 runtime."
);
}
}
}
let handle = app.handle();
// initialize default tray icon if defined