remove shared screenResult objects#367
remove shared screenResult objects#367timlenardo merged 2 commits intorefactor/context-fetching-servicefrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR refactors the context loading architecture by eliminating a shared ScreenResult object from AccessibilityNotificationsManager that was causing context contamination bugs. Previously, the system used a single global ScreenResult instance that could be overwritten by concurrent operations, leading to situations where context from one application would appear in another application's context.
The refactoring introduces several key changes:
-
New ScreenResult struct: A standalone
ScreenResultstruct is created inData/Structures/ScreenResult.swiftwith comprehensive initialization options and proper encapsulation of application context data. -
Context creation moved to ContextFetchingService: Instead of mutating a shared object,
ContextFetchingServicenow creates individualScreenResultinstances for each context operation and passes them toOnitPanelState.addAutoContext(). -
Parameter-based data flow: The
addAutoContextmethod signature is updated to accept an optionalscreenResultparameter, making each context operation self-contained and eliminating race conditions. -
Temporary selectedText property: A
@Published selectedTextproperty is added toAccessibilityNotificationsManagerto maintain compatibility withQuickEditManager, though this is acknowledged as a temporary solution until highlighted text logic is moved to a dedicated manager.
This architectural shift moves from a shared mutable state pattern to a more functional approach where data flows explicitly through method parameters, improving isolation between context operations and preventing cross-contamination.
Confidence score: 3/5
• This PR has a significant architectural improvement but introduces some inconsistencies that could cause issues
• The main concern is the inconsistent data source usage in QuickEditManager's caretDidDisappear() method, which uses a different source than the text selection monitoring setup, potentially creating race conditions
• Files that need more attention: macos/Onit/UI/QuickEdit/QuickEditManager.swift for the data source inconsistency issue
5 files reviewed, 3 comments
Niduank
left a comment
There was a problem hiding this comment.
We should create a ticket to:
- Remove the
showDebugfunctions fromAccessibilityNotificationsManagerandContextFetchingService - Ensure consistency of the highlightedText source in
QuickEditManagerand test it in Tethered mode
Other than that, not much.
44b29b0 to
830ae20
Compare
# Conflicts: # macos/Onit/Accessibility/Notifications/AccessibilityNotificationsManager.swift
adb64dd to
077f60f
Compare
| accessibilityManager.$screenResult | ||
| .map(\.userInteraction.selectedText) | ||
| // Monitor the selectedText property from AccessibilityNotificationsManager | ||
| AccessibilityNotificationsManager.shared.$selectedText |
There was a problem hiding this comment.
We can use our accessibilityManager property here
|
@lk340 - I am going to handle your nits in a separate PR since it will be painful to keep this in tandem with the new repository. Merging! |
Instead of having a shared "ScreenResult" object on the AccessibilityNotificationsManager, we should create them when loading context, and pass them to the OnitPanelState to generate the context objects.
I've noticed a number of bugs in the Context adding: for example, sometimes, the context loads and it has the text from some other application. I suspect that moving away from the shared 'ScreenResult' object will solve some of these issues.
A few notes