-
Notifications
You must be signed in to change notification settings - Fork 38
remove shared screenResult objects #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove shared screenResult objects #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
lk340
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of nits!
| accessibilityManager.$screenResult | ||
| .map(\.userInteraction.selectedText) | ||
| // Monitor the selectedText property from AccessibilityNotificationsManager | ||
| AccessibilityNotificationsManager.shared.$selectedText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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