'use client'; import { useEffect, useState } from 'react'; import { useLocale, useTranslations } from 'next-intl'; import { desktopDownloadUrl, type DesktopFileInfo, type DesktopLatestInfo, formatFileSize, loadDesktopLatest } from '@/lib/desktop'; import { useIsDesktopClient } from '@/lib/desktop-client'; const BUTTON_CLASS = 'inline-flex items-center gap-2 rounded-md bg-primary px-4 py-2.5 text-sm font-medium text-primary-foreground hover:opacity-90'; function WindowsIcon() { return ( ); } function LinuxIcon() { return ( ); } function DownloadButton({ file, label, icon, testId, locale, fileInfoText, }: { file: DesktopFileInfo; label: string; icon: React.ReactNode; testId: string; locale: string; fileInfoText: (values: { name: string; size: string }) => string; }) { return (
{icon} {label}

{fileInfoText({ name: file.name, size: formatFileSize(file.size, locale) })}

); } /** * Inhalt der Einstellungsseite "Desktop-App" (D-12): vier erklaerende * Saetze, dann Version/Downloads oder ein Hinweis, wenn der Server keine * Pakete traegt (`loadDesktopLatest()` liefert `null`). Im Desktop-Client * (260917-jn2) zusaetzlich ein Block "Verbunden mit: {origin}" -- `isDesktop` * ist im Server-HTML und im ersten Client-Render false (Hook mit * `useEffect`), der Block rendert also erst nach der Hydration, weshalb * `window.location.origin` hier direkt gelesen werden darf (kein * Hydration-Fehler). */ export function DesktopAppSettings() { const t = useTranslations('settings'); const locale = useLocale(); const isDesktop = useIsDesktopClient(); const [info, setInfo] = useState(undefined); useEffect(() => { let active = true; loadDesktopLatest().then((data) => { if (active) setInfo(data); }); return () => { active = false; }; }, []); const fileInfoText = (values: { name: string; size: string }) => t('desktop.fileInfo', values); return (

{t('desktop.intro')}

{t('desktop.firstStart')}

{t('desktop.tray')}

{t('desktop.update')}

{isDesktop && (

{t('desktop.connectedTo', { origin: window.location.origin })}

{t('desktop.changeHint')}

)} {info === null &&

{t('desktop.unavailable')}

} {info && ( <>

{t('desktop.versionLabel', { version: info.version })}

{info.channel === 'beta' && (

{t('desktop.channelBeta', { commit: info.commit })}

)}
{info.files.windows && ( } testId="desktop-download-windows" locale={locale} fileInfoText={fileInfoText} /> )} {info.files.linux && ( } testId="desktop-download-linux" locale={locale} fileInfoText={fileInfoText} /> )}
)}
); }