mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
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:
@@ -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`.
|
||||||
|
|||||||
Reference in New Issue
Block a user