import React, { useState } from 'react'; import type { UpdateInfo } from '../hooks/useUpdateCheck'; import type { Origin } from '@plannotator/core/agents'; import { isWindows } from '../utils/platform'; import { copyTextToClipboard } from '../utils/clipboard'; import { requestUpdateNow } from '../utils/updateNotice'; /** The command when the server sent none (an advert always carries one). */ function fallbackCommand(origin?: Origin | null, isWSL = false): string { if (origin === 'pi') return 'pi update --extensions'; return isWindows && !isWSL ? 'irm https://plannotator.ai/install.ps1 | iex' : 'curl -fsSL https://plannotator.ai/install.sh | bash'; } interface MenuVersionSectionProps { appVersion: string; updateInfo?: UpdateInfo | null; origin?: Origin | null; isWSL: boolean; closeMenu: () => void; } /** * The Options menu's version section: the running version and, when the * machine knows of a newer release, "X is available · What's new" with the * command for this host (remembered install flags included) and, for the * binary the install script manages, Update now. */ export const MenuVersionSection: React.FC = ({ appVersion, updateInfo, origin, isWSL, closeMenu, }) => { const [copied, setCopied] = useState(false); const [updating, setUpdating] = useState<'idle' | 'starting' | 'started' | string>('idle'); const hasUpdate = !!updateInfo?.updateAvailable; const command = updateInfo?.command ?? fallbackCommand(origin, isWSL); const handleCopy = async () => { if (await copyTextToClipboard(command)) { setCopied(true); setTimeout(() => setCopied(false), 2000); } }; const handleUpdate = async () => { setUpdating('starting'); const result = await requestUpdateNow(); setUpdating('error' in result ? result.error : 'started'); }; return (
Plannotator v{appVersion}
{hasUpdate && ( <> {updateInfo!.latestVersion} is available · )} {hasUpdate ? "What's new" : 'Release notes'} {hasUpdate && ( <>
{command}
{updateInfo!.action === 'script' && ( )} {updating !== 'idle' && updating !== 'starting' && updating !== 'started' && ( {updating} )} )}
); };