Skip to content

Commit

Permalink
Fixes for dependency upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeicor committed Aug 26, 2023
1 parent 6f4e3dd commit 9ffbb2c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 43 deletions.
29 changes: 2 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,9 @@ fn android_main(app: android_activity::AndroidApp) {
println!("Starting android_main");

use winit::platform::android::EventLoopBuilderExtAndroid;
let _ign = run::native_main(true, Box::new(|b| {
let _ign = run::native_main(true, Some(Box::new(|b| {
b.with_android_app(app);
}));
})));

println!("Exiting android_main")

// use android_activity::{InputStatus, MainEvent, PollEvent};
// loop {
// app.poll_events(Some(std::time::Duration::from_millis(500)) /* timeout */, |event| {
// match event {
// PollEvent::Wake => {
// log::info!("Early wake up");
// }
// PollEvent::Timeout => { log::info!("Hello, World!"); }
// PollEvent::Main(main_event) => {
// log::info!("Main event: {:?}", main_event);
// match main_event {
// MainEvent::Destroy => { return; }
// _ => {}
// }
// }
// _ => {}
// }
//
// app.input_events(|event| {
// log::info!("Input Event: {event:?}");
// InputStatus::Unhandled
// });
// });
// }
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ mod cli;
#[cfg(not(any(target_arch = "wasm32")))]
#[tokio::main(flavor = "multi_thread")]
async fn main() {
run::native_main(false, Box::new(|_b| ())).await;
run::native_main(false, None).await;
}
43 changes: 30 additions & 13 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type AppCreator = Option<eframe::AppCreator>;
#[cfg(not(feature = "app"))]
type AppCreator = Option<()>;

#[cfg(feature = "app")]
type EventLoopBuilderHook = Option<eframe::EventLoopBuilderHook>;
#[cfg(not(feature = "app"))]
type EventLoopBuilderHook = Option<()>;

/// All entry-points redirect here after platform-specific initialization and
/// before platform-specific window start (which may be cancelled if None is returned).
pub async fn setup_app() -> AppCreator {
Expand Down Expand Up @@ -63,22 +68,34 @@ pub fn setup_app_sync() -> AppCreator {
}))
}
#[cfg(feature = "server")]
Commands::Server(_srv) => {
tracing::error!("Server is not supported in sync mode");
None
Commands::Server(srv) => {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
srv.run().await;
None
})
},
#[cfg(feature = "meshers")]
Commands::Mesh(_mesher) => {
tracing::error!("Meshing is not supported in sync mode");
None
Commands::Mesh(mesher) => {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
mesher.run_cli().await.unwrap();
None
})
}
}
}

// === Native entry-points redirect here ===
#[cfg(not(any(target_arch = "wasm32")))]
#[allow(dead_code)] // False positive
pub fn native_main(sync: bool, event_loop_builder: eframe::EventLoopBuilderHook) -> Pin<Box<dyn Future<Output=()>>> {
pub fn native_main(sync: bool, event_loop_builder: EventLoopBuilderHook) -> Pin<Box<dyn Future<Output=()>>> {
// Setup logging
tracing::subscriber::set_global_default(tracing_subscriber::FmtSubscriber::default())
.expect("Failed to set global default subscriber");
Expand All @@ -90,29 +107,29 @@ pub fn native_main(sync: bool, event_loop_builder: eframe::EventLoopBuilderHook)
});
}
// Run app
let app_creator_handler = |app_creator: eframe::AppCreator| {
let app_creator_handler = |app_creator: AppCreator| {
#[cfg(feature = "app")]
{
let native_options = eframe::NativeOptions {
depth_buffer: 16, // Needed for 3D rendering
event_loop_builder: Some(event_loop_builder),
event_loop_builder,
..eframe::NativeOptions::default()
};
println!("Starting native app");
eframe::run_native("SDF Viewer", native_options, app_creator).unwrap();
eframe::run_native("SDF Viewer", native_options, app_creator.unwrap()).unwrap();
println!("Native app exited");
}
};
if sync {
if let Some(app_creator) = setup_app_sync() {
app_creator_handler(app_creator);
app_creator_handler(Some(app_creator));
}
Box::pin(future::ready(()))
} else {
use futures_util::FutureExt;
Box::pin(setup_app().map(|t| {
Box::pin(setup_app().map(move |t| {
if let Some(app_creator) = t {
app_creator_handler(app_creator);
app_creator_handler(Some(app_creator));
}
}))
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ impl CliServer {

// Select recommended watcher for debouncer.
// Using a callback here, could also be a channel.
let mut debouncer = new_debouncer(self.watch_merge_ns, None, move |res: DebounceEventResult| {
let mut debouncer = new_debouncer(self.watch_merge_ns, move |res: DebounceEventResult| {
match res {
Ok(events) => {
events.iter().for_each(|e| println!("Event {:?} for {:?}", e.kind, e.path));
if !events.is_empty() {
tx.send(events).unwrap();
}
}
Err(errors) => errors.iter().for_each(|e| tracing::error!("Error {:?}",e)),
Err(e) => tracing::error!("Error {:?}", e),
}
})?;

Expand Down

0 comments on commit 9ffbb2c

Please sign in to comment.