Log frontmost macOS app name and bundle id for anchoring diagnostics#126
Merged
Conversation
Capture the frontmost application's localized name and bundle identifier alongside the PID via a single AppleScript call, and include that label in snippet-window anchoring log messages. This makes it possible to attribute anchoring failures (e.g. AXFocusedUIElement unavailable) to a specific app when reviewing diagnostics.log. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves macOS anchoring diagnostics by threading the frontmost application’s identifying information (PID, localized name, bundle identifier) through the caret/focused-element anchoring flow so log lines can be attributed to a specific app during later triage.
Changes:
- Replace PID-only capture with a
FrontmostApplicationrecord (pid/name/bundle) resolved via a single AppleScript call. - Pass a “frontmost app” label through
NavigatorintoMacOSTextAnchorand append it to key Info/Error log lines. - Extend
ActivateProcessto optionally include the app name in activation logging.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Neptuo.Productivity.SnippetManager.Avalonia/Navigator.cs | Captures/stores the full frontmost-app record, passes a derived label into anchoring, and logs app info when restoring focus. |
| src/Neptuo.Productivity.SnippetManager.Avalonia/MacOSTextAnchor.cs | Adds an optional context suffix to anchoring pipeline log lines for better attribution. |
| src/Neptuo.Productivity.SnippetManager.Avalonia/MacOSApplication.cs | Introduces FrontmostApplication, updates frontmost-app resolution to return pid/name/bundle, and extends activation logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback on PR #126: - Quote Name/BundleIdentifier with JSON-style escaping in FrontmostApplication.DescribeForLog so embedded quotes, tabs, or control characters cannot make log lines ambiguous. Missing values render as <unknown> (unquoted) to remain distinguishable from an empty string. - Switch the AppleScript delimiter from tab to ASCII Unit Separator (character id 31 / 0x1F), which cannot appear in a macOS app name or bundle id, and defensively log when fewer than 3 fields are returned. - Compute the 'Frontmost app: ...' suffix once in UpdateWindowPositionAnchor instead of duplicating it in each branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the snippet window fails to anchor to the focused text field on macOS,
diagnostics.logonly recorded the frontmost application's PID. By the time I went to triage the log later, those PIDs were long gone, so it was impossible to tell which apps were breaking anchoring (the current log has five PIDs that always fail and a Chromium-ish PID that intermittently produces degenerate(0,982,1,1)caret bounds, but none of them are identifiable).This PR threads the frontmost app's localized name and bundle identifier through the anchoring path so every related log line is attributable to a specific app.
Approach
MacOSApplication.GetFrontmostApplicationProcessId()becomesGetFrontmostApplication()and returns a newFrontmostApplicationrecord (ProcessId,Name,BundleIdentifier). A singleosascriptcall returnspid \t name \t bundlewithtryblocks aroundname/bundle identifierso processes that don't expose them still yield a usable PID.Navigatorstores the whole record (was justint?) and passes afrontmostAppLabelstring intoUpdateWindowPositionAnchorand on intoMacOSTextAnchor.TryGetForFocusedElement.MacOSTextAnchorappendsFrontmost app: pid=..., name='...', bundle='...'.to every Info/Error line in the anchor pipeline: the initial attempt, eachAXFocusedUIElement/AXFocusedWindow/AXBoundsForRangefailure, the degenerate-bounds rejection, and the final centered-placement fallback. Empty labels produce no suffix, so behavior is unchanged when the PID capture fails.ActivateProcessalso accepts an optionalnameso the "Restoring focus to macOS process ..." line includes it.Notes for reviewers
tabas a separator and empty strings for unavailable fields; confirmed on macOS the output is e.g.94697\tgithub\tcom.copilot.tauri\n.SelectedTextBoundsPlausibilityTestsstill pass (110/110).MacOSTextAnchor.TryGetForFocusedElementgained an optional parameter with a default, so callers outside the Avalonia project are unaffected.