({ onCancel })
| 16 | } |
| 17 | |
| 18 | export const UpdateSelector: React.FC<UpdateSelectorProps> = ({ onCancel }) => { |
| 19 | const [selectedIndex, setSelectedIndex] = useState(0); |
| 20 | const updateServiceState = useService<UpdateServiceState>( |
| 21 | SERVICE_NAMES.UPDATE, |
| 22 | ); |
| 23 | |
| 24 | const updateState = updateServiceState.value; |
| 25 | |
| 26 | const isWorking = |
| 27 | updateServiceState.state === "loading" || |
| 28 | updateState?.status === "checking" || |
| 29 | updateState?.status === "updating"; |
| 30 | |
| 31 | const error: string | null = useMemo(() => { |
| 32 | if (updateServiceState.state === "error") { |
| 33 | return updateServiceState.error?.message || "Update service error"; |
| 34 | } |
| 35 | if (updateState?.status === "error") { |
| 36 | return updateState.message || "Update failed"; |
| 37 | } |
| 38 | return null; |
| 39 | }, [updateServiceState.state, updateServiceState.error, updateState]); |
| 40 | |
| 41 | const loadingMessage = useMemo(() => { |
| 42 | if (!updateState) return "Preparing update..."; |
| 43 | return updateState.message || "Working..."; |
| 44 | }, [updateState]); |
| 45 | |
| 46 | const options: UpdateOption[] = useMemo(() => { |
| 47 | const runLabel = updateState?.latestVersion |
| 48 | ? `Run update to v${updateState.latestVersion}` |
| 49 | : "Run update"; |
| 50 | |
| 51 | const autoUpdateLabel = updateState?.autoUpdate |
| 52 | ? "Turn off auto-updates" |
| 53 | : "Turn on auto-updates"; |
| 54 | |
| 55 | return [ |
| 56 | { id: "run-update", name: runLabel, action: "run" }, |
| 57 | { id: "toggle-auto", name: autoUpdateLabel, action: "toggle-auto" }, |
| 58 | { id: "back", name: "Back", action: "back" }, |
| 59 | ]; |
| 60 | }, [updateState?.latestVersion, updateState?.autoUpdate]); |
| 61 | |
| 62 | const handleSelect = async (option: UpdateOption) => { |
| 63 | switch (option.action) { |
| 64 | case "run": |
| 65 | // Perform a manual update (not auto-update) |
| 66 | await services.updateService.performUpdate(false); |
| 67 | return; // Keep selector open to show status changes |
| 68 | case "toggle-auto": |
| 69 | // Toggle auto-update setting |
| 70 | const newValue = !updateState?.autoUpdate; |
| 71 | await services.updateService.setAutoUpdate(newValue); |
| 72 | return; // Keep selector open to show updated label |
| 73 | case "back": |
| 74 | onCancel(); |
| 75 | return; |
nothing calls this directly
no test coverage detected