import React, { useState, useEffect } from "react"; import axios from "axios"; import { FaWindows, FaApple, FaLinux } from "react-icons/fa"; import { twMerge } from "tailwind-merge"; const systemsTemplate = [ { name: "Mac M1, M2, M3", logo: FaApple, fileFormat: "{appname}-mac-arm64-{tag}.dmg", comingSoon: false, }, { name: "Mac (Intel)", logo: FaApple, fileFormat: "{appname}-mac-x64-{tag}.dmg", comingSoon: false, }, { name: "Windows", logo: FaWindows, fileFormat: "{appname}-win-x64-{tag}.exe", comingSoon: true, }, { name: "Linux", logo: FaLinux, fileFormat: "{appname}-linux-amd64-{tag}.deb", comingSoon: true, }, ]; 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)-.*$/; 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(); }, []); return (
Download for PC
🚧 Warning: Jan is in the process of being built. Expect bugs!
{systems.map((system, i) => ( {system.name} {system.comingSoon && ( Coming Soon )} ))}
); }