@devries-cameron20 / t3code Mirror · read-only / commits / 790ba13d0c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 14:30 UTC

refactor(mobile): app update checks start with the app (#25856)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 04:11 UTC 790ba13d0c839d3cd1b4c45f6d3c252b9286dc99
4 files changed +36 -55
apps/mobile/src/App.tsx
+2
@@ -85,6 +85,7 @@ import {
85 } from "./lib/rootNavigation";
86 import { pruneNewTaskFlowStates } from "./features/threads/new-task-flow-state";
87 import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen";
88 +import { installAppUpdateChecks } from "./features/updates/app-updates";
89
90 import "../global.css";
91
@@ -176,6 +177,7 @@ const appServiceDisposers = [
177 startIncomingShareInbox(),
178 installAgentNotificationNavigation(linkToAppPath),
179 installAppShortcuts(linkToAppPath),
180 + installAppUpdateChecks(),
181 ];
182 disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.hot, () => {
183 for (const dispose of appServiceDisposers) dispose();
apps/mobile/src/features/home/HomeRouteScreen.tsx
-6
@@ -22,7 +22,6 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
22 import { useDeviceType, useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
23 import { WorkspaceEmptyDetail } from "../layout/WorkspaceEmptyDetail";
24 import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
25 -import { checkForAppUpdateOnLaunch, startAppUpdateForegroundRecheck } from "../updates/app-updates";
25 import { AndroidHomeFabLayout } from "./AndroidHomeFab";
26 import { HomeScreen } from "./HomeScreen";
27 import { HomeHeader } from "./HomeHeader";
@@ -95,11 +94,6 @@ export function HomeRouteScreen() {
94 [selectThreadRoute],
95 );
96
98 - useEffect(() => {
99 - void checkForAppUpdateOnLaunch();
100 - startAppUpdateForegroundRecheck();
101 - }, []);
102 -
97 const {
98 archiveThread,
99 confirmDeleteThread,
apps/mobile/src/features/updates/app-updates.test.ts
+11 -11
@@ -1,8 +1,9 @@
1 +import { AppState } from "react-native";
2 import { describe, expect, it, vi } from "vite-plus/test";
3
4 import {
5 createAppUpdateDeferral,
5 - createAppUpdateLaunchCheck,
6 + installAppUpdateChecks,
7 runAppUpdateCheck,
8 type AppUpdateCheckState,
9 type AppUpdateClient,
@@ -234,10 +235,9 @@ describe("runAppUpdateCheck", () => {
235 const client = makeUpdateClient({
236 checkForUpdateAsync: vi.fn(() => checkResult),
237 });
237 - const checkOnLaunch = createAppUpdateLaunchCheck(client);
238 const manualStates: AppUpdateCheckState[] = [];
239
240 - const launchCheck = checkOnLaunch();
240 + const launchCheck = runAppUpdateCheck({ client });
241 const manualCheck = runAppUpdateCheck({
242 client,
243 onStateChange: (state) => manualStates.push(state),
@@ -303,16 +303,16 @@ describe("runAppUpdateCheck", () => {
303 });
304 });
305
306 -describe("createAppUpdateLaunchCheck", () => {
307 - it("checks at most once for each JavaScript launch", async () => {
306 +describe("installAppUpdateChecks", () => {
307 + it("checks once at launch and stops listening for foregrounds when disposed", () => {
308 + const remove = vi.fn();
309 + vi.mocked(AppState.addEventListener).mockReturnValueOnce({ remove });
310 const client = makeUpdateClient();
309 - const checkOnLaunch = createAppUpdateLaunchCheck(client);
311
311 - const first = checkOnLaunch();
312 - const second = checkOnLaunch();
313 - await first;
314 -
315 - expect(second).toBeUndefined();
312 + const dispose = installAppUpdateChecks(client);
313 expect(client.checkForUpdateAsync).toHaveBeenCalledOnce();
314 + dispose();
315 +
316 + expect(remove).toHaveBeenCalledOnce();
317 });
318 });
apps/mobile/src/features/updates/app-updates.ts
+23 -38
@@ -466,20 +466,6 @@ function isAppUpdateUnavailableError(error: unknown): boolean {
466 return typeof code === "string" && UPDATE_CHECK_UNAVAILABLE_ERROR_CODES.has(code);
467 }
468
469 -export function createAppUpdateLaunchCheck(
470 - client: AppUpdateClient = Updates,
471 -): () => Promise<void> | undefined {
472 - let started = false;
473 -
474 - return () => {
475 - if (started || !isAppUpdateCheckAvailable(client)) return undefined;
476 - started = true;
477 - return runAppUpdateCheck({ client });
478 - };
479 -}
480 -
481 -export const checkForAppUpdateOnLaunch = createAppUpdateLaunchCheck();
482 -
469 export const FOREGROUND_APP_UPDATE_RECHECK_AFTER_MS = 15 * 60 * 1000;
470
471 export function shouldRecheckAppUpdateOnForeground(
@@ -494,31 +480,30 @@ export function shouldRecheckAppUpdateOnForeground(
480 );
481 }
482
497 -export function createAppUpdateForegroundRecheck(
483 +/**
484 + * App-lifetime update checks: one at launch, then again when the app returns
485 + * from a long stay in the background.
486 + */
487 +export function installAppUpdateChecks(
488 client: AppUpdateClient = Updates,
489 deferral: AppUpdateDeferral = appUpdateDeferral,
490 ): () => void {
501 - let started = false;
502 -
503 - return () => {
504 - if (started || !isAppUpdateCheckAvailable(client)) return;
505 - started = true;
506 - let backgroundedAtMs: number | null = null;
507 - AppState.addEventListener("change", (state) => {
508 - if (state === "background") {
509 - backgroundedAtMs = Date.now();
510 - return;
511 - }
512 - if (state !== "active") return;
513 - const shouldCheck = shouldRecheckAppUpdateOnForeground(
514 - backgroundedAtMs,
515 - Date.now(),
516 - deferral.pendingInstall,
517 - );
518 - backgroundedAtMs = null;
519 - if (shouldCheck) void runAppUpdateCheck({ client, deferral });
520 - });
521 - };
491 + if (!isAppUpdateCheckAvailable(client)) return () => undefined;
492 + void runAppUpdateCheck({ client, deferral });
493 + let backgroundedAtMs: number | null = null;
494 + const subscription = AppState.addEventListener("change", (state) => {
495 + if (state === "background") {
496 + backgroundedAtMs = Date.now();
497 + return;
498 + }
499 + if (state !== "active") return;
500 + const shouldCheck = shouldRecheckAppUpdateOnForeground(
501 + backgroundedAtMs,
502 + Date.now(),
503 + deferral.pendingInstall,
504 + );
505 + backgroundedAtMs = null;
506 + if (shouldCheck) void runAppUpdateCheck({ client, deferral });
507 + });
508 + return () => subscription.remove();
509 }
523 -
524 -export const startAppUpdateForegroundRecheck = createAppUpdateForegroundRecheck();