import React, { useState, useEffect } from 'react' import axios from 'axios' import { FaWindows, FaApple, FaLinux } from 'react-icons/fa' import { twMerge } from 'tailwind-merge' import { DownloadIcon } from 'lucide-react' const systemsTemplate = [ { name: 'Mac M1, M2, M3', label: 'Apple Silicon', logo: FaApple, fileFormat: '{appname}-mac-arm64-{tag}.dmg', }, { name: 'Mac (Intel)', label: 'Apple Intel', logo: FaApple, fileFormat: '{appname}-mac-x64-{tag}.dmg', }, { name: 'Windows', label: 'Standard (64-bit)', logo: FaWindows, fileFormat: '{appname}-win-x64-{tag}.exe', }, { name: 'Linux (AppImage)', label: 'AppImage', logo: FaLinux, fileFormat: '{appname}-linux-x86_64-{tag}.AppImage', }, { name: 'Linux (deb)', label: 'Deb', logo: FaLinux, fileFormat: '{appname}-linux-amd64-{tag}.deb', }, ] const groupTemnplate = [ { label: 'MacOS', name: 'mac', logo: FaApple }, { label: 'Windows', name: 'windows', logo: FaWindows }, { label: 'Linux', name: 'linux', logo: FaLinux }, ] export default function DownloadApp() { const [systems, setSystems] = useState(systemsTemplate) const getLatestReleaseInfo = async (repoOwner, repoName) => { const url = `https://api.github.com/repos/${repoOwner}/${repoName}/releases/latest` try { const response = await axios.get(url) return response.data } catch (error) { console.error(error) return null } } const extractAppName = (fileName) => { // Extract appname using a regex that matches the provided file formats const regex = /^(.*?)-(?:mac|win|linux)-(?:arm64|x64|amd64|x86_64)-.*$/ const match = fileName.match(regex) return match ? match[1] : null } useEffect(() => { const updateDownloadLinks = async () => { try { const releaseInfo = await getLatestReleaseInfo('janhq', 'jan') // Extract appname from the first asset name const firstAssetName = releaseInfo.assets[0].name const appname = extractAppName(firstAssetName) if (!appname) { console.error( 'Failed to extract appname from file name:', firstAssetName ) return } // Remove 'v' at the start of the tag_name const tag = releaseInfo.tag_name.startsWith('v') ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name const updatedSystems = systems.map((system) => { const downloadUrl = system.fileFormat .replace('{appname}', appname) .replace('{tag}', tag) return { ...system, href: `https://github.com/janhq/jan/releases/download/${releaseInfo.tag_name}/${downloadUrl}`, } }) setSystems(updatedSystems) } catch (error) { console.error('Failed to update download links:', error) } } updateDownloadLinks() }, []) const renderDownloadLink = (group) => { return ( <> {systems .filter((x) => x.name.toLowerCase().includes(group)) .map((system, i) => (
))} > ) } return (Jan is in the process of being built. Expect bugs!