From 6c13dd6966809c79d25c6be3ae4afec0cce47b9b Mon Sep 17 00:00:00 2001 From: vgmoose Date: Sun, 24 Oct 2021 19:21:51 -0400 Subject: [PATCH] bring up config on click --- TheNotch/NotchView.swift | 8 ++++++++ TheNotch/TheNotchApp.swift | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/TheNotch/NotchView.swift b/TheNotch/NotchView.swift index d0e3243..52106b8 100644 --- a/TheNotch/NotchView.swift +++ b/TheNotch/NotchView.swift @@ -5,6 +5,14 @@ struct NotchView: View { RoundedRectangle(cornerRadius: CGFloat(NotchWindow.notchHeight) / 4.0) .fill(Color.black) .frame(width: CGFloat(NotchWindow.notchWidth), height: CGFloat(NotchWindow.notchHeight)) + .onTapGesture { + if !NotchWindow.showInDock { + // when the dock icon is hidden, when the view is touched, make config visible + if TheNotchApp.singleton?.window?.isOnActiveSpace ?? false { + TheNotchApp.singleton?.window?.makeKeyAndOrderFront(self) + } + } + } } } diff --git a/TheNotch/TheNotchApp.swift b/TheNotch/TheNotchApp.swift index 0c9d2d7..bb934e9 100644 --- a/TheNotch/TheNotchApp.swift +++ b/TheNotch/TheNotchApp.swift @@ -4,18 +4,24 @@ import Cocoa @NSApplicationMain class TheNotchApp: NSApplication, NSApplicationDelegate { + var window: NSWindow? + static var singleton: TheNotchApp? + override init() { super.init() delegate = self -// mainMenu = mainAppMenu } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { + window?.makeKeyAndOrderFront(sender) + return true + } + func applicationDidFinishLaunching(_ notification: Notification) { - Swift.print("wasup") let window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 450, height: 200), styleMask: [.titled, .closable, .miniaturizable, .resizable], @@ -23,6 +29,7 @@ class TheNotchApp: NSApplication, NSApplicationDelegate { ) window.center() window.title = "The Notch" + window.isReleasedWhenClosed = false let view = ConfigView().padding(20).frame(width: 450, height: 200) window.contentView = NSHostingView(rootView: view) @@ -31,5 +38,7 @@ class TheNotchApp: NSApplication, NSApplicationDelegate { NotchWindow().makeKeyAndOrderFront(self) window.makeKeyAndOrderFront(true) + self.window = window + TheNotchApp.singleton = self } }