mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-22 19:18:36 +00:00
macos: confirm on quit
This commit is contained in:
48
macos/Sources/ContentView.swift
Normal file
48
macos/Sources/ContentView.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import SwiftUI
|
||||
import GhosttyKit
|
||||
|
||||
struct ContentView: View {
|
||||
let ghostty: Ghostty.AppState
|
||||
|
||||
@EnvironmentObject private var appDelegate: AppDelegate
|
||||
|
||||
var body: some View {
|
||||
switch ghostty.readiness {
|
||||
case .loading:
|
||||
Text("Loading")
|
||||
.onChange(of: appDelegate.confirmQuit) { value in
|
||||
guard value else { return }
|
||||
NSApplication.shared.reply(toApplicationShouldTerminate: true)
|
||||
}
|
||||
case .error:
|
||||
ErrorView()
|
||||
.onChange(of: appDelegate.confirmQuit) { value in
|
||||
guard value else { return }
|
||||
NSApplication.shared.reply(toApplicationShouldTerminate: true)
|
||||
}
|
||||
case .ready:
|
||||
Ghostty.TerminalSplit(onClose: Self.closeWindow)
|
||||
.ghosttyApp(ghostty.app!)
|
||||
.confirmationDialog(
|
||||
"Quit Ghostty?",
|
||||
isPresented: $appDelegate.confirmQuit) {
|
||||
Button("Close Ghostty", role: .destructive) {
|
||||
NSApplication.shared.reply(toApplicationShouldTerminate: true)
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
|
||||
Button("Cancel", role: .cancel) {
|
||||
NSApplication.shared.reply(toApplicationShouldTerminate: false)
|
||||
}
|
||||
.keyboardShortcut(.cancelAction)
|
||||
} message: {
|
||||
Text("All terminal sessions will be terminated.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func closeWindow() {
|
||||
guard let currentWindow = NSApp.keyWindow else { return }
|
||||
currentWindow.close()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user