swiftui-multiplatform/macOS/AppDelegate.swift
Angelo Stavrow 549ad3039f
Clean up project warnings (#199)
* Set "recommended project settings" for Mac app

* Add default fallback for font typingAttribute

* Clean up linter errors

* Update extension iconset

* Fix spm errors and upgrade sparkle (#203)

* Switch WriteFreely package import from ssh to https

* Sign macOS project target for Development

This fixes a crash-on-launch bug when running Product > Run from Xcode (Product > Archive should work correctly). See https://github.com/sparkle-project/Sparkle/issues/2056 for more details.

Bug introduced by commit:
671b0540ac

* Update Sparkle to v2.0 from official repo

Previously, we forked the repo to the WriteFreely org because Sparkle didn't support tag-based SPM updates. We therefore had to pull from the `master` branch, so forking insulated us from unexpected changes.

As of 2.x Sparkle now allows for tag-based updating via SPM; we'll allow patch updates but stop short of 2.1 until we can vet changes.

* Add MacUpdatesViewModel ObservableObject

* Use MacUpdatesViewModel to handle Sparkle update logic
2022-04-02 08:04:50 -04:00

39 lines
1.5 KiB
Swift

import Cocoa
import Sparkle
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 by activating Finder.app (note that
// this will bring any Finder windows that are behind other apps to the foreground).
func applicationDidChangeOcclusionState(_ notification: Notification) {
if let window = NSApp.windows.first, window.isMiniaturized {
NSWorkspace.shared.runningApplications.first(where: {
$0.activationPolicy == .regular
})?.activate(options: .activateAllWindows)
}
}
lazy var windows = NSWindow()
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag {
for window in sender.windows {
window.makeKeyAndOrderFront(self)
}
}
return true
}
}