|
@@ -9,13 +9,21 @@ import Cocoa
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
|
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
|
- DispatchQueue.main.async {
|
|
|
|
|
- self.configureMainWindow()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ configureMainWindow()
|
|
|
|
|
+ NSApp.activate(ignoringOtherApps: true)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ func applicationShouldRestoreApplicationState(_ app: NSApplication) -> Bool {
|
|
|
|
|
+ false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func configureMainWindow() {
|
|
private func configureMainWindow() {
|
|
|
- guard let window = NSApplication.shared.windows.first else { return }
|
|
|
|
|
|
|
+ guard let window = mainWindow else {
|
|
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
|
|
+ self?.configureMainWindow()
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
window.title = "Smart Printer"
|
|
window.title = "Smart Printer"
|
|
|
window.titlebarAppearsTransparent = true
|
|
window.titlebarAppearsTransparent = true
|
|
@@ -24,8 +32,35 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
window.isMovableByWindowBackground = true
|
|
window.isMovableByWindowBackground = true
|
|
|
window.backgroundColor = AppTheme.background
|
|
window.backgroundColor = AppTheme.background
|
|
|
window.setContentSize(NSSize(width: AppTheme.windowWidth, height: AppTheme.windowHeight))
|
|
window.setContentSize(NSSize(width: AppTheme.windowWidth, height: AppTheme.windowHeight))
|
|
|
- window.center()
|
|
|
|
|
window.minSize = NSSize(width: AppTheme.windowMinWidth, height: AppTheme.windowMinHeight)
|
|
window.minSize = NSSize(width: AppTheme.windowMinWidth, height: AppTheme.windowMinHeight)
|
|
|
|
|
+ window.isRestorable = false
|
|
|
|
|
+ centerWindowOnScreen(window)
|
|
|
|
|
+
|
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
|
+ self.centerWindowOnScreen(window)
|
|
|
|
|
+ window.makeKeyAndOrderFront(nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func centerWindowOnScreen(_ window: NSWindow) {
|
|
|
|
|
+ let screen = NSScreen.main ?? window.screen ?? NSScreen.screens.first
|
|
|
|
|
+ guard let visibleFrame = screen?.visibleFrame else {
|
|
|
|
|
+ window.center()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var frame = window.frame
|
|
|
|
|
+ frame.size.width = min(frame.width, visibleFrame.width)
|
|
|
|
|
+ frame.size.height = min(frame.height, visibleFrame.height)
|
|
|
|
|
+ frame.origin.x = visibleFrame.midX - frame.width / 2
|
|
|
|
|
+ frame.origin.y = visibleFrame.midY - frame.height / 2
|
|
|
|
|
+ window.setFrame(frame, display: true)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private var mainWindow: NSWindow? {
|
|
|
|
|
+ NSApplication.shared.mainWindow
|
|
|
|
|
+ ?? NSApplication.shared.keyWindow
|
|
|
|
|
+ ?? NSApplication.shared.windows.first(where: \.canBecomeMain)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
|
|
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
|