macOS: Remove global HANDLER and AppState (#3389)

This commit is contained in:
Mads Marquart 2024-01-14 03:37:53 +01:00 committed by GitHub
parent 22311802b5
commit 40b61d2d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 683 additions and 878 deletions

View file

@ -7,11 +7,6 @@ use std::{
time::Instant,
};
use crate::platform_impl::platform::{
app_state::AppState,
event_loop::{stop_app_on_panic, PanicInfo},
ffi,
};
use core_foundation::base::{CFIndex, CFOptionFlags, CFRelease};
use core_foundation::date::CFAbsoluteTimeGetCurrent;
use core_foundation::runloop::{
@ -19,10 +14,16 @@ use core_foundation::runloop::{
CFRunLoopActivity, CFRunLoopAddObserver, CFRunLoopAddTimer, CFRunLoopGetMain,
CFRunLoopObserverCallBack, CFRunLoopObserverContext, CFRunLoopObserverCreate,
CFRunLoopObserverRef, CFRunLoopRef, CFRunLoopTimerCreate, CFRunLoopTimerInvalidate,
CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate,
CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, CFRunLoopWakeUp,
};
use icrate::Foundation::MainThreadMarker;
use super::ffi;
use super::{
app_delegate::ApplicationDelegate,
event_loop::{stop_app_on_panic, PanicInfo},
};
unsafe fn control_flow_handler<F>(panic_info: *mut c_void, f: F)
where
F: FnOnce(Weak<PanicInfo>) + UnwindSafe,
@ -56,7 +57,7 @@ extern "C" fn control_flow_begin_handler(
match activity {
kCFRunLoopAfterWaiting => {
//trace!("Triggered `CFRunLoopAfterWaiting`");
AppState::wakeup(panic_info);
ApplicationDelegate::get(MainThreadMarker::new().unwrap()).wakeup(panic_info);
//trace!("Completed `CFRunLoopAfterWaiting`");
}
_ => unreachable!(),
@ -78,7 +79,7 @@ extern "C" fn control_flow_end_handler(
match activity {
kCFRunLoopBeforeWaiting => {
//trace!("Triggered `CFRunLoopBeforeWaiting`");
AppState::cleared(panic_info);
ApplicationDelegate::get(MainThreadMarker::new().unwrap()).cleared(panic_info);
//trace!("Completed `CFRunLoopBeforeWaiting`");
}
kCFRunLoopExit => (), //unimplemented!(), // not expected to ever happen
@ -88,13 +89,17 @@ extern "C" fn control_flow_end_handler(
}
}
struct RunLoop(CFRunLoopRef);
pub struct RunLoop(CFRunLoopRef);
impl RunLoop {
unsafe fn get() -> Self {
pub unsafe fn get() -> Self {
RunLoop(unsafe { CFRunLoopGetMain() })
}
pub fn wakeup(&self) {
unsafe { CFRunLoopWakeUp(self.0) }
}
unsafe fn add_observer(
&self,
flags: CFOptionFlags,
@ -141,6 +146,7 @@ pub fn setup_control_flow_observers(panic_info: Weak<PanicInfo>) {
}
}
#[derive(Debug)]
pub struct EventLoopWaker {
timer: CFRunLoopTimerRef,