From d2924f7ce67af9588a763016f05c87e6888da9c3 Mon Sep 17 00:00:00 2001 From: cdricms <36056008+cdricms@users.noreply.github.com> Date: Fri, 24 Jul 2026 18:32:15 +0200 Subject: [PATCH] fix(apple): focus the running instance on notification tap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../Core/LocalNotificationService.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apple/VniDrop/Core/LocalNotificationService.swift b/apple/VniDrop/Core/LocalNotificationService.swift index 4f7f11c..8b246e2 100644 --- a/apple/VniDrop/Core/LocalNotificationService.swift +++ b/apple/VniDrop/Core/LocalNotificationService.swift @@ -26,6 +26,27 @@ private final class NotificationPresenter: NSObject, UNUserNotificationCenterDel ) async -> UNNotificationPresentationOptions { [.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`.