( device: DeviceInfo, state: string, )
| 242 | } |
| 243 | |
| 244 | async function resolveAndroidAppearanceTarget( |
| 245 | device: DeviceInfo, |
| 246 | state: string, |
| 247 | ): Promise<'light' | 'dark'> { |
| 248 | const action = parseAppearanceAction(state); |
| 249 | if (action !== 'toggle') return action; |
| 250 | |
| 251 | const currentResult = await runAndroidAdb(device, ['shell', 'cmd', 'uimode', 'night'], { |
| 252 | allowFailure: true, |
| 253 | }); |
| 254 | if (currentResult.exitCode !== 0) { |
| 255 | throw new AppError('COMMAND_FAILED', 'Failed to read current Android appearance', { |
| 256 | stdout: currentResult.stdout, |
| 257 | stderr: currentResult.stderr, |
| 258 | exitCode: currentResult.exitCode, |
| 259 | }); |
| 260 | } |
| 261 | const current = parseAndroidAppearance(currentResult.stdout, currentResult.stderr); |
| 262 | if (!current) { |
| 263 | throw new AppError( |
| 264 | 'COMMAND_FAILED', |
| 265 | 'Unable to determine current Android appearance for toggle', |
| 266 | { |
| 267 | stdout: currentResult.stdout, |
| 268 | stderr: currentResult.stderr, |
| 269 | }, |
| 270 | ); |
| 271 | } |
| 272 | if (current === 'auto') return 'dark'; |
| 273 | return current === 'dark' ? 'light' : 'dark'; |
| 274 | } |
| 275 | |
| 276 | function parseAndroidAppearance(stdout: string, stderr: string): 'light' | 'dark' | 'auto' | null { |
| 277 | const match = /night mode:\s*(yes|no|auto)\b/i.exec(`${stdout}\n${stderr}`); |
no test coverage detected