From a43d81295020cf6fb8002de2905672d03d2faeea Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 26 Sep 2023 05:18:12 +0300 Subject: [PATCH] Allow hiding the menu bar icon closes #40 --- NearDrop/AppDelegate.swift | 6 ++++++ NearbyShare/InboundNearbyConnection.swift | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NearDrop/AppDelegate.swift b/NearDrop/AppDelegate.swift index 9190c69..b327fef 100644 --- a/NearDrop/AppDelegate.swift +++ b/NearDrop/AppDelegate.swift @@ -23,6 +23,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele statusItem=NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) statusItem?.button?.image=NSImage(named: "MenuBarIcon") statusItem?.menu=menu + statusItem?.behavior = .removalAllowed let nc=UNUserNotificationCenter.current() nc.requestAuthorization(options: [.alert, .sound]) { granted, err in @@ -39,6 +40,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele NearbyConnectionManager.shared.mainAppDelegate=self NearbyConnectionManager.shared.becomeVisible() } + + func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + statusItem?.isVisible=true + return true + } func applicationWillTerminate(_ aNotification: Notification) { UNUserNotificationCenter.current().removeAllDeliveredNotifications() diff --git a/NearbyShare/InboundNearbyConnection.swift b/NearbyShare/InboundNearbyConnection.swift index 5f0eba8..9fc317b 100644 --- a/NearbyShare/InboundNearbyConnection.swift +++ b/NearbyShare/InboundNearbyConnection.swift @@ -349,7 +349,7 @@ class InboundNearbyConnection: NearbyConnection{ currentState = .receivingFiles try sendTransferSetupFrame(frame) }catch{ - print("Error \(error)") + lastError=error protocolError() } }