From 4c58b4f414fb7e1d235a481d70c4688c59b39a37 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Wed, 30 Nov 2022 17:37:05 +0200 Subject: [PATCH 1/4] feat(tauri-build): add option to specify Windows manifest, closes #5584 --- .changes/cli-no-dev-server.md | 2 +- .changes/tauri-build-windows-manifest.md | 7 ++++ core/tauri-build/src/lib.rs | 41 ++++++++++++-------- core/tauri-build/src/window-app-manifest.xml | 14 +++++++ 4 files changed, 47 insertions(+), 17 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/cli-no-dev-server.md b/.changes/cli-no-dev-server.md index 8bbba444929..ecd3e3417f6 100644 --- a/.changes/cli-no-dev-server.md +++ b/.changes/cli-no-dev-server.md @@ -1,5 +1,5 @@ --- -"cli.rs": "patch" +"cli.rs": "minor" --- Add `--no-dev-server` flag to the cli to disable the dev server for static files in dev mode. diff --git a/.changes/tauri-build-windows-manifest.md b/.changes/tauri-build-windows-manifest.md new file mode 100644 index 00000000000..fe96a9f14d0 --- /dev/null +++ b/.changes/tauri-build-windows-manifest.md @@ -0,0 +1,7 @@ +--- +"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..ff84c5c8249 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: + /// ``` + #[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,18 @@ impl WindowsAttributes { self.sdk_dir = Some(sdk_dir.as_ref().into()); self } + + /// Sets the app manifest. Currently only used on Windows. + /// + /// Defaults to: + /// ``` + #[doc = include_str!("window-app-manifest.xml")] + /// ``` + #[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. @@ -337,22 +358,10 @@ pub fn try_build(attributes: Attributes) -> Result<()> { let mut res = WindowsResource::new(); res.set_manifest( - r#" - - - - - - - - "#, + &attributes + .windows_attributes + .app_manifest + .unwrap_or(include_str!("window-app-manifest.xml").to_string()), ); if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir { 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 @@ + + + + + + + From fc00bea43853fb2ed4597182225cf014be921d14 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Wed, 30 Nov 2022 18:17:09 +0200 Subject: [PATCH 2/4] fix tests --- core/tauri-build/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index ff84c5c8249..3f3bda33664 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -113,7 +113,7 @@ pub struct WindowsAttributes { /// A string containing an [application manifest] to be included with the application on Windows. /// /// Defaults to: - /// ``` + /// ```ignore #[doc = include_str!("window-app-manifest.xml")] /// ``` /// @@ -148,7 +148,7 @@ impl WindowsAttributes { /// Sets the app manifest. Currently only used on Windows. /// /// Defaults to: - /// ``` + /// ```ignore #[doc = include_str!("window-app-manifest.xml")] /// ``` #[must_use] From ca56bf40e8dbb4ebf85ebfa28f3ce48f1bbaa5d0 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 14 Dec 2022 15:06:46 +0200 Subject: [PATCH 3/4] Delete cli-no-dev-server.md --- .changes/cli-no-dev-server.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changes/cli-no-dev-server.md diff --git a/.changes/cli-no-dev-server.md b/.changes/cli-no-dev-server.md deleted file mode 100644 index ecd3e3417f6..00000000000 --- a/.changes/cli-no-dev-server.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"cli.rs": "minor" ---- - -Add `--no-dev-server` flag to the cli to disable the dev server for static files in dev mode. From af0c449889e4ee97e1156215efd91aaa97b3c894 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 14 Dec 2022 12:03:06 -0300 Subject: [PATCH 4/4] enhance docs, avoid allocation --- .changes/tauri-build-windows-manifest.md | 2 -- core/tauri-build/src/lib.rs | 40 +++++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.changes/tauri-build-windows-manifest.md b/.changes/tauri-build-windows-manifest.md index fe96a9f14d0..29605ee5642 100644 --- a/.changes/tauri-build-windows-manifest.md +++ b/.changes/tauri-build-windows-manifest.md @@ -3,5 +3,3 @@ --- 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 3f3bda33664..3ab1f465266 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -145,11 +145,38 @@ impl WindowsAttributes { self } - /// Sets the app manifest. Currently only used on Windows. + /// 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 { @@ -357,12 +384,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> { if window_icon_path.exists() { let mut res = WindowsResource::new(); - res.set_manifest( - &attributes - .windows_attributes - .app_manifest - .unwrap_or(include_str!("window-app-manifest.xml").to_string()), - ); + 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() {