2020-12-22 20:06:25 +00:00
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
2021-08-20 19:00:34 +00:00
|
|
|
|
|
|
|
// MARK: - Window handling when miniaturized into app icon on the Dock
|
|
|
|
// Credit to Henry Cooper (pillboxer) on GitHub:
|
|
|
|
// https://github.com/tact/beta-bugs/issues/31#issuecomment-855914705
|
|
|
|
|
|
|
|
// If the window is currently minimized into the Dock, de-miniaturize it (note that if it's minimized
|
|
|
|
// and the user uses OPT+TAB to switch to it, it will be de-miniaturized and brought to the foreground).
|
|
|
|
func applicationDidBecomeActive(_ notification: Notification) {
|
|
|
|
if let window = NSApp.windows.first {
|
|
|
|
window.deminiaturize(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 12:30:55 +00:00
|
|
|
// If we're miniaturizing the window, deactivate it as well.
|
|
|
|
// Credit to KHKnobl on GitHub:
|
|
|
|
// https://github.com/writefreely/writefreely-swiftui-multiplatform/issues/135#issuecomment-1101713817
|
2021-08-20 19:00:34 +00:00
|
|
|
func applicationDidChangeOcclusionState(_ notification: Notification) {
|
|
|
|
if let window = NSApp.windows.first, window.isMiniaturized {
|
2022-09-10 12:30:55 +00:00
|
|
|
NSApp.hide(self)
|
2021-08-20 19:00:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lazy var windows = NSWindow()
|
|
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
|
|
if !flag {
|
|
|
|
for window in sender.windows {
|
|
|
|
window.makeKeyAndOrderFront(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-12-22 20:06:25 +00:00
|
|
|
}
|