From bca09f7f5ff1c9c5a4b51da043bdd5da668a179b Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 14 Dec 2022 17:18:46 +0200 Subject: [PATCH] feat(tauri-build): add option to specify Windows manifest, closes #5584 (#5730) Co-authored-by: Lucas Nogueira --- .changes/tauri-build-windows-manifest.md | 5 ++ core/tauri-build/src/lib.rs | 71 +++++++++++++++----- core/tauri-build/src/window-app-manifest.xml | 14 ++++ 3 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 .changes/tauri-build-windows-manifest.md create mode 100644 core/tauri-build/src/window-app-manifest.xml diff --git a/.changes/tauri-build-windows-manifest.md b/.changes/tauri-build-windows-manifest.md new file mode 100644 index 00000000000..29605ee5642 --- /dev/null +++ b/.changes/tauri-build-windows-manifest.md @@ -0,0 +1,5 @@ +--- +"tauri-build": "minor" +--- + +Add `WindowsAttributes::app_manifest` to specify the application manifest on Windows. diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index a3cb65c3970..3ab1f465266 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -110,6 +110,15 @@ pub struct WindowsAttributes { /// /// If it is left unset, it will look up a path in the registry, i.e. HKLM\SOFTWARE\Microsoft\Windows Kits\Installed Roots sdk_dir: Option, + /// A string containing an [application manifest] to be included with the application on Windows. + /// + /// Defaults to: + /// ```ignore + #[doc = include_str!("window-app-manifest.xml")] + /// ``` + /// + /// [application manifest]: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests + app_manifest: Option, } impl WindowsAttributes { @@ -135,6 +144,45 @@ impl WindowsAttributes { self.sdk_dir = Some(sdk_dir.as_ref().into()); self } + + /// Sets the Windows app [manifest]. + /// + /// # Example + /// + /// The following manifest will brand the exe as requesting administrator privileges. + /// Thus, everytime it is executed, a Windows UAC dialog will appear. + /// + /// Note that you can move the manifest contents to a separate file and use `include_str!("manifest.xml")` + /// instead of the inline string. + /// + /// ```rust,no_run + /// let mut windows = tauri_build::WindowsAttributes::new(); + /// windows = windows.app_manifest(r#" + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// "#); + /// tauri_build::try_build( + /// tauri_build::Attributes::new().windows_attributes(windows) + /// ).expect("failed to run build script"); + /// ``` + /// + /// Defaults to: + /// ```ignore + #[doc = include_str!("window-app-manifest.xml")] + /// [manifest]: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests + /// ``` + #[must_use] + pub fn app_manifest>(mut self, manifest: S) -> Self { + self.app_manifest = Some(manifest.as_ref().to_string()); + self + } } /// The attributes used on the build. @@ -336,24 +384,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> { if window_icon_path.exists() { let mut res = WindowsResource::new(); - res.set_manifest( - r#" - - - - - - - - "#, - ); + if let Some(manifest) = attributes.windows_attributes.app_manifest { + res.set_manifest(&manifest); + } else { + res.set_manifest(include_str!("window-app-manifest.xml")); + } if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir { if let Some(sdk_dir_str) = sdk_dir.to_str() { diff --git a/core/tauri-build/src/window-app-manifest.xml b/core/tauri-build/src/window-app-manifest.xml new file mode 100644 index 00000000000..2d510ed314a --- /dev/null +++ b/core/tauri-build/src/window-app-manifest.xml @@ -0,0 +1,14 @@ + + + + + + +