|
|
@@ -7,10 +7,41 @@
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
+enum AppWindowConfiguration {
|
|
|
+ static let defaultContentSize = NSSize(width: 1120, height: 750)
|
|
|
+ static let minimumContentSize = NSSize(width: 1120, height: 750)
|
|
|
+
|
|
|
+ @MainActor
|
|
|
+ static func apply(to window: NSWindow) {
|
|
|
+ window.minSize = minimumContentSize
|
|
|
+ window.isRestorable = false
|
|
|
+ window.title = "App for Indeed"
|
|
|
+ window.styleMask.insert(.fullSizeContentView)
|
|
|
+ window.titlebarAppearsTransparent = true
|
|
|
+ window.titleVisibility = .hidden
|
|
|
+ window.isMovableByWindowBackground = true
|
|
|
+
|
|
|
+ let targetContent = NSRect(origin: .zero, size: defaultContentSize)
|
|
|
+ let targetFrame = window.frameRect(forContentRect: targetContent)
|
|
|
+ var frame = targetFrame
|
|
|
+ let current = window.frame
|
|
|
+ frame.origin.x = current.midX - frame.width / 2
|
|
|
+ frame.origin.y = current.midY - frame.height / 2
|
|
|
+ window.setFrame(frame, display: false, animate: false)
|
|
|
+ window.setContentSize(defaultContentSize)
|
|
|
+ }
|
|
|
+
|
|
|
+ @MainActor
|
|
|
+ static func mainWindow(in app: NSApplication = .shared) -> NSWindow? {
|
|
|
+ app.mainWindow
|
|
|
+ ?? app.keyWindow
|
|
|
+ ?? app.windows.first(where: { $0.isVisible && $0.canBecomeKey })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
@main
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
|
- private let minimumWindowSize = NSSize(width: 1120, height: 700)
|
|
|
/// Avoids hammering StoreKit when `didBecomeActive` fires in quick succession (e.g. after system sheets).
|
|
|
private var lastSubscriptionRefreshAt: Date?
|
|
|
|
|
|
@@ -45,23 +76,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
NotificationCenter.default.post(name: .subscriptionStatusDidChange, object: nil)
|
|
|
}
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
+ applyDefaultWindowSize()
|
|
|
+ }
|
|
|
+
|
|
|
+ @MainActor
|
|
|
+ private func applyDefaultWindowSize() {
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
- guard
|
|
|
- let self,
|
|
|
- let window = NSApp.windows.first
|
|
|
- else { return }
|
|
|
-
|
|
|
- window.minSize = self.minimumWindowSize
|
|
|
- window.setContentSize(self.minimumWindowSize)
|
|
|
- // Prevents "className=(null)" restoration warnings; layout is applied each launch.
|
|
|
- window.isRestorable = false
|
|
|
- window.title = "App for Indeed"
|
|
|
- window.styleMask.insert(.fullSizeContentView)
|
|
|
- window.titlebarAppearsTransparent = true
|
|
|
- window.titleVisibility = .hidden
|
|
|
- window.isMovableByWindowBackground = true
|
|
|
+ guard let self, let window = AppWindowConfiguration.mainWindow() else { return }
|
|
|
+ AppWindowConfiguration.apply(to: window)
|
|
|
window.center()
|
|
|
window.makeKeyAndOrderFront(nil)
|
|
|
+
|
|
|
+ // Layout can run after the first pass; enforce default size once more.
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
|
|
|
+ guard self != nil, let window = AppWindowConfiguration.mainWindow() else { return }
|
|
|
+ AppWindowConfiguration.apply(to: window)
|
|
|
+ window.center()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -76,4 +107,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|