MCPcopy Create free account
hub / github.com/Noumena-Network/code / NativeAutoUpdater

Function NativeAutoUpdater

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected