|
|
@@ -9,13 +9,21 @@ import Cocoa
|
|
9
|
9
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
10
|
10
|
|
|
11
|
11
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
12
|
|
- DispatchQueue.main.async {
|
|
13
|
|
- self.configureMainWindow()
|
|
14
|
|
- }
|
|
|
12
|
+ configureMainWindow()
|
|
|
13
|
+ NSApp.activate(ignoringOtherApps: true)
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ func applicationShouldRestoreApplicationState(_ app: NSApplication) -> Bool {
|
|
|
17
|
+ false
|
|
15
|
18
|
}
|
|
16
|
19
|
|
|
17
|
20
|
private func configureMainWindow() {
|
|
18
|
|
- guard let window = NSApplication.shared.windows.first else { return }
|
|
|
21
|
+ guard let window = mainWindow else {
|
|
|
22
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
23
|
+ self?.configureMainWindow()
|
|
|
24
|
+ }
|
|
|
25
|
+ return
|
|
|
26
|
+ }
|
|
19
|
27
|
|
|
20
|
28
|
window.title = "Smart Printer"
|
|
21
|
29
|
window.titlebarAppearsTransparent = true
|
|
|
@@ -24,8 +32,35 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
24
|
32
|
window.isMovableByWindowBackground = true
|
|
25
|
33
|
window.backgroundColor = AppTheme.background
|
|
26
|
34
|
window.setContentSize(NSSize(width: AppTheme.windowWidth, height: AppTheme.windowHeight))
|
|
27
|
|
- window.center()
|
|
28
|
35
|
window.minSize = NSSize(width: AppTheme.windowMinWidth, height: AppTheme.windowMinHeight)
|
|
|
36
|
+ window.isRestorable = false
|
|
|
37
|
+ centerWindowOnScreen(window)
|
|
|
38
|
+
|
|
|
39
|
+ DispatchQueue.main.async {
|
|
|
40
|
+ self.centerWindowOnScreen(window)
|
|
|
41
|
+ window.makeKeyAndOrderFront(nil)
|
|
|
42
|
+ }
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ private func centerWindowOnScreen(_ window: NSWindow) {
|
|
|
46
|
+ let screen = NSScreen.main ?? window.screen ?? NSScreen.screens.first
|
|
|
47
|
+ guard let visibleFrame = screen?.visibleFrame else {
|
|
|
48
|
+ window.center()
|
|
|
49
|
+ return
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ var frame = window.frame
|
|
|
53
|
+ frame.size.width = min(frame.width, visibleFrame.width)
|
|
|
54
|
+ frame.size.height = min(frame.height, visibleFrame.height)
|
|
|
55
|
+ frame.origin.x = visibleFrame.midX - frame.width / 2
|
|
|
56
|
+ frame.origin.y = visibleFrame.midY - frame.height / 2
|
|
|
57
|
+ window.setFrame(frame, display: true)
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ private var mainWindow: NSWindow? {
|
|
|
61
|
+ NSApplication.shared.mainWindow
|
|
|
62
|
+ ?? NSApplication.shared.keyWindow
|
|
|
63
|
+ ?? NSApplication.shared.windows.first(where: \.canBecomeMain)
|
|
29
|
64
|
}
|
|
30
|
65
|
|
|
31
|
66
|
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
|