-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a6aa24
commit a000119
Showing
7 changed files
with
132 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use futures::executor::LocalPool; | ||
use futures::task::LocalSpawnExt; | ||
use std::future::Future; | ||
use thiserror::Error; | ||
use winit::application::ApplicationHandler; | ||
use winit::error::EventLoopError; | ||
use winit::event::WindowEvent; | ||
use winit::event_loop::{ActiveEventLoop, EventLoop}; | ||
use winit::window::WindowId; | ||
|
||
pub fn block_on(main: impl Future<Output = ()> + 'static) -> Result<(), RuntimeError> { | ||
// Setup winit event loop. | ||
let mut el = EventLoop::<Event>::with_user_event(); | ||
let el = el.build().map_err(RuntimeError::CreateEventLoop)?; | ||
let exe = LocalPool::new(); | ||
|
||
exe.spawner() | ||
.spawn_local(async move { | ||
main.await; | ||
todo!() | ||
}) | ||
.unwrap(); | ||
|
||
// Run event loop. | ||
el.run_app(&mut AsyncExecutor(exe)) | ||
.map_err(RuntimeError::RunEventLoop) | ||
} | ||
|
||
/// Implementation of [`ApplicationHandler`] to drive [`Future`]. | ||
struct AsyncExecutor(LocalPool); | ||
|
||
impl ApplicationHandler<Event> for AsyncExecutor { | ||
fn resumed(&mut self, event_loop: &ActiveEventLoop) { | ||
self.0.run_until_stalled(); | ||
} | ||
|
||
fn window_event( | ||
&mut self, | ||
event_loop: &ActiveEventLoop, | ||
window_id: WindowId, | ||
event: WindowEvent, | ||
) { | ||
todo!() | ||
} | ||
} | ||
|
||
/// Event to wakeup winit event loop. | ||
enum Event {} | ||
|
||
/// Represents an error when [`block_on()`] fails. | ||
#[derive(Debug, Error)] | ||
pub enum RuntimeError { | ||
#[error("couldn't create event loop")] | ||
CreateEventLoop(#[source] EventLoopError), | ||
|
||
#[error("couldn't run event loop")] | ||
RunEventLoop(#[source] EventLoopError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
pub use self::backend::*; | ||
pub use self::profile::*; | ||
|
||
use slint::ComponentHandle; | ||
|
||
mod backend; | ||
mod profile; | ||
|
||
/// Provides methods for [`ComponentHandle`] to work with our async runtime. | ||
pub trait RuntimeExt: ComponentHandle { | ||
async fn exec(&self) -> Result<(), slint::PlatformError>; | ||
} | ||
|
||
impl<T: ComponentHandle> RuntimeExt for T { | ||
async fn exec(&self) -> Result<(), slint::PlatformError> { | ||
todo!() | ||
} | ||
} | ||
|
||
// This macro includes the generated Rust code from .slint files | ||
slint::include_modules!(); |