MCPcopy
hub / github.com/codeaashu/claude-code / NativeAutoUpdater

Function NativeAutoUpdater

src/components/NativeAutoUpdater.tsx:51–192  ·  view source on GitHub ↗
({
  isUpdating,
  onChangeIsUpdating,
  onAutoUpdaterResult,
  autoUpdaterResult,
  showSuccessMessage,
  verbose
}: Props)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

useUpdateNotificationFunction · 0.85
getInitialSettingsFunction · 0.85
logForDebuggingFunction · 0.85
isAutoUpdaterDisabledFunction · 0.85
logEventFunction · 0.85
getMaxVersionFunction · 0.85
gtFunction · 0.85
getMaxVersionMessageFunction · 0.85
installLatestFunction · 0.85
getErrorTypeFunction · 0.85
useIntervalFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected