Skip to content

Commit 001bdcb

Browse files
author
Maledong
authored
fix: windows 11 cannot detect CPU processor successfully (#5125)
Refs: 1. #5028. 2. #5025. Due to the author doesn't have free time to fix this, I'd like to help.
1 parent bad4449 commit 001bdcb

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

public/static/js/legacyMain.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,43 @@ const listenScrollToTopButton = () => {
8080
});
8181
};
8282

83-
const detectEnviromentAndSetDownloadOptions = () => {
83+
const detectEnviromentAndSetDownloadOptions = async () => {
8484
const userAgent = navigator.userAgent;
85+
const userAgentData = navigator.userAgentData;
8586
const osMatch = userAgent.match(/(Win|Mac|Linux)/);
86-
8787
const os = (osMatch && osMatch[1]) || '';
8888

89-
const arch =
90-
userAgent.match(/x86_64|Win64|WOW64/) || navigator.cpuClass === 'x64'
91-
? 'x64'
92-
: 'x86';
89+
// detects the architecture through regular ways on user agents that
90+
// expose the architecture and platform information
91+
// @note this is not available on Windows11 anymore
92+
// @see https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
93+
let arch = userAgent.match(/x86_64|Win64|WOW64/) ? 'x64' : 'x86';
94+
95+
// detects the platform through a legacy property on navigator
96+
// available only on firefox
97+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/oscpu
98+
if (navigator.oscpu && navigator.oscpu.length) {
99+
arch = navigator.oscpu.match(/x86_64|Win64|WOW64/) ? 'x64' : 'x86';
100+
}
101+
102+
// detects the platform through a legacy property on navigator
103+
// only available on internet explorer
104+
if (navigator.cpuClass && navigator.cpuClass.length) {
105+
arch = navigator.cpuClass === 'x64' ? 'x64' : 'x86';
106+
}
107+
108+
// detects the architecture and other platform data on the navigator
109+
// available only on Chromium-based browsers
110+
// @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues
111+
if (userAgentData && userAgentData.getHighEntropyValues) {
112+
// note that getHighEntropyValues returns an object
113+
const platform = await userAgentData.getHighEntropyValues(['bitness']);
114+
115+
if (platform && platform.bitness) {
116+
// note that platform.bitness returns a string
117+
arch = platform.bitness === '64' ? 'x64' : 'x86';
118+
}
119+
}
93120

94121
const buttons = document.querySelectorAll('.home-downloadbutton');
95122
const downloadHead = document.querySelector('#home-downloadhead');

0 commit comments

Comments
 (0)