Repository navigation
Expand file tree
/
Copy pathsystem-surface-disclosure.ts
More file actions
36 lines (34 loc) · 1.65 KB
/
Copy pathsystem-surface-disclosure.ts
File metadata and controls
36 lines (34 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { SnapshotState } from '@agent-device/kernel/snapshot';
import { systemSurfaceDisclosure } from '@agent-device/contracts/android-system-surface-disclosure';
import { iosSystemSurfaceDisclosure } from '@agent-device/contracts/ios-system-surface';
import type { DaemonResponse } from './daemon-request.ts';
/**
* Append the occluding-system-surface disclosure to a selector-route response whose consumed
* snapshot was a system surface: an Android notification shade / quick settings, or an iOS in-place
* system sheet such as web sign-in or Apple Pay (#2438). Both found and not-found outcomes must
* explain that app content is occluded: a match found inside the surface is not app content, and a miss is expected while the
* surface covers the app.
*/
export function withSystemSurfaceDisclosure(
response: DaemonResponse,
snapshot: Pick<SnapshotState, 'systemSurfaceOnly' | 'iosSystemSurfaceBundleId'> | undefined,
): DaemonResponse {
const disclosure = snapshot?.iosSystemSurfaceBundleId
? iosSystemSurfaceDisclosure(snapshot.iosSystemSurfaceBundleId)
: systemSurfaceDisclosure(snapshot);
if (!disclosure) return response;
if (response.ok) {
const warning = appended(response.data?.warning, disclosure);
return { ...response, data: { ...response.data, warning } };
}
const details = response.error.details ?? {};
return {
...response,
error: { ...response.error, details: { ...details, hint: appended(details.hint, disclosure) } },
};
}
function appended(existing: unknown, disclosure: string): string {
return typeof existing === 'string' && existing.trim() !== ''
? `${existing}\n${disclosure}`
: disclosure;
}