"use client" import { useEffect, useState, type ReactNode } from "react" import { detectPlatform, type DetectedArch, type DetectedOS, type DetectedPlatform } from "./platform-detect" export type DownloadCardInstallers = { macos: { appleSilicon: string; intel: string } windows: { x64: string; arm64: string } linux: { appImageX64: string; appImageArm64: string; tarX64: string; tarArm64: string } } export type DownloadPlatformOption = { href: string label: string arch?: DetectedArch } export type DownloadPlatformGroup = { os: DetectedOS title: string options: DownloadPlatformOption[] } const FALLBACK_RELEASE = "https://github.com/different-ai/openwork/releases" const FALLBACK_INSTALLERS: DownloadCardInstallers = { macos: { appleSilicon: FALLBACK_RELEASE, intel: FALLBACK_RELEASE }, windows: { x64: FALLBACK_RELEASE, arm64: FALLBACK_RELEASE }, linux: { appImageX64: FALLBACK_RELEASE, appImageArm64: FALLBACK_RELEASE, tarX64: FALLBACK_RELEASE, tarArm64: FALLBACK_RELEASE, }, } function DownloadIcon({ className }: { className?: string }) { return ( ) } function MonitorIcon({ className }: { className?: string }) { return ( ) } function PlatformIcon({ os, className }: { os: DetectedOS; className?: string }) { if (os === "macos") { return ( ) } if (os === "windows") { return ( ) } // Tux from Font Awesome Free 6 brands (CC BY 4.0, fontawesome.com/license/free). return ( ) } function DownloadColumn({ os, title, detectedLabel, showPlatformIcon, flat, children, }: { os: DetectedOS title: string detectedLabel: string | null showPlatformIcon: boolean flat: boolean children: ReactNode }) { return (
{showPlatformIcon ? ( ) : ( )} {title} {detectedLabel ? ( {detectedLabel} ) : null}
{children}
) } function DownloadLink({ href, children, recommended, testId, openInNewTab, keepLabelOnOneLine, flat, onDownload, }: { href: string children: ReactNode recommended?: boolean testId?: string openInNewTab: boolean keepLabelOnOneLine: boolean flat: boolean onDownload?: () => void }) { return ( {children} {recommended ? ( For your device ) : null} ) } function getArchLabel(os: DetectedOS, arch: DetectedArch): string { if (os === "macos") return arch === "arm64" ? "Apple Silicon" : "Intel" return arch === "arm64" ? "ARM64" : "x64" } function getDetectedLabel(detected: DetectedPlatform | null, os: DetectedOS): string | null { if (!detected || detected.os !== os) return null if (detected.arch === null) return "Detected" return `Detected ยท ${getArchLabel(os, detected.arch)}` } function isRecommended(detected: DetectedPlatform | null, os: DetectedOS, arch?: DetectedArch): boolean { return Boolean(arch && detected && detected.os === os && detected.arch === arch) } function useDetectedPlatform() { const [detected, setDetected] = useState(null) useEffect(() => { let cancelled = false void detectPlatform().then((platform) => { if (!cancelled) setDetected(platform) }) return () => { cancelled = true } }, []) return detected } function DownloadPlatformGridContent({ detected, groups, openInNewTab, customCompanyPresentation, flat, recommendedTestId, onDownload, }: { detected: DetectedPlatform | null groups: DownloadPlatformGroup[] openInNewTab: boolean customCompanyPresentation: boolean flat: boolean recommendedTestId?: string onDownload?: (option: DownloadPlatformOption) => void }) { return (
{groups.map((group) => ( {group.options.map((option) => ( onDownload(option) : undefined} > {option.label} ))} ))}
) } export function DownloadPlatformGrid({ groups, openInNewTab = false, recommendedTestId, onDownload, variant = "card", }: { groups: DownloadPlatformGroup[] openInNewTab?: boolean recommendedTestId?: string onDownload?: (option: DownloadPlatformOption) => void variant?: "card" | "flat" }) { const detected = useDetectedPlatform() return (
) } function groupsForInstallers(installers: DownloadCardInstallers): DownloadPlatformGroup[] { return [ { os: "macos", title: "macOS", options: [ { href: installers.macos.appleSilicon, label: "Apple Silicon (M1+)", arch: "arm64" }, { href: installers.macos.intel, label: "Intel", arch: "x64" }, ], }, { os: "windows", title: "Windows", options: [ { href: installers.windows.x64, label: "x64 Installer", arch: "x64" }, { href: installers.windows.arm64, label: "ARM64 Installer", arch: "arm64" }, ], }, { os: "linux", title: "Linux", options: [ { href: installers.linux.appImageX64, label: "AppImage (x64)", arch: "x64" }, { href: installers.linux.appImageArm64, label: "AppImage (ARM64)", arch: "arm64" }, { href: installers.linux.tarX64, label: "tar.gz (x64)" }, { href: installers.linux.tarArm64, label: "tar.gz (ARM64)" }, ], }, ] } export function DownloadOpenWorkCard({ installers, releaseTag, }: { installers?: DownloadCardInstallers | null releaseTag?: string }) { const detected = useDetectedPlatform() const resolvedInstallers = installers ?? FALLBACK_INSTALLERS const tag = releaseTag?.trim() return (
Download OpenWork {tag ? ( {tag} ) : null}

Install the desktop app on macOS, Windows, or Linux. Your workspace connects automatically after sign-in.

) }