MCPcopy Index your code
hub / github.com/callstack/agent-device / resolveAndroidAppearanceTarget

Function resolveAndroidAppearanceTarget

src/platforms/android/settings.ts:244–274  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  state: string,
)

Source from the content-addressed store, hash-verified

242}
243
244async 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
276function parseAndroidAppearance(stdout: string, stderr: string): 'light' | 'dark' | 'auto' | null {
277 const match = /night mode:\s*(yes|no|auto)\b/i.exec(`${stdout}\n${stderr}`);

Callers 1

setAndroidSettingFunction · 0.85

Calls 3

parseAppearanceActionFunction · 0.90
runAndroidAdbFunction · 0.90
parseAndroidAppearanceFunction · 0.85

Tested by

no test coverage detected