@@ -2165,6 +2165,26 @@ tauri::Builder::default()
2165
2165
} ,
2166
2166
} ;
2167
2167
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
+
2168
2188
#[ cfg( any( windows, target_os = "linux" ) ) ]
2169
2189
let mut runtime = if self . runtime_any_thread {
2170
2190
R :: new_any_thread ( runtime_args) ?
@@ -2242,25 +2262,6 @@ tauri::Builder::default()
2242
2262
app. manage ( ChannelDataIpcQueue :: default ( ) ) ;
2243
2263
app. handle . plugin ( crate :: ipc:: channel:: plugin ( ) ) ?;
2244
2264
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
-
2264
2265
let handle = app. handle ( ) ;
2265
2266
2266
2267
// initialize default tray icon if defined
0 commit comments