Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix(desktop): add win version checks for DWM attr api (#5010)
Shreyas93787f8389d6
diff --git a/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/ui/windows/posit.rs b/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/ui/windows/posit.rsindex 2ecfb4c28..e957c3652 100644--- a/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/ui/windows/posit.rs+++ b/packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/ui/windows/posit.rs@@ -12,6 +12,19 @@ use windows::Win32::{};use winver::WindowsVersion;+// Windows 11 Build 22000 is the minimum version required for+// DWMWA_USE_IMMERSIVE_DARK_MODE and DWMWA_CAPTION_COLOR.+//+// According to Microsoft documentation:+// https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute+//+// "DWMWA_USE_IMMERSIVE_DARK_MODE: Use with DwmSetWindowAttribute.+// [...] This value is supported starting with Windows 11 Build 22000."+//+// "DWMWA_CAPTION_COLOR: Use with DwmSetWindowAttribute.+// [...] This value is supported starting with Windows 11 Build 22000."+const MIN_WIN11_BUILD: u32 = 22000;+#[derive(Debug)]pub struct WindowsWindow<R: Runtime> {window: WebviewWindow<R>,@@ -51,30 +64,32 @@ impl<R: Runtime> WindowsWindow<R> {}fn set_dark_mode(&self) {- unsafe {- let use_dark_mode = BOOL::from(true);- DwmSetWindowAttribute(- self.hwnd,- DWMWA_USE_IMMERSIVE_DARK_MODE,- ptr::addr_of!(use_dark_mode) as *const c_void,- size_of::<BOOL>().try_into().unwrap(),- )- .expect("Failed to set dark mode");+ if let Some(version) = WindowsVersion::detect() {+ if version.major() >= 10 && version.build() >= MIN_WIN11_BUILD {+ unsafe {+ let use_dark_mode = BOOL::from(true);+ let _ = DwmSetWindowAttribute(+ self.hwnd,+ DWMWA_USE_IMMERSIVE_DARK_MODE,+ ptr::addr_of!(use_dark_mode) as *const c_void,+ size_of::<BOOL>().try_into().unwrap(),+ );+ }+ }}}fn set_caption_color(&self, color: HexColor) {if let Some(version) = WindowsVersion::detect() {- if version >= WindowsVersion::new(10, 0, 22000) {+ if version.major() >= 10 && version.build() >= MIN_WIN11_BUILD {unsafe {let color_ref = self.hex_color_to_colorref(color);- DwmSetWindowAttribute(+ let _ = DwmSetWindowAttribute(self.hwnd,DWMWA_CAPTION_COLOR,ptr::addr_of!(color_ref) as *const c_void,size_of::<COLORREF>().try_into().unwrap(),- )- .expect("Failed to set caption color");+ );}}}diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.lock b/packages/hoppscotch-desktop/src-tauri/Cargo.lockindex b636f5dc2..a288666d6 100644--- a/packages/hoppscotch-desktop/src-tauri/Cargo.lock+++ b/packages/hoppscotch-desktop/src-tauri/Cargo.lock@@ -4972,7 +4972,7 @@ dependencies = [[[package]]name = "tauri-plugin-appload"version = "0.1.0"-source = "git+https://github.com/CuriousCorrelation/tauri-plugin-appload#1c2e8b19db7f1b6af6d00abb907f15cdc2017298"+source = "git+https://github.com/CuriousCorrelation/tauri-plugin-appload#c191e3de23a078b51103dd6fa60259b72f8b1443"dependencies = ["base64 0.22.1","blake3",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex bfd0987ec..9b10fbcf0 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -520,7 +520,7 @@ importers:version: link:../hoppscotch-kernel'@hoppscotch/plugin-appload':specifier: github:CuriousCorrelation/tauri-plugin-appload- version: '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1c2e8b19db7f1b6af6d00abb907f15cdc2017298'+ version: '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/c191e3de23a078b51103dd6fa60259b72f8b1443''@hoppscotch/ui':specifier: 0.2.2version: 0.2.2([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected]))([email protected]([email protected]))@@ -978,7 +978,7 @@ importers:version: link:../hoppscotch-kernel'@hoppscotch/plugin-appload':specifier: github:CuriousCorrelation/tauri-plugin-appload- version: '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1c2e8b19db7f1b6af6d00abb907f15cdc2017298'+ version: '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/c191e3de23a078b51103dd6fa60259b72f8b1443''@hoppscotch/ui':specifier: 0.2.1version: 0.2.1([email protected]([email protected]))([email protected])([email protected])([email protected](@types/[email protected])([email protected])([email protected]))([email protected]([email protected]))@@ -1806,8 +1806,8 @@ packages:graphql:optional: true- '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1c2e8b19db7f1b6af6d00abb907f15cdc2017298':- resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1c2e8b19db7f1b6af6d00abb907f15cdc2017298}+ '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/c191e3de23a078b51103dd6fa60259b72f8b1443':+ resolution: {tarball: https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/c191e3de23a078b51103dd6fa60259b72f8b1443}version: 0.1.0'@CuriousCorrelation/plugin-relay@https://codeload.github.com/CuriousCorrelation/tauri-plugin-relay/tar.gz/68d6b2532c900b4be24a038c49eec4794e990a3d':@@ -13204,7 +13204,7 @@ snapshots:optionalDependencies:graphql: 16.9.0- '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/1c2e8b19db7f1b6af6d00abb907f15cdc2017298':+ '@CuriousCorrelation/plugin-appload@https://codeload.github.com/CuriousCorrelation/tauri-plugin-appload/tar.gz/c191e3de23a078b51103dd6fa60259b72f8b1443':dependencies:'@tauri-apps/api': 2.1.1