mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: only show alert once
This commit is contained in:
@ -27,6 +27,9 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
|
|||||||
/// Fullscreen state management.
|
/// Fullscreen state management.
|
||||||
private let fullscreenHandler = FullScreenHandler()
|
private let fullscreenHandler = FullScreenHandler()
|
||||||
|
|
||||||
|
/// True when an alert is active so we don't overlap multiple.
|
||||||
|
private var alert: NSAlert? = nil
|
||||||
|
|
||||||
/// The style mask to use for the new window
|
/// The style mask to use for the new window
|
||||||
private var styleMask: NSWindow.StyleMask {
|
private var styleMask: NSWindow.StyleMask {
|
||||||
var mask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable]
|
var mask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable]
|
||||||
@ -119,23 +122,28 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
|
|||||||
// If our surfaces don't require confirmation, close.
|
// If our surfaces don't require confirmation, close.
|
||||||
if (!node.needsConfirmQuit()) { return true }
|
if (!node.needsConfirmQuit()) { return true }
|
||||||
|
|
||||||
// We require confirmation, so show an alert.
|
// We require confirmation, so show an alert as long as we aren't already.
|
||||||
let alert = NSAlert()
|
if (alert == nil) {
|
||||||
alert.messageText = "Close Terminal?"
|
let alert = NSAlert()
|
||||||
alert.informativeText = "The terminal still has a running process. If you close the " +
|
alert.messageText = "Close Terminal?"
|
||||||
|
alert.informativeText = "The terminal still has a running process. If you close the " +
|
||||||
"terminal the process will be killed."
|
"terminal the process will be killed."
|
||||||
alert.addButton(withTitle: "Close the Terminal")
|
alert.addButton(withTitle: "Close the Terminal")
|
||||||
alert.addButton(withTitle: "Cancel")
|
alert.addButton(withTitle: "Cancel")
|
||||||
alert.alertStyle = .warning
|
alert.alertStyle = .warning
|
||||||
alert.beginSheetModal(for: window, completionHandler: { response in
|
alert.beginSheetModal(for: window, completionHandler: { response in
|
||||||
switch (response) {
|
self.alert = nil
|
||||||
case .alertFirstButtonReturn:
|
switch (response) {
|
||||||
window.close()
|
case .alertFirstButtonReturn:
|
||||||
|
window.close()
|
||||||
default:
|
|
||||||
break
|
default:
|
||||||
}
|
break
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.alert = alert
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user