MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / NativeAutoUpdater

Function NativeAutoUpdater

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

Source from the content-addressed store, hash-verified

51};
52
53export 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', {

Callers

nothing calls this directly

Calls 13

useUpdateNotificationFunction · 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
nowMethod · 0.80
getInitialSettingsFunction · 0.50
logForDebuggingFunction · 0.50

Tested by

no test coverage detected