Skip to content

Commit a98d0e5

Browse files
committed
fix: respect stored live activity preference in sync path
The in-memory localLiveActivitiesEnabled flag was not updated when the user disabled Live Activity Updates via settings, allowing snapshot subscriptions to recreate activities after disable. - Export setLocalLiveActivitiesEnabled from liveActivityController - Call it from setLiveActivityUpdatesEnabled when preference changes - Add initializeLiveActivityPreferenceState to hydrate the in-memory flag from stored preferences on app startup (before environments connect)
1 parent 65f080a commit a98d0e5

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

apps/mobile/src/features/agent-awareness/liveActivityController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ function isMissingNativeLiveActivityError(error: unknown): boolean {
598598
return error instanceof Error && error.message.includes("Can't find live activity with id:");
599599
}
600600

601+
export function setLocalLiveActivitiesEnabled(enabled: boolean): void {
602+
localLiveActivitiesEnabled = enabled;
603+
}
604+
601605
export function __resetAgentLiveActivitiesForTest(): void {
602606
localLiveActivitiesEnabled = true;
603607
activeActivity = null;

apps/mobile/src/features/agent-awareness/liveActivityPreferences.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { HttpClient } from "effect/unstable/http";
88
import type { SavedRemoteConnection } from "../../lib/connection";
99
import { savePreferencesPatch } from "../../lib/storage";
1010
import { linkEnvironmentToCloud } from "../cloud/linkEnvironment";
11-
import { endAllAgentLiveActivities } from "./liveActivityController";
11+
import { endAllAgentLiveActivities, setLocalLiveActivitiesEnabled } from "./liveActivityController";
1212
import { setLiveActivityUpdatesEnabled } from "./liveActivityPreferences";
1313
import { refreshAgentAwarenessRegistration } from "./remoteRegistration";
1414

@@ -22,6 +22,7 @@ vi.mock("../cloud/linkEnvironment", () => ({
2222

2323
vi.mock("./liveActivityController", () => ({
2424
endAllAgentLiveActivities: vi.fn(() => Effect.void),
25+
setLocalLiveActivitiesEnabled: vi.fn(),
2526
}));
2627

2728
vi.mock("./remoteRegistration", () => ({

apps/mobile/src/features/agent-awareness/liveActivityPreferences.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import { HttpClient } from "effect/unstable/http";
33
import { ManagedRelayClient } from "@t3tools/client-runtime";
44

55
import type { SavedRemoteConnection } from "../../lib/connection";
6-
import { savePreferencesPatch } from "../../lib/storage";
6+
import { loadPreferences, savePreferencesPatch } from "../../lib/storage";
77
import { linkEnvironmentToCloud } from "../cloud/linkEnvironment";
8-
import { endAllAgentLiveActivities } from "./liveActivityController";
8+
import { endAllAgentLiveActivities, setLocalLiveActivitiesEnabled } from "./liveActivityController";
99
import { refreshAgentAwarenessRegistration } from "./remoteRegistration";
1010

11+
export async function initializeLiveActivityPreferenceState(): Promise<void> {
12+
const preferences = await loadPreferences();
13+
if (preferences.liveActivitiesEnabled === false) {
14+
setLocalLiveActivitiesEnabled(false);
15+
}
16+
}
17+
1118
export function setLiveActivityUpdatesEnabled(input: {
1219
readonly enabled: boolean;
1320
readonly clerkToken: string | null;
@@ -19,6 +26,8 @@ export function setLiveActivityUpdatesEnabled(input: {
1926
catch: (error) => error,
2027
});
2128

29+
setLocalLiveActivitiesEnabled(input.enabled);
30+
2231
if (!input.enabled) {
2332
yield* endAllAgentLiveActivities();
2433
}

apps/mobile/src/state/use-remote-environment-registry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
stopAgentAwarenessForEnvironment,
6060
stopAllAgentAwareness,
6161
} from "../features/agent-awareness/shellLiveActivitySync";
62+
import { initializeLiveActivityPreferenceState } from "../features/agent-awareness/liveActivityPreferences";
6263
import { environmentRuntimeManager, useEnvironmentRuntimeStates } from "./use-environment-runtime";
6364
import {
6465
clearCachedShellSnapshotMetadata,
@@ -565,6 +566,11 @@ export function useRemoteEnvironmentBootstrap() {
565566
return;
566567
}
567568

569+
await initializeLiveActivityPreferenceState();
570+
if (cancelled) {
571+
return;
572+
}
573+
568574
replaceSavedConnections(
569575
Object.fromEntries(
570576
connections.map((connection) => [connection.environmentId, connection]),

0 commit comments

Comments
 (0)