run method

Future<ActionResult> run(
  1. Scene scene,
  2. Action action
)

Implementation

Future<ActionResult> run(Scene scene, Action action) async {
  CallProgress.enter('delivering ${action.runtimeType}', key: 'deliver');
  try {
    final result = await _dispatch(scene, action);
    final input = backend.takeInput();
    return input == null || !result.ok ? result : result.withInput(input);
  } on BackendFailure catch (e) {
    return ActionResult.failure(
      action: action,
      summary: '${action.label} not delivered',
      error: e.detail,
      errorKind: e.kind,
      nextSteps: e.nextSteps,
      extra: e.data,
    );
  } on IosToolchainBlocked catch (e) {
    return ActionResult.failure(
      action: action,
      summary: 'refused ${action.label}: ${e.detail}',
      error: e.detail,
      errorKind: GlintErrorKind.unsupportedToolchain,
      nextSteps: e.nextSteps,
    );
  } on UnsupportedBackendAction catch (e) {
    return ActionResult.failure(
      action: action,
      summary: 'backend rejected ${action.label}: ${e.detail}',
      error: e.detail,
      errorKind: GlintErrorKind.unsupportedBackendAction,
      nextSteps: e.nextSteps,
    );
  } on BackendToolError catch (e) {
    return ActionResult.failure(
      action: action,
      summary: '${backend.label} failed ${action.label}',
      error: 'exit=${e.exitCode} ${e.stderr}',
      errorKind: GlintErrorKind.backendToolError,
    );
  } on UnresolvedTarget catch (e) {
    return ActionResult.failure(
      action: action,
      summary: e.message,
      error: e.message,
      errorKind: GlintErrorKind.unresolvedTarget,
      nextSteps: const [
        'read the scene with get_scene to see current glintIds',
        'use CoordinateTarget if the target genuinely isn\'t in the tree',
      ],
    );
  } on OffViewportRefused catch (e) {
    return ActionResult.failure(
      action: action,
      summary: e.message,
      error: e.message,
      errorKind: GlintErrorKind.offViewport,
      physicalCenter: e.physicalCenter,
      logicalCenter: e.logicalCenter,
      devicePixelRatio: e.devicePixelRatio,
      painted: false,
      hittable: false,
      nextSteps: [
        if (e.underKeyboard)
          'close the on-screen keyboard (hardware_button back on Android, or tap outside the field), then retry'
        else
          'bring it on-screen with '
              'scroll_to_find targetGlintId:"${_glintIdOf(action) ?? "<glintId>"}", '
              'then retry',
      ],
    );
  } on NotHittableRefused catch (e) {
    final targetId = _glintIdOf(action);
    final fadedInput = e.faded && targetId != null && isInputNode(scene, targetId);
    final parent = fadedInput ? await findVisibleParent(scene, resolver, targetId) : null;
    return ActionResult.failure(
      action: action,
      summary: e.message,
      error: e.message,
      errorKind: GlintErrorKind.notHittable,
      physicalCenter: e.physicalCenter,
      logicalCenter: e.logicalCenter,
      devicePixelRatio: e.devicePixelRatio,
      painted: e.painted,
      hittable: false,
      extra: {
        if (e.faded) 'faded': true,
        if (parent != null) 'visibleParent': parent,
      },
      nextSteps: fadedInput
          ? [
              if (parent != null)
                'tap $parent (the visible control over it) to focus it, then type without focus'
              else
                'get_scene: tap the visible control that stands over it (an amount shown above an invisible field), then type without focus',
              'refuseNotHittable:false taps the hidden field itself',
            ]
          : e.faded
              ? const [
                  'it shows once the screen moves on: controls that fade out (video, call, camera) come back after a tap '
                      'on an empty area; a button that fades in on a later page or step needs that page first',
                  'get_scene shows it without [hidden] once it is back; refuseNotHittable:false taps it anyway',
                ]
              : e.hitBy != null
                  ? [
                      'something covers the target: scroll it into view with scroll_to_find targetGlintId:"${targetId ?? "<glintId>"}", or dismiss what is on top, then retry',
                      'pass refuseNotHittable:false to tap anyway',
                    ]
                  : const [
                      'check what\'s on top with get_scene: a modal or absorber probably covers the target',
                    ],
    );
  } on GeometryResolveError catch (e) {
    return ActionResult.failure(
      action: action,
      summary: 'resolve failed for ${action.label}',
      error: e.message,
      errorKind: GlintErrorKind.geometryResolveError,
      nextSteps: const [
        'retry once: the app may have been mid-rebuild',
        'if it repeats, call get_scene and target a fresh glintId',
      ],
    );
  }
}