Fix WindowEvent::Destroyed might fire twice on macOS (#831)

This commit is contained in:
Ngo Iok Ui (Wu Yu Wei)
2023-11-06 12:46:05 +09:00
committed by GitHub
parent a57e08565e
commit e33104c2cf
2 changed files with 8 additions and 15 deletions

6
.changes/mac-destroy.md Normal file
View File

@@ -0,0 +1,6 @@
---
"tao": patch
---
On macOS, fix `WindowEvent::Destroyed` may fire twice.

View File

@@ -20,15 +20,7 @@ use objc::{
use crate::{
dpi::LogicalSize,
event::{Event, WindowEvent},
platform_impl::platform::{
app_state::AppState,
event::EventWrapper,
ffi,
util::IdRef,
window::{get_window_id, SharedState},
},
window::WindowId,
platform_impl::platform::{ffi, util::IdRef, window::SharedState},
};
pub fn is_main_thread() -> bool {
@@ -251,14 +243,9 @@ pub unsafe fn set_focus(ns_window: id) {
// through the `IdRef` because otherwise it would dereference free'd memory
pub unsafe fn close_async(ns_window: IdRef) {
let ns_window = MainThreadSafe(ns_window);
Queue::main().exec_async(move || {
run_on_main(move || {
autoreleasepool(move || {
ns_window.close();
let event = Event::WindowEvent {
window_id: WindowId(get_window_id(*ns_window.0)),
event: WindowEvent::Destroyed,
};
AppState::queue_event(EventWrapper::StaticEvent(event));
});
});
}