Skip to content

Commit a4dcb28

Browse files
fix(parser): Ensure sequential command extraction order
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.
1 parent 4830719 commit a4dcb28

2 files changed

Lines changed: 211 additions & 629 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/ScreenOperatorAccessibilityService.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ class ScreenOperatorAccessibilityService : AccessibilityService() {
115115
serviceInstance!!.commandQueue.add(command)
116116
Log.d(TAG, "Command $command added to queue. Queue size: ${serviceInstance!!.commandQueue.size}")
117117

118-
if (!serviceInstance!!.isProcessingQueue.get()) {
119-
serviceInstance!!.processCommandQueue() // Call the instance method
118+
// Ensure processCommandQueue is called on the service's handler thread
119+
serviceInstance!!.handler.post {
120+
serviceInstance!!.processCommandQueue()
120121
}
121122
}
122123

0 commit comments

Comments
 (0)