mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(website): basic platform detection
This commit is contained in:
parent
cb6cb97326
commit
65e207648b
49
apps/website/src/lib/download-helper.ts
Normal file
49
apps/website/src/lib/download-helper.ts
Normal file
@ -0,0 +1,49 @@
|
||||
function getArchitecture() {
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
if (userAgent.includes('x86_64') || userAgent.includes('x64') || userAgent.includes('amd64')) {
|
||||
return 'x64';
|
||||
} else if (userAgent.includes('arm64') || userAgent.includes('aarch64')) {
|
||||
return 'arm64';
|
||||
}
|
||||
}
|
||||
|
||||
function getPlatform() {
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
if (userAgent.includes('macintosh') || userAgent.includes('mac os x')) {
|
||||
return "mac";
|
||||
} else if (userAgent.includes('windows') || userAgent.includes('win32')) {
|
||||
return "windows";
|
||||
} else {
|
||||
return "linux";
|
||||
}
|
||||
}
|
||||
|
||||
function getDownloadLink(platform: string, architecture: string) {
|
||||
const baseUrl = 'https://example.com/downloads';
|
||||
let url;
|
||||
if (platform === 'mac') {
|
||||
url = `${baseUrl}/mac-${architecture}.dmg`;
|
||||
} else if (platform === 'windows') {
|
||||
url = `${baseUrl}/windows-${architecture}.exe`;
|
||||
} else if (platform === 'linux') {
|
||||
url = `${baseUrl}/linux-${architecture}.tar.gz`;
|
||||
} else {
|
||||
url = `${baseUrl}/other-${architecture}.zip`;
|
||||
}
|
||||
|
||||
return {
|
||||
url: url,
|
||||
platform: platform,
|
||||
architecture: architecture
|
||||
};
|
||||
}
|
||||
|
||||
export function getRecommendedDownload() {
|
||||
const architecture = getArchitecture();
|
||||
const platform = getPlatform();
|
||||
console.log(`Detected platform: ${platform}, architecture: ${architecture}`);
|
||||
if (!architecture || !platform) {
|
||||
return null;
|
||||
}
|
||||
return getDownloadLink(platform, architecture);
|
||||
}
|
@ -1,3 +1,14 @@
|
||||
<script>
|
||||
import { getRecommendedDownload } from "$lib/download-helper";
|
||||
|
||||
let recommendedDownload = getRecommendedDownload();
|
||||
</script>
|
||||
|
||||
{#if recommendedDownload}
|
||||
<a href="#" class="py-2 px-5 bg-violet-600 text-white font-semibold rounded-full shadow-md hover:bg-violet-700 focus:outline-none focus:ring focus:ring-violet-400 focus:ring-opacity-75">
|
||||
Download now
|
||||
<span class="text-sm text-gray-300">
|
||||
({recommendedDownload.platform} {recommendedDownload.architecture})
|
||||
</span>
|
||||
</a>
|
||||
{/if}
|
Loading…
x
Reference in New Issue
Block a user