Skip to content

Commit 2ca762d

Browse files
feat(bundler): extend webview2 installation options, closes #2882 #2452 (#4466)
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
1 parent 3efbc67 commit 2ca762d

File tree

16 files changed

+497
-102
lines changed

16 files changed

+497
-102
lines changed

.changes/webview-install-mode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-utils": patch
3+
"tauri-bundler": patch
4+
---
5+
6+
Added webview install mode options.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl From<NativeImage> for NativeImageWrapper {
482482
}
483483
}
484484

485-
/// Wrapper around a [`wry::application::window::Icon`] that can be created from an [`WindowIcon`].
485+
/// Wrapper around a [`wry::application::window::Icon`] that can be created from an [`Icon`].
486486
pub struct WryIcon(WryWindowIcon);
487487

488488
fn icon_err<E: std::error::Error + Send + Sync + 'static>(e: E) -> Error {

core/tauri-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl SystemTray {
5454
self.menu.as_ref()
5555
}
5656

57-
/// Sets the tray icon. Must be a [`TrayIcon::File`] on Linux and a [`TrayIcon::Raw`] on Windows and macOS.
57+
/// Sets the tray icon.
5858
#[must_use]
5959
pub fn with_icon(mut self, icon: Icon) -> Self {
6060
self.icon.replace(icon);

core/tauri-utils/src/config.rs

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ pub struct WixConfig {
384384
#[serde(default)]
385385
pub merge_refs: Vec<String>,
386386
/// Disables the Webview2 runtime installation after app install.
387+
///
388+
/// Will be removed in v2, prefer the [`WindowsConfig::webview_install_mode`] option.
387389
#[serde(default)]
388390
pub skip_webview_install: bool,
389391
/// The path to the license file to render on the installer.
@@ -405,6 +407,61 @@ pub struct WixConfig {
405407
pub dialog_image_path: Option<PathBuf>,
406408
}
407409

410+
/// Install modes for the Webview2 runtime.
411+
/// Note that for the updater bundle [`Self::DownloadBootstrapper`] is used.
412+
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
413+
#[serde(tag = "type", rename_all = "camelCase", deny_unknown_fields)]
414+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
415+
pub enum WebviewInstallMode {
416+
/// Do not install the Webview2 as part of the Windows Installer.
417+
Skip,
418+
/// Download the bootstrapper and run it.
419+
/// Requires internet connection.
420+
/// Results in a smaller installer size, but is not recommended on Windows 7.
421+
DownloadBootstrapper {
422+
/// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
423+
#[serde(default = "default_webview_install_silent")]
424+
silent: bool,
425+
},
426+
/// Embed the bootstrapper and run it.
427+
/// Requires internet connection.
428+
/// Increases the installer size by around 1.8MB, but offers better support on Windows 7.
429+
EmbedBootstrapper {
430+
/// Instructs the installer to run the bootstrapper in silent mode. Defaults to `true`.
431+
#[serde(default = "default_webview_install_silent")]
432+
silent: bool,
433+
},
434+
/// Embed the offline installer and run it.
435+
/// Does not require internet connection.
436+
/// Increases the installer size by around 127MB.
437+
OfflineInstaller {
438+
/// Instructs the installer to run the installer in silent mode. Defaults to `true`.
439+
#[serde(default = "default_webview_install_silent")]
440+
silent: bool,
441+
},
442+
/// Embed a fixed webview2 version and use it at runtime.
443+
/// Increases the installer size by around 180MB.
444+
FixedRuntime {
445+
/// The path to the fixed runtime to use.
446+
///
447+
/// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
448+
/// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
449+
path: PathBuf,
450+
},
451+
}
452+
453+
fn default_webview_install_silent() -> bool {
454+
true
455+
}
456+
457+
impl Default for WebviewInstallMode {
458+
fn default() -> Self {
459+
Self::DownloadBootstrapper {
460+
silent: default_webview_install_silent(),
461+
}
462+
}
463+
}
464+
408465
/// Windows bundler configuration.
409466
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
410467
#[cfg_attr(feature = "schema", derive(JsonSchema))]
@@ -421,7 +478,12 @@ pub struct WindowsConfig {
421478
/// use a TSP timestamp server, like e.g. SSL.com does. If so, enable TSP by setting to true.
422479
#[serde(default)]
423480
pub tsp: bool,
424-
/// Path to the webview fixed runtime to use.
481+
/// The installation mode for the Webview2 runtime.
482+
#[serde(default)]
483+
pub webview_install_mode: WebviewInstallMode,
484+
/// Path to the webview fixed runtime to use. Overwrites [`Self::webview_install_mode`] if set.
485+
///
486+
/// Will be removed in v2, prefer the [`Self::webview_install_mode`] option.
425487
///
426488
/// The fixed version can be downloaded [on the official website](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).
427489
/// The `.cab` file must be extracted to a folder and this folder path must be defined on this field.
@@ -444,6 +506,7 @@ impl Default for WindowsConfig {
444506
certificate_thumbprint: None,
445507
timestamp_url: None,
446508
tsp: false,
509+
webview_install_mode: Default::default(),
447510
webview_fixed_runtime_path: None,
448511
allow_downgrades: default_allow_downgrades(),
449512
wix: None,
@@ -2873,17 +2936,41 @@ mod build {
28732936
}
28742937
}
28752938

2939+
impl ToTokens for WebviewInstallMode {
2940+
fn to_tokens(&self, tokens: &mut TokenStream) {
2941+
let prefix = quote! { ::tauri::utils::config::WebviewInstallMode };
2942+
2943+
tokens.append_all(match self {
2944+
Self::Skip => quote! { #prefix::Skip },
2945+
Self::DownloadBootstrapper { silent } => {
2946+
quote! { #prefix::DownloadBootstrapper { silent: #silent } }
2947+
}
2948+
Self::EmbedBootstrapper { silent } => {
2949+
quote! { #prefix::EmbedBootstrapper { silent: #silent } }
2950+
}
2951+
Self::OfflineInstaller { silent } => {
2952+
quote! { #prefix::OfflineInstaller { silent: #silent } }
2953+
}
2954+
Self::FixedRuntime { path } => {
2955+
let path = path_buf_lit(&path);
2956+
quote! { #prefix::FixedRuntime { path: #path } }
2957+
}
2958+
})
2959+
}
2960+
}
2961+
28762962
impl ToTokens for WindowsConfig {
28772963
fn to_tokens(&self, tokens: &mut TokenStream) {
2878-
let webview_fixed_runtime_path = opt_lit(
2879-
self
2880-
.webview_fixed_runtime_path
2881-
.as_ref()
2882-
.map(path_buf_lit)
2883-
.as_ref(),
2884-
);
2964+
let webview_install_mode = if let Some(fixed_runtime_path) = &self.webview_fixed_runtime_path
2965+
{
2966+
WebviewInstallMode::FixedRuntime {
2967+
path: fixed_runtime_path.clone(),
2968+
}
2969+
} else {
2970+
self.webview_install_mode.clone()
2971+
};
28852972
tokens.append_all(quote! { ::tauri::utils::config::WindowsConfig {
2886-
webview_fixed_runtime_path: #webview_fixed_runtime_path,
2973+
webview_install_mode: #webview_install_mode,
28872974
..Default::default()
28882975
}})
28892976
}

core/tauri/src/app.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,16 +1441,19 @@ impl<R: Runtime> Builder<R> {
14411441

14421442
#[cfg(windows)]
14431443
{
1444-
if let Some(w) = &app
1444+
if let crate::utils::config::WebviewInstallMode::FixedRuntime { path } = &app
14451445
.manager
14461446
.config()
14471447
.tauri
14481448
.bundle
14491449
.windows
1450-
.webview_fixed_runtime_path
1450+
.webview_install_mode
14511451
{
14521452
if let Some(resource_dir) = app.path_resolver().resource_dir() {
1453-
std::env::set_var("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", resource_dir.join(w));
1453+
std::env::set_var(
1454+
"WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",
1455+
resource_dir.join(path),
1456+
);
14541457
} else {
14551458
#[cfg(debug_assertions)]
14561459
eprintln!(

examples/api/dist/assets/index.js

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/dist/assets/vendor.js

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
svelte-hmr "^0.14.7"
2424

2525
"@tauri-apps/api@../../tooling/api/dist":
26-
version "1.0.0"
26+
version "1.0.0-rc.6"
2727
dependencies:
28-
type-fest "2.13.1"
28+
type-fest "2.13.0"
2929

3030
"@zerodevx/svelte-json-view@0.2.0":
3131
version "0.2.0"
@@ -267,10 +267,10 @@ svelte@3.35.0:
267267
resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.35.0.tgz#e0d0ba60c4852181c2b4fd851194be6fda493e65"
268268
integrity sha512-gknlZkR2sXheu/X+B7dDImwANVvK1R0QGQLd8CNIfxxGPeXBmePnxfzb6fWwTQRsYQG7lYkZXvpXJvxvpsoB7g==
269269

270-
type-fest@2.13.1:
271-
version "2.13.1"
272-
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.13.1.tgz#621c84220df0e01a8469002594fc005714f0cfba"
273-
integrity sha512-hXYyrPFwETT2swFLHeoKtJrvSF/ftG/sA15/8nGaLuaDGfVAaq8DYFpu4yOyV4tzp082WqnTEoMsm3flKMI2FQ==
270+
type-fest@2.13.0:
271+
version "2.13.0"
272+
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.13.0.tgz#d1ecee38af29eb2e863b22299a3d68ef30d2abfb"
273+
integrity sha512-lPfAm42MxE4/456+QyIaaVBAwgpJb6xZ8PRu09utnhPdWwcyj9vgy6Sq0Z5yNbJ21EdxB5dRU/Qg8bsyAMtlcw==
274274

275275
vite@^2.6.4:
276276
version "2.6.14"

tooling/bundler/src/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
4949
#[cfg(target_os = "macos")]
5050
PackageType::IosBundle => macos::ios::bundle_project(&settings)?,
5151
#[cfg(target_os = "windows")]
52-
PackageType::WindowsMsi => windows::msi::bundle_project(&settings)?,
52+
PackageType::WindowsMsi => windows::msi::bundle_project(&settings, false)?,
5353
#[cfg(target_os = "linux")]
5454
PackageType::Deb => linux::debian::bundle_project(&settings)?,
5555
#[cfg(target_os = "linux")]

tooling/bundler/src/bundle/settings.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use super::category::AppCategory;
66
use crate::bundle::{common, platform::target_triple};
7+
pub use tauri_utils::config::WebviewInstallMode;
78
use tauri_utils::{
89
config::BundleType,
910
resources::{external_binaries, ResourcePaths},
@@ -186,7 +187,7 @@ pub struct MacOsSettings {
186187
/// Configuration for a target language for the WiX build.
187188
#[derive(Debug, Clone, Default)]
188189
pub struct WixLanguageConfig {
189-
/// The path to a locale (`.wxl`) file. See https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html.
190+
/// The path to a locale (`.wxl`) file. See <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>.
190191
pub locale_path: Option<PathBuf>,
191192
}
192193

@@ -203,7 +204,7 @@ impl Default for WixLanguage {
203204
/// Settings specific to the WiX implementation.
204205
#[derive(Clone, Debug, Default)]
205206
pub struct WixSettings {
206-
/// The app languages to build. See https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables.
207+
/// The app languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
207208
pub language: WixLanguage,
208209
/// By default, the bundler uses an internal template.
209210
/// This option allows you to define your own wix file.
@@ -220,7 +221,7 @@ pub struct WixSettings {
220221
pub feature_refs: Vec<String>,
221222
/// The Merge element ids you want to reference from the fragments.
222223
pub merge_refs: Vec<String>,
223-
/// Disables the Webview2 runtime installation after app install.
224+
/// Disables the Webview2 runtime installation after app install. Will be removed in v2, use [`WindowsSettings::webview_install_mode`] instead.
224225
pub skip_webview_install: bool,
225226
/// The path to the LICENSE file.
226227
pub license: Option<PathBuf>,
@@ -254,7 +255,13 @@ pub struct WindowsSettings {
254255
pub wix: Option<WixSettings>,
255256
/// The path to the application icon. Defaults to `./icons/icon.ico`.
256257
pub icon_path: PathBuf,
258+
/// The installation mode for the Webview2 runtime.
259+
pub webview_install_mode: WebviewInstallMode,
257260
/// Path to the webview fixed runtime to use.
261+
///
262+
/// Overwrites [`Self::webview_install_mode`] if set.
263+
///
264+
/// Will be removed in v2, use [`Self::webview_install_mode`] instead.
258265
pub webview_fixed_runtime_path: Option<PathBuf>,
259266
/// Validates a second app installation, blocking the user from installing an older version if set to `false`.
260267
///
@@ -273,6 +280,7 @@ impl Default for WindowsSettings {
273280
tsp: false,
274281
wix: None,
275282
icon_path: PathBuf::from("icons/icon.ico"),
283+
webview_install_mode: Default::default(),
276284
webview_fixed_runtime_path: None,
277285
allow_downgrades: true,
278286
}
@@ -301,7 +309,7 @@ pub struct BundleSettings {
301309
/// the app's long description.
302310
pub long_description: Option<String>,
303311
// Bundles for other binaries:
304-
/// Configuration map for the possible [bin] apps to bundle.
312+
/// Configuration map for the apps to bundle.
305313
pub bin: Option<HashMap<String, BundleSettings>>,
306314
/// External binaries to add to the bundle.
307315
///
@@ -316,7 +324,7 @@ pub struct BundleSettings {
316324
/// If you are building a universal binary for MacOS, the bundler expects
317325
/// your external binary to also be universal, and named after the target triple,
318326
/// e.g. `sqlite3-universal-apple-darwin`. See
319-
/// https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary
327+
/// <https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary>
320328
pub external_bin: Option<Vec<String>>,
321329
/// Debian-specific settings.
322330
pub deb: DebianSettings,

0 commit comments

Comments
 (0)