Repository navigation
Conversation
After the OAuth redirect from Safari, the desktop app stayed in the background while Safari displayed "Authentication Successful". Now NSApp.activate(ignoringOtherApps:true) brings the app to foreground immediately after receiving the callback URL. Fixes #5784 (friction #7) Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile SummaryThis PR fixes a UX friction point where the desktop app remained in the background after completing an OAuth login via Safari. A single line — Key observations:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Safari
participant macOS
participant AppDelegate (OmiApp)
participant AuthService
Safari->>macOS: Open omidesktop://auth/callback?code=...
macOS->>AppDelegate (OmiApp): handleGetURLEvent(_:withReplyEvent:)
AppDelegate (OmiApp)->>AppDelegate (OmiApp): Task { @MainActor in }
AppDelegate (OmiApp)->>AuthService: handleOAuthCallback(url:)
alt callback is for this bundle
AuthService->>AuthService: resume oauthContinuation
AuthService-->>AppDelegate (OmiApp): return (handled)
AppDelegate (OmiApp)->>AppDelegate (OmiApp): NSApp.activate(ignoringOtherApps: true) ✅
else callback is for a different bundle
AuthService->>macOS: NSWorkspace.open(url, withApplicationAt: targetApp) [async, activates: true]
AuthService-->>AppDelegate (OmiApp): return (forwarded)
AppDelegate (OmiApp)->>AppDelegate (OmiApp): NSApp.activate(ignoringOtherApps: true) ⚠️ wrong app activated
macOS-->>macOS: [later] target app activates and takes focus
end
Last reviewed commit: "Activate app after O..." |
| Task { @MainActor in | ||
| AuthService.shared.handleOAuthCallback(url: url) | ||
| // Bring app to foreground after OAuth redirect — Safari stays in front otherwise | ||
| NSApp.activate(ignoringOtherApps: true) | ||
| } |
There was a problem hiding this comment.
Unconditional activation on forwarded OAuth callbacks
NSApp.activate(ignoringOtherApps: true) is called unconditionally even when handleOAuthCallback detects the callback is for a different bundle identifier and forwards it (via forwardOAuthCallback, which already sets config.activates = true on the target app).
The call sequence in that scenario becomes:
handleOAuthCallbackdispatchesNSWorkspace.shared.open(_:withApplicationAt:configuration:)asynchronously to activate the target bundle.handleOAuthCallbackreturns synchronously.NSApp.activate(ignoringOtherApps: true)fires immediately — bringing the wrong app to the front.- Later, the async
NSWorkspace.opencompletion activates the correct target bundle, displacing focus again.
This causes a visible flash of the wrong app and an unnecessary focus steal, even though the forwarding path ultimately wins. Consider having handleOAuthCallback return a Bool indicating whether this instance actually consumed the callback, and only activate when true:
Task { @MainActor in
let handled = AuthService.shared.handleOAuthCallback(url: url)
if handled {
NSApp.activate(ignoringOtherApps: true)
}
}|
Hey @beastoin 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
Summary
NSApp.activate(ignoringOtherApps: true)after handling the OAuth callback URL inhandleGetURLEventFixes #5784 (friction #7)
How it works
When macOS receives the custom URL scheme callback (
omidesktop://auth/callback),handleGetURLEventfires. After passing the URL toAuthService.handleOAuthCallback(), the app now callsNSApp.activate(ignoringOtherApps: true)to bring itself to the foreground — the same pattern used throughout the app (27 existing call sites).Test plan
by AI for @beastoin
🤖 Generated with Claude Code