AppWindow.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import AppKit
  2. import CoreGraphics
  3. enum AppWindow {
  4. static let width: CGFloat = 1140
  5. static let height: CGFloat = 720
  6. static let minWidth: CGFloat = width
  7. static let minHeight: CGFloat = height
  8. /// Extra top inset for the sidebar when the window is in macOS full screen.
  9. static let fullScreenTopInset: CGFloat = 16
  10. /// Small top breathing room for the embedded Reddit panel.
  11. static let redditTopInset: CGFloat = 30
  12. @MainActor
  13. static func centerOnScreen(_ window: NSWindow) {
  14. guard !window.styleMask.contains(.fullScreen) else { return }
  15. let screen = NSScreen.main ?? window.screen
  16. guard let screen else {
  17. window.center()
  18. return
  19. }
  20. var frame = window.frame
  21. frame.size = NSSize(width: width, height: height)
  22. let visible = screen.visibleFrame
  23. frame.origin.x = visible.origin.x + ((visible.width - frame.width) / 2)
  24. frame.origin.y = visible.origin.y + ((visible.height - frame.height) / 2)
  25. window.setFrame(frame, display: true)
  26. }
  27. }