Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions _scripts/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,57 @@ export function detectedOS () {
}
return 'Unknown'
}

/**
* detectedArchitecture
* Returns the architecture of the user's device using User-Agent Client Hints API
*
* @return {Promise<String>} - Architecture of the user (ARM or x86)
*/
export async function detectedArchitecture () {
// Try to use the modern User-Agent Client Hints API first
if (navigator.userAgentData && navigator.userAgentData.getHighEntropyValues) {
try {
const values = await navigator.userAgentData.getHighEntropyValues(['architecture'])

if (values.architecture) {
const arch = values.architecture.toLowerCase()
if (arch.indexOf('arm') >= 0) {
return 'ARM'
}
if (arch.indexOf('x86') >= 0) {
return 'x86'
}
}
} catch (e) {
// Fall through to legacy detection
}
}

// Fallback to legacy user agent parsing
const ua = window.navigator.userAgent
if (ua == null || ua === false) return 'Unknown'

// Check for ARM indicators in user agent
if (ua.indexOf('ARM') >= 0 || ua.indexOf('aarch64') >= 0 || ua.indexOf('arm64') >= 0) {
return 'ARM'
}

// Check for x86/x64 indicators
if (ua.indexOf('x86') >= 0 || ua.indexOf('x64') >= 0 || ua.indexOf('WOW64') >= 0 || ua.indexOf('Win64') >= 0 || ua.indexOf('Intel Mac') >= 0) {
return 'x86'
}

// Additional platform checks
if (navigator.platform) {
const platform = navigator.platform.toLowerCase()
if (platform.indexOf('arm') >= 0 || platform.indexOf('aarch') >= 0) {
return 'ARM'
}
if (platform.indexOf('x86') >= 0 || platform.indexOf('win') >= 0 || platform.indexOf('mac') >= 0 || platform.indexOf('linux') >= 0) {
return 'x86'
}
}

return 'Unknown'
}
6 changes: 3 additions & 3 deletions _scripts/pages/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import jQuery from '~/lib/jquery'

import { detectedOS } from '~/page'
import { detectedArchitecture } from '~/page'
import config from '~/config'

import { openDownloadOverlay } from '~/widgets/download-modal'
Expand Down Expand Up @@ -132,7 +132,7 @@ Promise.all([config, jQuery, openDownloadOverlay]).then(([config, $, openDownloa
})

// ACTION: .download-http.click: Track downloads
$('.download-link').click(function () {
$('.download-link').click(async function () {
let downloadMethod = 'Unknown'
if ($(this).hasClass('magnet')) {
downloadMethod = 'Magnet'
Expand All @@ -144,7 +144,7 @@ Promise.all([config, jQuery, openDownloadOverlay]).then(([config, $, openDownloa
props: {
Region: config.user.region,
Method: downloadMethod,
OS: detectedOS(),
Architecture: await detectedArchitecture(),
Version: config.release.version
}
})
Expand Down
6 changes: 3 additions & 3 deletions _scripts/previous.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import jQuery from '~/lib/jquery'

import config from '~/config'
import { detectedOS } from '~/page'
import { detectedArchitecture } from '~/page'

Promise.all([config, jQuery]).then(([config, $]) => {
$(document).ready(() => {
// ACTION: .download-http.click: Track download over HTTP
$('.download-link').click(function () {
$('.download-link').click(async function () {
let downloadMethod = 'Unknown'
if ($(this).hasClass('magnet')) {
downloadMethod = 'Magnet'
Expand All @@ -25,7 +25,7 @@ Promise.all([config, jQuery]).then(([config, $]) => {
props: {
Region: config.user.region,
Method: downloadMethod,
OS: detectedOS(),
Architecture: await detectedArchitecture(),
Version: config.previous.version
}
})
Expand Down
Loading