|
|
@@ -34,7 +34,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
|
applyBundledAppIcon()
|
|
|
- configureMainWindowIfNeeded()
|
|
|
+ configureMainWindowIfNeeded(centerOnLaunch: true)
|
|
|
setupStatusBarItem()
|
|
|
StatusBarAppIconsController.shared.start()
|
|
|
presentLauncherAndPaywallOnLaunch()
|
|
|
@@ -272,7 +272,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
}
|
|
|
|
|
|
private func showMainWindow() {
|
|
|
- configureMainWindowIfNeeded()
|
|
|
+ configureMainWindowIfNeeded(centerOnLaunch: false)
|
|
|
NSApp.setActivationPolicy(.regular)
|
|
|
NSRunningApplication.current.activate(options: [.activateAllWindows, .activateIgnoringOtherApps])
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
@@ -289,7 +289,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func configureMainWindowIfNeeded() {
|
|
|
+ private func configureMainWindowIfNeeded(centerOnLaunch: Bool = false) {
|
|
|
guard let window = launcherWindow else { return }
|
|
|
observeLauncherWindowResign(window)
|
|
|
window.title = "My Apps"
|
|
|
@@ -317,6 +317,26 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
|
|
|
)
|
|
|
window.setFrame(targetFrame, display: true)
|
|
|
}
|
|
|
+
|
|
|
+ if centerOnLaunch {
|
|
|
+ centerWindowOnCurrentOrPrimaryScreen(window)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func centerWindowOnCurrentOrPrimaryScreen(_ window: NSWindow) {
|
|
|
+ // Prefer the screen the window is currently on; fall back to the primary screen.
|
|
|
+ let screen = window.screen ?? NSScreen.main
|
|
|
+ guard let visibleFrame = screen?.visibleFrame else { return }
|
|
|
+
|
|
|
+ let frameSize = window.frame.size
|
|
|
+ let unclampedX = visibleFrame.midX - (frameSize.width / 2)
|
|
|
+ let unclampedY = visibleFrame.midY - (frameSize.height / 2)
|
|
|
+
|
|
|
+ // Clamp so we don't move the window completely off-screen on small displays.
|
|
|
+ let clampedX = min(max(unclampedX, visibleFrame.minX), visibleFrame.maxX - frameSize.width)
|
|
|
+ let clampedY = min(max(unclampedY, visibleFrame.minY), visibleFrame.maxY - frameSize.height)
|
|
|
+
|
|
|
+ window.setFrame(NSRect(origin: NSPoint(x: clampedX, y: clampedY), size: frameSize), display: false)
|
|
|
}
|
|
|
|
|
|
private func observeLauncherWindowResign(_ window: NSWindow) {
|