ghostty/macos/Sources/Features/About/AboutController.swift
Mitchell Hashimoto 2e74a0f9d4
macos: custom about window so we can be a first responder
Fixes #1052

This implements the about window as a custom window with a view
controller. This lets us implement the proper responder chain so that
our custom close window IBActions do the right thing.

This has an additional benefit that we can easily customize this window
going forward.
2023-12-17 15:51:04 -08:00

38 lines
914 B
Swift

import Foundation
import Cocoa
import SwiftUI
class AboutController: NSWindowController, NSWindowDelegate {
static let shared: AboutController = AboutController()
override var windowNibName: NSNib.Name? { "About" }
override func windowDidLoad() {
guard let window = window else { return }
window.center()
window.contentView = NSHostingView(rootView: AboutView())
}
// MARK: - Functions
func show() {
guard let window = window else { return }
window.makeKeyAndOrderFront(nil)
}
//MARK: - First Responder
@IBAction func close(_ sender: Any) {
self.window?.performClose(sender)
}
@IBAction func closeWindow(_ sender: Any) {
self.window?.performClose(sender)
}
// This is called when "escape" is pressed.
@objc func cancel(_ sender: Any?) {
close()
}
}