diff options
author | 2021-11-07 14:32:18 +0100 | |
---|---|---|
committer | 2021-11-29 14:41:05 +0700 | |
commit | 08c771fa703f93faf57207a6793cf70cf105de5a (patch) | |
tree | 8d3b146046229c9d7675f329de95ebcc0dc9c8cc | |
parent | aeec0375f0897b2ef0897c4c54476b2d0db9311a (diff) | |
download | iced-08c771fa703f93faf57207a6793cf70cf105de5a.tar.gz iced-08c771fa703f93faf57207a6793cf70cf105de5a.tar.bz2 iced-08c771fa703f93faf57207a6793cf70cf105de5a.zip |
Allow `Application::run` to return on native platforms
-rw-r--r-- | glutin/src/application.rs | 7 | ||||
-rw-r--r-- | src/application.rs | 4 | ||||
-rw-r--r-- | winit/src/application.rs | 9 |
3 files changed, 13 insertions, 7 deletions
diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 5d10e96a..3a96cae9 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -11,6 +11,7 @@ use iced_winit::futures; use iced_winit::futures::channel::mpsc; use iced_winit::{Cache, Clipboard, Debug, Proxy, Settings}; +use crate::glutin::platform::run_return::EventLoopExtRunReturn; use glutin::window::Window; use std::mem::ManuallyDrop; @@ -33,7 +34,7 @@ where let mut debug = Debug::new(); debug.startup_started(); - let event_loop = EventLoop::with_user_event(); + let mut event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); let mut runtime = { @@ -115,7 +116,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run(move |event, _, control_flow| { + event_loop.run_return(move |event, _, control_flow| { use glutin::event_loop::ControlFlow; if let ControlFlow::Exit = control_flow { @@ -148,6 +149,8 @@ where }; } }); + + Ok(()) } async fn run_instance<A, E, C>( diff --git a/src/application.rs b/src/application.rs index af04215e..5728dc0b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -188,9 +188,9 @@ pub trait Application: Sized { /// Runs the [`Application`]. /// /// On native platforms, this method will take control of the current thread - /// and __will NOT return__ unless there is an [`Error`] during startup. + /// until the event loop of the main window exits. /// - /// It should probably be that last thing you call in your `main` function. + /// Does never return on the web platform /// /// [`Error`]: crate::Error fn run(settings: Settings<Self::Flags>) -> crate::Result diff --git a/winit/src/application.rs b/winit/src/application.rs index 9ae1364d..e52283d7 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -17,6 +17,7 @@ use iced_graphics::window; use iced_native::program::Program; use iced_native::{Cache, UserInterface}; +use crate::winit::platform::run_return::EventLoopExtRunReturn; use std::mem::ManuallyDrop; /// An interactive, native cross-platform application. @@ -119,7 +120,7 @@ where let mut debug = Debug::new(); debug.startup_started(); - let event_loop = EventLoop::with_user_event(); + let mut event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); let mut runtime = { @@ -178,7 +179,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run(move |event, _, control_flow| { + event_loop.run_return(move |event, _, control_flow| { use winit::event_loop::ControlFlow; if let ControlFlow::Exit = control_flow { @@ -211,6 +212,8 @@ where }; } }); + + Ok(()) } async fn run_instance<A, E, C>( @@ -401,7 +404,7 @@ async fn run_instance<A, E, C>( Err(error) => match error { // This is an unrecoverable error. window::SurfaceError::OutOfMemory => { - panic!("{}", error); + panic!("{:?}", error); } _ => { debug.render_finished(); |