Propagate error from EventLoop creation

Inner panics could make it hard to trouble shoot the issues and for some
users ints not desirable.

The inner panics were left only when they are used to `assert!` during
development.
This commit is contained in:
Kirill Chibisov 2023-08-06 06:03:54 +04:00 committed by GitHub
parent 584aab4cd0
commit ed26dd58fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 344 additions and 291 deletions

View file

@ -19,11 +19,9 @@ use objc2::rc::Id;
use objc2::ClassType;
use raw_window_handle::{RawDisplayHandle, UiKitDisplayHandle};
use super::uikit::{UIApplication, UIApplicationMain, UIDevice, UIScreen};
use super::view::WinitUIWindow;
use super::{app_state, monitor, view, MonitorHandle};
use crate::{
dpi::LogicalSize,
error::EventLoopError,
event::Event,
event_loop::{
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
@ -31,6 +29,10 @@ use crate::{
platform::ios::Idiom,
};
use super::uikit::{UIApplication, UIApplicationMain, UIDevice, UIScreen};
use super::view::WinitUIWindow;
use super::{app_state, monitor, view, MonitorHandle};
#[derive(Debug)]
pub(crate) enum EventWrapper {
StaticEvent(Event<Never>),
@ -75,7 +77,9 @@ pub struct EventLoop<T: 'static> {
pub(crate) struct PlatformSpecificEventLoopAttributes {}
impl<T: 'static> EventLoop<T> {
pub(crate) fn new(_: &PlatformSpecificEventLoopAttributes) -> EventLoop<T> {
pub(crate) fn new(
_: &PlatformSpecificEventLoopAttributes,
) -> Result<EventLoop<T>, EventLoopError> {
assert_main_thread!("`EventLoop` can only be created on the main thread on iOS");
static mut SINGLETON_INIT: bool = false;
@ -93,7 +97,7 @@ impl<T: 'static> EventLoop<T> {
// this line sets up the main run loop before `UIApplicationMain`
setup_control_flow_observers();
EventLoop {
Ok(EventLoop {
window_target: RootEventLoopWindowTarget {
p: EventLoopWindowTarget {
receiver,
@ -101,7 +105,7 @@ impl<T: 'static> EventLoop<T> {
},
_marker: PhantomData,
},
}
})
}
pub fn run<F>(self, event_handler: F) -> !