Skip to content

Commit 1762e98

Browse files
authored
fix: added arm64 download file (#59)
1 parent f53200c commit 1762e98

File tree

1 file changed

+86
-17
lines changed

1 file changed

+86
-17
lines changed

index.html

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap&family=Roboto+Mono:wght@400;600&display=swap"
1313
rel="stylesheet"
1414
/>
15-
<link rel="icon" href="./public/TrayNotificationIcon.svg" type="image/x-icon" />
15+
<link
16+
rel="icon"
17+
href="./public/TrayNotificationIcon.svg"
18+
type="image/x-icon"
19+
/>
1620
<script src="https://cdn.tailwindcss.com"></script>
1721
<style>
1822
body {
@@ -28,30 +32,33 @@
2832
document.addEventListener('DOMContentLoaded', async function () {
2933
const translations = {
3034
en: {
31-
description: 'Download NethLink update with bug fixes and new features.',
35+
description:
36+
'Download NethLink update with bug fixes and new features.',
3237
release: 'Release: ',
3338
downloadUpdate: 'Download update',
34-
chooseOS: 'Choose your operating system and click to start the download',
39+
chooseOS:
40+
'Choose your operating system and click to start the download',
3541
linux: 'Linux',
3642
macos: 'MacOS',
3743
windows: 'Windows',
3844
feature1: "Don't miss a single call",
3945
feature2: 'Speed dials',
40-
feature3: 'All your contacts and Phonebook'
46+
feature3: 'All your contacts and Phonebook',
4147
},
4248
it: {
4349
description:
4450
"Scarica l'aggiornamento NethLink con correzioni di bug e nuove funzionalità per le impostazioni e lo stato.",
4551
release: 'Rilascio: ',
4652
downloadUpdate: "Scarica l'aggiornamento",
47-
chooseOS: 'Scegli il tuo sistema operativo e clicca per avviare il download',
53+
chooseOS:
54+
'Scegli il tuo sistema operativo e clicca per avviare il download',
4855
linux: 'Linux',
4956
macos: 'MacOS',
5057
windows: 'Windows',
5158
feature1: 'Non perdere una chiamata',
5259
feature2: 'Numeri veloci',
53-
feature3: 'Tutti i tuoi contatti e rubrica'
54-
}
60+
feature3: 'Tutti i tuoi contatti e rubrica',
61+
},
5562
}
5663

5764
const userLang = navigator.language.startsWith('it') ? 'it' : 'en'
@@ -60,16 +67,42 @@
6067
document.getElementById('description').innerText = t.description
6168
document.getElementById('downloadUpdate').innerText = t.downloadUpdate
6269
document.getElementById('chooseOS').innerText = t.chooseOS
63-
document.getElementById('linux').querySelector('span').innerText = t.linux
64-
document.getElementById('macos').querySelector('span').innerText = t.macos
65-
document.getElementById('windows').querySelector('span').innerText = t.windows
70+
document.getElementById('linux').querySelector('span').innerText =
71+
t.linux
72+
document.getElementById('macos').querySelector('span').innerText =
73+
t.macos
74+
document.getElementById('windows').querySelector('span').innerText =
75+
t.windows
6676
document.getElementById('feature1').innerText = t.feature1
6777
document.getElementById('feature2').innerText = t.feature2
6878
document.getElementById('feature3').innerText = t.feature3
6979

80+
const getMacArchitecture = async () => {
81+
try {
82+
if (
83+
navigator.userAgentData &&
84+
typeof navigator.userAgentData.getHighEntropyValues === 'function'
85+
) {
86+
const data = await navigator.userAgentData.getHighEntropyValues([
87+
'architecture',
88+
])
89+
if (data && data.architecture) {
90+
return data.architecture === 'arm' ? 'arm64' : 'x64'
91+
}
92+
}
93+
return 'x64'
94+
} catch (error) {
95+
console.error('Error detecting Mac architecture:', error)
96+
return 'x64'
97+
}
98+
}
99+
70100
const os = navigator.userAgent
71101
let selectedElement
102+
let selectedIconDownload
72103
let currentOS
104+
let macArchitecture = 'x64'
105+
73106
if (os.indexOf('Linux') !== -1) {
74107
currentOS = 'linux'
75108
selectedElement = document.getElementById('linux')
@@ -82,6 +115,10 @@
82115
selectedIconDownload = document.getElementById('macDownloadIcon')
83116
selectedElement.classList.add('border-blue-500', 'text-white')
84117
selectedIconDownload.classList.add('text-blue-500')
118+
119+
getMacArchitecture().then((arch) => {
120+
macArchitecture = arch
121+
})
85122
} else if (os.indexOf('Windows') !== -1) {
86123
currentOS = 'windows'
87124
selectedElement = document.getElementById('windows')
@@ -106,7 +143,7 @@
106143
const fetchDownloadLinks = async () => {
107144
try {
108145
const response = await fetch(
109-
'https://api.github.com/repos/nethesis/nethlink/releases/latest'
146+
'https://api.github.com/repos/nethesis/nethlink/releases/latest',
110147
)
111148
const data = await response.json()
112149

@@ -120,7 +157,7 @@
120157
(asset.content_type === 'application/octet-stream' ||
121158
asset.content_type === 'application/x-msdownload' ||
122159
asset.content_type === 'application/x-ms-dos-executable') &&
123-
!asset.browser_download_url.endsWith('.blockmap')
160+
!asset.browser_download_url.endsWith('.blockmap'),
124161
)
125162
.reduce((acc, asset) => {
126163
const url = asset.browser_download_url
@@ -129,11 +166,34 @@
129166
} else if (url.includes('.AppImage')) {
130167
acc.linuxUrl = url
131168
} else if (url.includes('.dmg')) {
132-
acc.macosUrl = url
169+
if (url.includes('-arm64.dmg')) {
170+
acc.macosArmUrl = url
171+
} else if (url.includes('-x64.dmg')) {
172+
acc.macosX64Url = url
173+
} else {
174+
acc.macosDefaultUrl = url
175+
}
133176
}
134177
return acc
135178
}, {})
136179

180+
if (currentOS === 'macos') {
181+
if (macArchitecture === 'arm64' && downloadUrls.macosArmUrl) {
182+
downloadUrls.macosUrl = downloadUrls.macosArmUrl
183+
} else if (downloadUrls.macosX64Url) {
184+
downloadUrls.macosUrl = downloadUrls.macosX64Url
185+
} else {
186+
downloadUrls.macosUrl = downloadUrls.macosDefaultUrl
187+
}
188+
}
189+
190+
if (!downloadUrls.macosUrl) {
191+
downloadUrls.macosUrl =
192+
downloadUrls.macosDefaultUrl ||
193+
downloadUrls.macosX64Url ||
194+
downloadUrls.macosArmUrl
195+
}
196+
137197
return downloadUrls
138198
} catch (error) {
139199
console.error('Cannot retrieve download url', error)
@@ -144,14 +204,19 @@
144204
const downloadLinks = await fetchDownloadLinks()
145205
document.getElementById('linux').href = downloadLinks.linuxUrl || '#'
146206
document.getElementById('macos').href = downloadLinks.macosUrl || '#'
147-
document.getElementById('windows').href = downloadLinks.windowsUrl || '#'
207+
document.getElementById('windows').href =
208+
downloadLinks.windowsUrl || '#'
148209
})
149210
</script>
150211
</head>
151212
<body class="flex items-center justify-center h-screen">
152213
<div class="bg-gray-950 py-14 px-12 rounded-2xl shadow-lg w-full max-w-4xl">
153214
<div class="text-left mb-16 text-gray-200">
154-
<img src="./public/Nethlink-logo.svg" alt="Nethlink logo" class="mb-4 w-36" />
215+
<img
216+
src="./public/Nethlink-logo.svg"
217+
alt="Nethlink logo"
218+
class="mb-4 w-36"
219+
/>
155220
<p id="description" class="mb-1"></p>
156221
<p id="release" class="mb-4"></p>
157222
</div>
@@ -168,7 +233,9 @@
168233
<i class="fab fa-linux mr-2 fa-xl"></i> <span></span>
169234
</div>
170235
<div class="download-text" id="linuxDownloadIcon">
171-
<i class="fa-solid fa-circle-arrow-down fa-xl hover:text-blue-500"></i>
236+
<i
237+
class="fa-solid fa-circle-arrow-down fa-xl hover:text-blue-500"
238+
></i>
172239
</div>
173240
</a>
174241
<a
@@ -192,7 +259,9 @@
192259
<i class="fab fa-windows mr-2 fa-xl"></i> <span></span>
193260
</div>
194261
<div class="download-text" id="windowsDownloadIcon">
195-
<i class="fa-solid fa-circle-arrow-down fa-xl hover:text-blue-500"></i>
262+
<i
263+
class="fa-solid fa-circle-arrow-down fa-xl hover:text-blue-500"
264+
></i>
196265
</div>
197266
</a>
198267
</div>

0 commit comments

Comments
 (0)