From e506d76e760facc86e32e060179554472d1fb802 Mon Sep 17 00:00:00 2001 From: Xyntho Date: Thu, 9 Jan 2025 23:40:48 +0530 Subject: [PATCH] fix logic for win11 detection --- src/components/VencordSettings/VencordTab.tsx | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index d0995f964..269b04c2d 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -48,6 +48,21 @@ type KeysOfType = { function VencordSettings() { + /* + we need to detect win11 for background material, + which is not supported by win 10 + https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-windows-11 + */ + const [isWindows11, , isWindows11Pending] = useAwaiter(async () => { + if ( + !navigator?.userAgentData || + navigator?.userAgentData?.platform !== "Windows" + ) return false; + + const ua = await navigator.userAgentData.getHighEntropyValues(["platformVersion"]); + const majorPlatformVersion = parseInt(ua?.platformVersion?.split(".")[0]!, 10); + return majorPlatformVersion >= 13; + }, { fallbackValue: false }); const [settingsDir, , settingsDirPending] = useAwaiter(VencordNative.settings.getSettingsDir, { fallbackValue: "Loading..." }); @@ -58,24 +73,6 @@ function VencordSettings() { const isWindows = navigator.platform.toLowerCase().startsWith("win"); const isMac = navigator.platform.toLowerCase().startsWith("mac"); const needsVibrancySettings = IS_DISCORD_DESKTOP && isMac; - - /* - we need to detect win11 for background material, - which is not supported by win 10 - https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#sample-code-for-detecting-windows-11 - */ - let isWindows11 = false; - navigator?.userAgentData?.getHighEntropyValues(["platformVersion"]) - .then(ua => { - if (isWindows) { - const majorPlatformVersion = parseInt( - ua?.platformVersion?.split(".")[0]! - ); - if (majorPlatformVersion >= 13) { - isWindows11 = true; - } - } - }); const needsBackgroundMaterial = IS_DISCORD_DESKTOP && isWindows11; const Switches: Array } +