1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-26 14:54:16 +03:00

honor the window_close_confirmation config option when quitting

This commit is contained in:
Quan Tong 2023-10-12 11:36:54 +07:00 committed by Wez Furlong
parent 15489249b8
commit f2a9c06247

View File

@ -7,6 +7,7 @@ use cocoa::appkit::NSApplicationTerminateReply;
use cocoa::base::id;
use cocoa::foundation::NSInteger;
use config::keyassignment::KeyAssignment;
use config::WindowCloseConfirmation;
use objc::declare::ClassDecl;
use objc::rc::StrongPtr;
use objc::runtime::{Class, Object, Sel, BOOL, NO, YES};
@ -21,6 +22,9 @@ extern "C" fn application_should_terminate(
) -> u64 {
log::debug!("application termination requested");
unsafe {
match config::configuration().window_close_confirmation {
WindowCloseConfirmation::NeverPrompt => terminate_now(),
WindowCloseConfirmation::AlwaysPrompt => {
let alert: id = msg_send![class!(NSAlert), alloc];
let alert: id = msg_send![alert, init];
let message_text = nsstring("Terminate WezTerm?");
@ -42,13 +46,19 @@ extern "C" fn application_should_terminate(
if result == NSModalResponseCancel {
NSApplicationTerminateReply::NSTerminateCancel as u64
} else {
terminate_now()
}
}
}
}
}
fn terminate_now() -> u64 {
if let Some(conn) = Connection::get() {
conn.terminate_message_loop();
}
NSApplicationTerminateReply::NSTerminateNow as u64
}
}
}
extern "C" fn application_will_finish_launching(
_self: &mut Object,