-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathsimulator-accessibility.ts
More file actions
82 lines (77 loc) · 2.31 KB
/
simulator-accessibility.ts
File metadata and controls
82 lines (77 loc) · 2.31 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type { CommandExecutor } from './execution/index.ts';
import { log } from './logging/index.ts';
const LOG_PREFIX = '[Simulator]';
/**
* Ensure accessibility defaults are enabled on a simulator.
* On iOS 26+ fresh simulators, AccessibilityEnabled and ApplicationAccessibilityEnabled
* default to 0, which prevents accessibility hierarchy queries from returning any elements.
*
* Both flags are written unconditionally on every call — defaults write is idempotent
* and avoids a partial-state problem where only checking one flag could skip the second.
* Failures are logged but never propagated — accessibility setup should not block boot.
*/
export async function ensureSimulatorAccessibility(
simulatorId: string,
executor: CommandExecutor,
): Promise<void> {
let a11yOk = false;
let appA11yOk = false;
try {
const writeA11y = await executor(
[
'xcrun',
'simctl',
'spawn',
simulatorId,
'defaults',
'write',
'com.apple.Accessibility',
'AccessibilityEnabled',
'-bool',
'true',
],
`${LOG_PREFIX}: enable AccessibilityEnabled`,
);
a11yOk = writeA11y.success;
if (!a11yOk) {
log('warn', `${LOG_PREFIX}: Failed to enable AccessibilityEnabled: ${writeA11y.error}`);
}
} catch (error) {
log(
'warn',
`${LOG_PREFIX}: Failed to enable AccessibilityEnabled: ${error instanceof Error ? error.message : String(error)}`,
);
}
try {
const writeAppA11y = await executor(
[
'xcrun',
'simctl',
'spawn',
simulatorId,
'defaults',
'write',
'com.apple.Accessibility',
'ApplicationAccessibilityEnabled',
'-bool',
'true',
],
`${LOG_PREFIX}: enable ApplicationAccessibilityEnabled`,
);
appA11yOk = writeAppA11y.success;
if (!appA11yOk) {
log(
'warn',
`${LOG_PREFIX}: Failed to enable ApplicationAccessibilityEnabled: ${writeAppA11y.error}`,
);
}
} catch (error) {
log(
'warn',
`${LOG_PREFIX}: Failed to enable ApplicationAccessibilityEnabled: ${error instanceof Error ? error.message : String(error)}`,
);
}
if (a11yOk && appA11yOk) {
log('info', `${LOG_PREFIX}: Accessibility defaults enabled for simulator ${simulatorId}`);
}
}