mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
884da073e9
* Add error handling to Mac app * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Refactor class to use protocol * Add environment object to settings window * Improve deactivation of app when miniaturizing * Chagne dispatch type when creating new post * Bump version and build number * Remove unnecessary TODO comment * Update change log * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Add environment object to settings window * Improve deactivation of app when miniaturizing * Chagne dispatch type when creating new post * Improve default window size (#220) * Clean up unnecessary import * Set idealWidth property on sidebars * Unset selected post on collection change (#218) * Unset selected post when changing collection * Update change log * Bump build number and update change log
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
import Cocoa
|
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// 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
|
|
func applicationDidChangeOcclusionState(_ notification: Notification) {
|
|
if let window = NSApp.windows.first, window.isMiniaturized {
|
|
NSApp.hide(self)
|
|
}
|
|
}
|
|
|
|
lazy var windows = NSWindow()
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
if !flag {
|
|
for window in sender.windows {
|
|
window.makeKeyAndOrderFront(self)
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
}
|