( device: DeviceInfo, interactor: Interactor, positionals: string[], context: DispatchContext | undefined, )
| 506 | } |
| 507 | |
| 508 | async function handleSettingsCommand( |
| 509 | device: DeviceInfo, |
| 510 | interactor: Interactor, |
| 511 | positionals: string[], |
| 512 | context: DispatchContext | undefined, |
| 513 | ): Promise<Record<string, unknown>> { |
| 514 | const [setting, state, target, mode] = positionals; |
| 515 | if (!setting || (!state && setting !== 'clear-app-state')) { |
| 516 | throw new AppError('INVALID_ARGS', 'settings requires setting state'); |
| 517 | } |
| 518 | if (setting === 'clear-app-state') { |
| 519 | const appBundleId = (state === 'clear' ? target : state) ?? context?.appBundleId; |
| 520 | if (!appBundleId) { |
| 521 | throw new AppError( |
| 522 | 'INVALID_ARGS', |
| 523 | 'settings clear-app-state requires an app id or an active app session.', |
| 524 | ); |
| 525 | } |
| 526 | emitDiagnostic({ |
| 527 | level: 'debug', |
| 528 | phase: 'settings_apply', |
| 529 | data: { setting, state: 'clear', appBundleId, platform: device.platform }, |
| 530 | }); |
| 531 | const result = await interactor.setSetting(setting, 'clear', appBundleId); |
| 532 | return result && typeof result === 'object' |
| 533 | ? withSuccessText( |
| 534 | { setting, state: 'clear', ...result }, |
| 535 | readResultMessage(result) ?? `Cleared user data for ${appBundleId}`, |
| 536 | ) |
| 537 | : { setting, state: 'clear', ...successText(`Cleared user data for ${appBundleId}`) }; |
| 538 | } |
| 539 | if (!state) { |
| 540 | throw new AppError('INVALID_ARGS', 'settings requires setting state'); |
| 541 | } |
| 542 | const isLocationSet = setting === 'location' && state === 'set'; |
| 543 | const usesPayloadAppBundleSlot = setting === 'permission' || isLocationSet; |
| 544 | const appBundleId = |
| 545 | (usesPayloadAppBundleSlot ? positionals[4] : positionals[2]) ?? context?.appBundleId; |
| 546 | const settingOptions = |
| 547 | setting === 'permission' |
| 548 | ? { |
| 549 | permissionTarget: target, |
| 550 | permissionMode: mode, |
| 551 | } |
| 552 | : isLocationSet |
| 553 | ? { |
| 554 | latitude: readLocationCoordinate(target, 'latitude'), |
| 555 | longitude: readLocationCoordinate(mode, 'longitude'), |
| 556 | } |
| 557 | : undefined; |
| 558 | const diagnosticPayload = isLocationSet |
| 559 | ? { setting, state, latitude: target, longitude: mode, platform: device.platform } |
| 560 | : setting === 'permission' |
| 561 | ? { |
| 562 | setting, |
| 563 | state, |
| 564 | permissionTarget: target, |
| 565 | permissionMode: mode, |
no test coverage detected