Skip to content

Commit 5349984

Browse files
authored
fix: set webview2 path before initializing runtime (#14054)
* fix: set webview2 path before initializing runtime * wrong current_exe function
1 parent 5f535b4 commit 5349984

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:bug
3+
---
4+
5+
Fixed an issue that caused the runtime WebView2 detection to fail for FixedRuntime installations.

crates/tauri/src/app.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,26 @@ tauri::Builder::default()
21652165
},
21662166
};
21672167

2168+
// The env var must be set before the Runtime is created so that GetAvailableBrowserVersionString picks it up.
2169+
#[cfg(windows)]
2170+
{
2171+
if let crate::utils::config::WebviewInstallMode::FixedRuntime { path } =
2172+
&manager.config.bundle.windows.webview_install_mode
2173+
{
2174+
if let Some(exe_dir) = crate::utils::platform::current_exe()
2175+
.ok()
2176+
.and_then(|p| p.parent().map(|p| p.to_path_buf()))
2177+
{
2178+
std::env::set_var("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", exe_dir.join(path));
2179+
} else {
2180+
#[cfg(debug_assertions)]
2181+
eprintln!(
2182+
"failed to resolve resource directory; fallback to the installed Webview2 runtime."
2183+
);
2184+
}
2185+
}
2186+
}
2187+
21682188
#[cfg(any(windows, target_os = "linux"))]
21692189
let mut runtime = if self.runtime_any_thread {
21702190
R::new_any_thread(runtime_args)?
@@ -2242,25 +2262,6 @@ tauri::Builder::default()
22422262
app.manage(ChannelDataIpcQueue::default());
22432263
app.handle.plugin(crate::ipc::channel::plugin())?;
22442264

2245-
#[cfg(windows)]
2246-
{
2247-
if let crate::utils::config::WebviewInstallMode::FixedRuntime { path } =
2248-
&app.manager.config().bundle.windows.webview_install_mode
2249-
{
2250-
if let Ok(resource_dir) = app.path().resource_dir() {
2251-
std::env::set_var(
2252-
"WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",
2253-
resource_dir.join(path),
2254-
);
2255-
} else {
2256-
#[cfg(debug_assertions)]
2257-
eprintln!(
2258-
"failed to resolve resource directory; fallback to the installed Webview2 runtime."
2259-
);
2260-
}
2261-
}
2262-
}
2263-
22642265
let handle = app.handle();
22652266

22662267
// initialize default tray icon if defined

0 commit comments

Comments
 (0)