Extract a platform::Lifecycle trait

This will allow us to make platform::Platform be Send + Sync and keep the lifecycle on the main thread.
This commit is contained in:
Nathan Sobo
2021-06-07 17:02:24 -06:00
parent 748c101076
commit 14b519f78d
5 changed files with 161 additions and 129 deletions
+24 -16
View File
@@ -8,6 +8,8 @@ use std::{
sync::Arc,
};
pub(crate) struct Lifecycle;
pub(crate) struct Platform {
dispatcher: Arc<dyn super::Dispatcher>,
fonts: Arc<dyn super::FontSystem>,
@@ -27,6 +29,24 @@ pub struct Window {
pub(crate) last_prompt: RefCell<Option<Box<dyn FnOnce(usize)>>>,
}
impl super::Lifecycle for Lifecycle {
fn on_menu_command(&self, _: Box<dyn FnMut(&str, Option<&dyn Any>)>) {}
fn on_become_active(&self, _: Box<dyn FnMut()>) {}
fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
fn on_event(&self, _: Box<dyn FnMut(crate::Event) -> bool>) {}
fn on_open_files(&self, _: Box<dyn FnMut(Vec<std::path::PathBuf>)>) {}
fn set_menus(&self, _: Vec<crate::Menu>) {}
fn run(&self, _on_finish_launching: Box<dyn FnOnce() -> ()>) {
unimplemented!()
}
}
impl Platform {
fn new() -> Self {
Self {
@@ -54,20 +74,6 @@ impl Platform {
}
impl super::Platform for Platform {
fn on_menu_command(&self, _: Box<dyn FnMut(&str, Option<&dyn Any>)>) {}
fn on_become_active(&self, _: Box<dyn FnMut()>) {}
fn on_resign_active(&self, _: Box<dyn FnMut()>) {}
fn on_event(&self, _: Box<dyn FnMut(crate::Event) -> bool>) {}
fn on_open_files(&self, _: Box<dyn FnMut(Vec<std::path::PathBuf>)>) {}
fn run(&self, _on_finish_launching: Box<dyn FnOnce() -> ()>) {
unimplemented!()
}
fn dispatcher(&self) -> Arc<dyn super::Dispatcher> {
self.dispatcher.clone()
}
@@ -91,8 +97,6 @@ impl super::Platform for Platform {
None
}
fn set_menus(&self, _menus: Vec<crate::Menu>) {}
fn quit(&self) {}
fn prompt_for_paths(
@@ -175,6 +179,10 @@ impl super::Window for Window {
}
}
pub(crate) fn lifecycle() -> Lifecycle {
Lifecycle
}
pub(crate) fn platform() -> Platform {
Platform::new()
}