Skip to content

Multiple commands#29

Merged
Android-PowerUser merged 6 commits intoDatabase2from
multiple-commands
Jun 5, 2025
Merged

Multiple commands#29
Android-PowerUser merged 6 commits intoDatabase2from
multiple-commands

Conversation

@Android-PowerUser
Copy link
Owner

No description provided.

Introduces a command queue in ScreenOperatorAccessibilityService to process screen interaction commands sequentially.

Key changes:
- Commands are added to a queue and processed one by one.
- A default delay of 150ms is introduced between the completion of one command and the start of the next.
- If the next command in the queue is TakeScreenshot, a longer delay of 850ms is applied before it starts.
- Existing internal delays within the TakeScreenshot process (850ms before capture and 800ms for retrieval) are preserved.
- The `executeCommand` method in the companion object now adds commands to this queue and triggers processing.
- The actual command execution logic has been moved to a new instance method `executeSingleCommand`.

This change ensures that multiple commands in a single message are executed in order without interference, especially after potentially long-running operations like scrolling.
Refactors command processing for better asynchronous operation sequencing and adjusts inter-command delays.

Key changes:
- Default inter-command delay increased from 150ms to 200ms for potentially better system processing by Android. The 850ms pre-TakeScreenshot delay remains.
- Asynchronous screen commands (gestures like scroll, tap, enter; and click actions) now correctly use callbacks to signal their completion before the next command in the queue is processed.
- `processCommandQueue`, `executeSingleCommand`, and a new helper `continueProcessingQueueAfterDelay` manage this updated flow.

This addresses issues with rapid consecutive gestures and commands following scrolls, and provides a slightly longer default pause between commands.
Increases the default inter-command delay to 500ms to provide more processing time for Android between actions. The 850ms pre-TakeScreenshot delay remains unchanged.

This commit also ensures that the refined asynchronous command processing (for gestures and click actions) correctly signals completion via callbacks before the next command in the queue is processed with the new delay.

Key changes:
- Default inter-command delay in `continueProcessingQueueAfterDelay` changed to 500L.
- Confirmed that all command execution paths (sync, async, success, failure) correctly lead to invoking `continueProcessingQueueAfterDelay` to maintain consistent command separation.
I've rigorously verified and refined the command processing logic in ScreenOperatorAccessibilityService. This ensures asynchronous operations (gestures, clicks) fully complete before the next command is processed, and increases the default inter-command delay.

Key changes:
- The default inter-command delay is now 500ms. The 850ms pre-TakeScreenshot delay remains.
- I've renamed the method `continueProcessingQueueAfterDelay` to `scheduleNextCommandProcessing` for clarity.
- I've confirmed that all asynchronous command paths (gestures, clicks, including error/cancellation paths) now exclusively trigger `scheduleNextCommandProcessing` upon their actual completion.
- Synchronous commands correctly have `scheduleNextCommandProcessing` called by `processCommandQueue` after their execution.
- The `scheduleNextCommandProcessing` method (which contains the logic to peek at the next command for potential 850ms TakeScreenshot delay) is now always called *after* the previous command has definitively finished.

This directly addresses issues where delays were not perceived correctly, especially the pre-TakeScreenshot delay and rapid consecutive commands.
Refactored CommandParser.kt to correctly parse commands based on their order of appearance in the input text.

Previously, commands were searched by type in a fixed sequence, which could lead to commands being extracted in a different order than they were written if multiple command types were present in a single message.

The new implementation:
- Consolidates all regex patterns with associated command builders.
- Finds all potential matches for all patterns in the input text.
- Sorts these matches by their start index.
- Iterates through the sorted matches, selecting the first valid, non-overlapping command, thus preserving the original sequence.
- Retains logic for ensuring certain parameterless commands (e.g., TakeScreenshot) are only added once per parsing operation.

This change is crucial for ensuring that the command execution queue receives commands in the intended sequence.
Corrected a compilation error in CommandParser.kt caused by duplicate
declarations of `MatchResultPlaceholder`.

Additionally, refactored `processTextInternal` to:
- Store `CommandTypeEnum` directly with parsed command matches using a new
  `ProcessedMatch` data class.
- Use this directly stored `commandType` for single-instance command checks,
  eliminating a previous, less reliable method of comparing command builder lambdas.
- Removed the `MatchResultPlaceholder` variable as it's no longer needed.

These changes make the parser more robust and fix the build failure.
@Android-PowerUser Android-PowerUser merged commit b06d6fb into Database2 Jun 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant