fix(apple): focus the running instance on notification tap

Add a UNUserNotificationCenterDelegate didReceive handler so tapping a notification
is handled inside the running app — activating and bringing the existing window
forward — instead of falling through to default launch behavior, which on macOS
can surface a second process. The approval/transfer UI is driven by core state, so
activating the window reveals any pending approval.
This commit is contained in:
2026-07-24 18:32:15 +02:00
parent 3042005226
commit d2924f7ce6

View File

@@ -26,6 +26,27 @@ private final class NotificationPresenter: NSObject, UNUserNotificationCenterDel
) async -> UNNotificationPresentationOptions { ) async -> UNNotificationPresentationOptions {
[.banner, .sound, .list] [.banner, .sound, .list]
} }
/// Handle a notification tap inside the running instance and bring the existing
/// window forward, rather than letting the default launch behavior surface (which
/// on macOS can spin up a second process). The approval/transfer UI is driven by
/// core state, so activating the window is enough to reveal a pending approval.
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse
) async {
#if os(macOS)
await MainActor.run {
NSApp.activate(ignoringOtherApps: true)
// Reopen/focus the single main window (activation triggers SwiftUI's
// reopen handling when it was closed).
for window in NSApp.windows where window.canBecomeMain {
window.makeKeyAndOrderFront(nil)
break
}
}
#endif
}
} }
/// Local notification service backed by `UNUserNotificationCenter`. /// Local notification service backed by `UNUserNotificationCenter`.