Skip to content

Commit 85df94f

Browse files
committed
feat(core): config for fixed webview2 runtime version path (#27)
1 parent a62faf2 commit 85df94f

File tree

7 files changed

+75
-3
lines changed

7 files changed

+75
-3
lines changed

.changes/fixed-webview2-runtime.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-utils": patch
4+
"cli.rs": patch
5+
---
6+
7+
Allow using a fixed version for the Webview2 runtime via the `tauri > bundle > windows > webviewFixedRuntimePath` config option.

core/tauri-utils/src/config.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ pub struct WindowsConfig {
181181
pub certificate_thumbprint: Option<String>,
182182
/// Server to use during timestamping.
183183
pub timestamp_url: Option<String>,
184+
/// Path to the webview fixed runtime to use.
185+
///
186+
/// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
187+
/// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
188+
pub webview_fixed_runtime_path: Option<PathBuf>,
184189
/// Configuration for the MSI generated with WiX.
185190
pub wix: Option<WixConfig>,
186191
}
@@ -1931,6 +1936,22 @@ mod build {
19311936
}
19321937
}
19331938

1939+
impl ToTokens for WindowsConfig {
1940+
fn to_tokens(&self, tokens: &mut TokenStream) {
1941+
let webview_fixed_runtime_path = opt_lit(
1942+
self
1943+
.webview_fixed_runtime_path
1944+
.as_ref()
1945+
.map(path_buf_lit)
1946+
.as_ref(),
1947+
);
1948+
tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
1949+
webview_fixed_runtime_path: #webview_fixed_runtime_path,
1950+
..Default::default()
1951+
}})
1952+
}
1953+
}
1954+
19341955
impl ToTokens for BundleConfig {
19351956
fn to_tokens(&self, tokens: &mut TokenStream) {
19361957
let identifier = str_lit(&self.identifier);
@@ -1945,7 +1966,7 @@ mod build {
19451966
let deb = quote!(Default::default());
19461967
let macos = quote!(Default::default());
19471968
let external_bin = quote!(None);
1948-
let windows = quote!(Default::default());
1969+
let windows = &self.windows;
19491970

19501971
literal_struct!(
19511972
tokens,

core/tauri/src/app.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,27 @@ impl<R: Runtime> Builder<R> {
10301030
});
10311031
app.manage(env);
10321032

1033+
#[cfg(windows)]
1034+
{
1035+
if let Some(w) = &app
1036+
.manager
1037+
.config()
1038+
.tauri
1039+
.bundle
1040+
.windows
1041+
.webview_fixed_runtime_path
1042+
{
1043+
if let Some(resource_dir) = app.path_resolver().resource_dir() {
1044+
std::env::set_var("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", resource_dir.join(w));
1045+
} else {
1046+
#[cfg(debug_assertions)]
1047+
eprintln!(
1048+
"failed to resolve resource directory; fallback to the installed Webview2 runtime."
1049+
);
1050+
}
1051+
}
1052+
}
1053+
10331054
#[cfg(feature = "system-tray")]
10341055
if let Some(system_tray) = self.system_tray {
10351056
let mut ids = HashMap::new();

tooling/bundler/src/bundle/settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ pub struct WindowsSettings {
225225
pub wix: Option<WixSettings>,
226226
/// The path to the application icon. Defaults to `./icons/icon.ico`.
227227
pub icon_path: PathBuf,
228+
/// Path to the webview fixed runtime to use.
229+
pub webview_fixed_runtime_path: Option<PathBuf>,
228230
}
229231

230232
impl Default for WindowsSettings {
@@ -235,6 +237,7 @@ impl Default for WindowsSettings {
235237
timestamp_url: None,
236238
wix: None,
237239
icon_path: PathBuf::from("icons/icon.ico"),
240+
webview_fixed_runtime_path: None,
238241
}
239242
}
240243
}

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub fn build_wix_app_installer(
518518
let mut fragment_paths = Vec::new();
519519
let mut handlebars = Handlebars::new();
520520
let mut has_custom_template = false;
521-
let mut install_webview = true;
521+
let mut install_webview = settings.windows().webview_fixed_runtime_path.is_none();
522522
let mut enable_elevated_update_task = false;
523523

524524
if let Some(wix) = &settings.windows().wix {
@@ -528,7 +528,9 @@ pub fn build_wix_app_installer(
528528
data.insert("feature_refs", to_json(&wix.feature_refs));
529529
data.insert("merge_refs", to_json(&wix.merge_refs));
530530
fragment_paths = wix.fragment_paths.clone();
531-
install_webview = !wix.skip_webview_install;
531+
if wix.skip_webview_install {
532+
install_webview = false;
533+
}
532534
enable_elevated_update_task = wix.enable_elevated_update_task;
533535

534536
if let Some(temp_path) = &wix.template {

tooling/cli.rs/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"certificateThumbprint": null,
151151
"digestAlgorithm": null,
152152
"timestampUrl": null,
153+
"webviewFixedRuntimePath": null,
153154
"wix": null
154155
}
155156
},
@@ -581,6 +582,7 @@
581582
"certificateThumbprint": null,
582583
"digestAlgorithm": null,
583584
"timestampUrl": null,
585+
"webviewFixedRuntimePath": null,
584586
"wix": null
585587
},
586588
"allOf": [
@@ -1439,6 +1441,7 @@
14391441
"certificateThumbprint": null,
14401442
"digestAlgorithm": null,
14411443
"timestampUrl": null,
1444+
"webviewFixedRuntimePath": null,
14421445
"wix": null
14431446
}
14441447
},
@@ -1872,6 +1875,13 @@
18721875
"null"
18731876
]
18741877
},
1878+
"webviewFixedRuntimePath": {
1879+
"description": "Path to the webview fixed runtime to use.\n\nThe fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section). The `.cab` file must be extracted to a folder and this folder path must be defined on this field.",
1880+
"type": [
1881+
"string",
1882+
"null"
1883+
]
1884+
},
18751885
"wix": {
18761886
"description": "Configuration for the MSI generated with WiX.",
18771887
"anyOf": [

tooling/cli.rs/src/interface/rust.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,13 @@ fn tauri_config_to_bundle_settings(
416416
depends.push("libgtk-3-0".to_string());
417417
}
418418

419+
#[cfg(windows)]
420+
{
421+
if let Some(webview_fixed_runtime_path) = &config.windows.webview_fixed_runtime_path {
422+
resources.push(webview_fixed_runtime_path.display().to_string());
423+
}
424+
}
425+
419426
let signing_identity = match std::env::var_os("APPLE_SIGNING_IDENTITY") {
420427
Some(signing_identity) => Some(
421428
signing_identity
@@ -481,6 +488,7 @@ fn tauri_config_to_bundle_settings(
481488
wix
482489
}),
483490
icon_path: windows_icon_path,
491+
webview_fixed_runtime_path: config.windows.webview_fixed_runtime_path,
484492
},
485493
updater: Some(UpdaterSettings {
486494
active: updater_config.active,

0 commit comments

Comments
 (0)