perf(mobile): isolate iOS Live Activity imports (#12380)
This commit is contained in:
1 parent
e0649ed7d8
commit
53830d4134
4 files changed
+35
-12
No files matched your search
@@ -0,0 +1,9 @@
|
||||
import AgentActivity, { type AgentActivityProps } from "../../widgets/AgentActivity";
|
||||
|
||||
export function getAgentLiveActivities() {
|
||||
return AgentActivity.getInstances();
|
||||
}
|
||||
|
||||
export function startAgentLiveActivity(props: AgentActivityProps) {
|
||||
return AgentActivity.start(props);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { LiveActivity } from "expo-widgets";
|
||||
import type { AgentActivityProps } from "../../widgets/AgentActivity";
|
||||
|
||||
export function getAgentLiveActivities(): Array<LiveActivity<AgentActivityProps>> {
|
||||
return [];
|
||||
}
|
||||
|
||||
export function startAgentLiveActivity(
|
||||
_props: AgentActivityProps,
|
||||
): LiveActivity<AgentActivityProps> | null {
|
||||
return null;
|
||||
}
|
||||
@@ -101,11 +101,9 @@ vi.mock("expo-widgets", () => ({
|
||||
addPushToStartTokenListener: vi.fn(() => ({ remove: vi.fn() })),
|
||||
}));
|
||||
|
||||
vi.mock("../../widgets/AgentActivity", () => ({
|
||||
default: {
|
||||
getInstances: widgetMocks.getInstances,
|
||||
start: widgetMocks.start,
|
||||
},
|
||||
vi.mock("./agentLiveActivity", () => ({
|
||||
getAgentLiveActivities: widgetMocks.getInstances,
|
||||
startAgentLiveActivity: widgetMocks.start,
|
||||
}));
|
||||
|
||||
// The state modules pull the whole connection stack (and native expo modules)
|
||||
|
||||
@@ -35,7 +35,8 @@ import {
|
||||
loadPreferences,
|
||||
saveAgentAwarenessRegistrationRecord,
|
||||
} from "../../persistence/imperative";
|
||||
import AgentActivity, { type AgentActivityProps } from "../../widgets/AgentActivity";
|
||||
import type { AgentActivityProps } from "../../widgets/AgentActivity";
|
||||
import { getAgentLiveActivities, startAgentLiveActivity } from "./agentLiveActivity";
|
||||
import { resolveCloudPublicConfig } from "../cloud/publicConfig";
|
||||
import { supportsAgentAwarenessPush } from "./capabilities";
|
||||
import { makeRelayDeviceRegistrationRequest, resolveApsEnvironment } from "./registrationPayload";
|
||||
@@ -522,11 +523,11 @@ function armAgentAwarenessLiveActivityForLocalWorkNow(input: {
|
||||
readonly projectTitle: string;
|
||||
}): void {
|
||||
try {
|
||||
if (AgentActivity.getInstances().length > 0) {
|
||||
if (getAgentLiveActivities().length > 0) {
|
||||
return;
|
||||
}
|
||||
const nowIso = new Date(Date.now()).toISOString();
|
||||
const activity = AgentActivity.start({
|
||||
const activity = startAgentLiveActivity({
|
||||
title: "T3 Code",
|
||||
subtitle: "Agent work in progress",
|
||||
activeCount: 1,
|
||||
@@ -545,6 +546,9 @@ function armAgentAwarenessLiveActivityForLocalWorkNow(input: {
|
||||
},
|
||||
],
|
||||
});
|
||||
if (!activity) {
|
||||
return;
|
||||
}
|
||||
logRegistrationDebug("live activity card armed for local work", {
|
||||
threadTitle: input.threadTitle,
|
||||
});
|
||||
@@ -842,7 +846,7 @@ function endLocalLiveActivities(context: string): void {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (const activity of AgentActivity.getInstances()) {
|
||||
for (const activity of getAgentLiveActivities()) {
|
||||
activity.end("immediate").catch((error: unknown) => {
|
||||
logRegistrationError(context, error);
|
||||
});
|
||||
@@ -1069,7 +1073,7 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
|
||||
}
|
||||
|
||||
let activities = yield* Effect.try({
|
||||
try: () => AgentActivity.getInstances(),
|
||||
try: () => getAgentLiveActivities(),
|
||||
catch: (cause) =>
|
||||
new AgentAwarenessOperationError({
|
||||
operation: "list-active-live-activities",
|
||||
@@ -1118,7 +1122,7 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
|
||||
// The snapshot request yields; an arm-on-send may have created the
|
||||
// card in the meantime. Re-check so two cards are never started.
|
||||
const armedMeanwhile = yield* Effect.try({
|
||||
try: () => AgentActivity.getInstances(),
|
||||
try: () => getAgentLiveActivities(),
|
||||
catch: () => [] as ReadonlyArray<LiveActivity<AgentActivityProps>>,
|
||||
}).pipe(Effect.orElseSucceed(() => [] as ReadonlyArray<LiveActivity<AgentActivityProps>>));
|
||||
if (armedMeanwhile.length > 0) {
|
||||
@@ -1127,7 +1131,7 @@ export function refreshActiveLiveActivityRemoteRegistration(): Effect.Effect<
|
||||
const aggregate = snapshot.aggregate;
|
||||
const primed = yield* Effect.try({
|
||||
try: () =>
|
||||
AgentActivity.start({
|
||||
startAgentLiveActivity({
|
||||
title: aggregate.title,
|
||||
subtitle: aggregate.subtitle,
|
||||
activeCount: aggregate.activeCount,
|
||||
|
||||
Reference in new issue
Block a user