fix(app): drop fullscreen control from About/Keyboard Shortcuts windows
SwiftUI's Window scene defaults to a full titlebar with a fullscreen button even for small fixed-size reference panels that have no reason to support it, matching neither platform convention nor how the main app window is styled.
This commit is contained in:
@@ -54,11 +54,13 @@ struct OutpostApp: App {
|
||||
#if os(macOS)
|
||||
Window("About Outpost", id: "about") {
|
||||
AboutView()
|
||||
.disablesFullScreen()
|
||||
}
|
||||
.windowResizability(.contentSize)
|
||||
|
||||
Window("Keyboard Shortcuts", id: "keyboard-shortcuts") {
|
||||
KeyboardShortcutsView()
|
||||
.disablesFullScreen()
|
||||
}
|
||||
.windowResizability(.contentSize)
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#if os(macOS)
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
/// Grabs the hosting `NSWindow` once it's attached to a screen, for the
|
||||
/// handful of things SwiftUI's `Window` scene doesn't expose a modifier for.
|
||||
private struct WindowConfigurator: NSViewRepresentable {
|
||||
let configure: (NSWindow) -> Void
|
||||
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
let view = NSView()
|
||||
DispatchQueue.main.async {
|
||||
if let window = view.window {
|
||||
configure(window)
|
||||
}
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
func updateNSView(_ nsView: NSView, context: Context) {}
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// `Window` scenes default to a full standard titlebar, fullscreen
|
||||
/// (green) button included — not appropriate for fixed-size reference
|
||||
/// panels like About or Keyboard Shortcuts, which have no reason to
|
||||
/// support fullscreen at all.
|
||||
func disablesFullScreen() -> some View {
|
||||
background(
|
||||
WindowConfigurator { window in
|
||||
window.collectionBehavior.remove(.fullScreenPrimary)
|
||||
window.collectionBehavior.insert(.fullScreenNone)
|
||||
window.standardWindowButton(.zoomButton)?.isHidden = true
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user