macos: confirm on quit

This commit is contained in:
Mitchell Hashimoto
2023-03-27 09:41:00 -07:00
parent 9f128afe31
commit 92870e4e60
3 changed files with 61 additions and 10 deletions

View File

@@ -18,15 +18,7 @@ struct GhosttyApp: App {
var body: some Scene {
WindowGroup {
switch ghostty.readiness {
case .loading:
Text("Loading")
case .error:
ErrorView()
case .ready:
Ghostty.TerminalSplit(onClose: Self.closeWindow)
.ghosttyApp(ghostty.app!)
}
ContentView(ghostty: ghostty)
}
.backport.defaultSize(width: 800, height: 600)
.commands {
@@ -110,7 +102,9 @@ struct GhosttyApp: App {
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
@Published var confirmQuit: Bool = false
// See CursedMenuManager for more information.
private var menuManager: CursedMenuManager?
@@ -124,6 +118,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// we can't create from SwiftUI.
menuManager = CursedMenuManager()
}
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
confirmQuit = true
return .terminateLater
}
}
/// SwiftUI as of macOS 13.x provides no way to manage the default menu items that are created