({
isUpdating,
onChangeIsUpdating,
onAutoUpdaterResult,
autoUpdaterResult,
showSuccessMessage,
verbose,
}: Props)
| 51 | }; |
| 52 | |
| 53 | export function NativeAutoUpdater({ |
| 54 | isUpdating, |
| 55 | onChangeIsUpdating, |
| 56 | onAutoUpdaterResult, |
| 57 | autoUpdaterResult, |
| 58 | showSuccessMessage, |
| 59 | verbose, |
| 60 | }: Props): React.ReactNode { |
| 61 | const [versions, setVersions] = useState<{ |
| 62 | current?: string | null; |
| 63 | latest?: string | null; |
| 64 | }>({}); |
| 65 | const [maxVersionIssue, setMaxVersionIssue] = useState<string | null>(null); |
| 66 | const updateSemver = useUpdateNotification(autoUpdaterResult?.version); |
| 67 | const channel = getInitialSettings()?.autoUpdatesChannel ?? 'latest'; |
| 68 | |
| 69 | // Track latest isUpdating value in a ref so the memoized checkForUpdates |
| 70 | // callback always sees the current value without changing callback identity |
| 71 | // (which would re-trigger the initial-check useEffect below and cause |
| 72 | // repeated downloads on remount — the upstream trigger for #22413). |
| 73 | const isUpdatingRef = useRef(isUpdating); |
| 74 | isUpdatingRef.current = isUpdating; |
| 75 | |
| 76 | const checkForUpdates = React.useCallback(async () => { |
| 77 | if (isUpdatingRef.current) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') { |
| 82 | logForDebugging('NativeAutoUpdater: Skipping update check in test/dev environment'); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if (isAutoUpdaterDisabled()) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | onChangeIsUpdating(true); |
| 91 | const startTime = Date.now(); |
| 92 | |
| 93 | // Log the start of an auto-update check for funnel analysis |
| 94 | logEvent('tengu_native_auto_updater_start', {}); |
| 95 | |
| 96 | try { |
| 97 | // Check if current version is above the max allowed version |
| 98 | const maxVersion = await getMaxVersion(); |
| 99 | if (maxVersion && gt(MACRO.VERSION, maxVersion)) { |
| 100 | const msg = await getMaxVersionMessage(); |
| 101 | setMaxVersionIssue(msg ?? 'affects your version'); |
| 102 | } |
| 103 | |
| 104 | const result = await installLatest(channel); |
| 105 | const currentVersion = MACRO.VERSION; |
| 106 | const latencyMs = Date.now() - startTime; |
| 107 | |
| 108 | // Handle lock contention gracefully - just return without treating as error |
| 109 | if (result.lockFailed) { |
| 110 | logEvent('tengu_native_auto_updater_lock_contention', { |
nothing calls this directly
no test coverage detected