refactor: use bevy for handling ctrl-c
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -14,7 +14,7 @@ use crate::nodes::{audio, drawable, input};
|
|||||||
|
|
||||||
use bevy::a11y::AccessibilityPlugin;
|
use bevy::a11y::AccessibilityPlugin;
|
||||||
use bevy::app::{
|
use bevy::app::{
|
||||||
App, PluginGroup, PluginsState, PostUpdate, ScheduleRunnerPlugin, Startup,
|
App, AppExit, PluginGroup, PluginsState, PostUpdate, ScheduleRunnerPlugin, Startup,
|
||||||
TerminalCtrlCHandlerPlugin, Update,
|
TerminalCtrlCHandlerPlugin, Update,
|
||||||
};
|
};
|
||||||
use bevy::asset::{AssetPlugin, AssetServer, Handle};
|
use bevy::asset::{AssetPlugin, AssetServer, Handle};
|
||||||
@@ -53,6 +53,7 @@ use bevy_mod_xr::session::{XrFirst, XrPreDestroySession, XrSessionCreated, XrSes
|
|||||||
use bevy_mod_xr::spaces::XrPrimaryReferenceSpace;
|
use bevy_mod_xr::spaces::XrPrimaryReferenceSpace;
|
||||||
use bevy_plugin::{DbusConnection, InputUpdate, StardustBevyPlugin, StardustFirst};
|
use bevy_plugin::{DbusConnection, InputUpdate, StardustBevyPlugin, StardustFirst};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use color_eyre::eyre::eyre;
|
||||||
use core::client::Client;
|
use core::client::Client;
|
||||||
use core::task;
|
use core::task;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
@@ -126,16 +127,15 @@ impl Deref for RuntimeWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> color_eyre::Result<AppExit> {
|
||||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()?;
|
||||||
.unwrap();
|
|
||||||
TOKIO.0.set(runtime).unwrap();
|
TOKIO.0.set(runtime).unwrap();
|
||||||
TOKIO.block_on(setup())
|
TOKIO.block_on(setup())
|
||||||
}
|
}
|
||||||
async fn setup() {
|
async fn setup() -> color_eyre::Result<AppExit> {
|
||||||
color_eyre::install().unwrap();
|
color_eyre::install()?;
|
||||||
|
|
||||||
let registry = tracing_subscriber::registry();
|
let registry = tracing_subscriber::registry();
|
||||||
|
|
||||||
@@ -227,10 +227,7 @@ async fn setup() {
|
|||||||
.map(|project_dirs| launch_start(&cli_args, project_dirs))
|
.map(|project_dirs| launch_start(&cli_args, project_dirs))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
tokio::select! {
|
let exit = stereokit_loop.await?;
|
||||||
_ = stereokit_loop => (),
|
|
||||||
_ = tokio::signal::ctrl_c() => {},
|
|
||||||
}
|
|
||||||
info!("Stopping...");
|
info!("Stopping...");
|
||||||
if let Some(project_dirs) = project_dirs {
|
if let Some(project_dirs) = project_dirs {
|
||||||
save_session(&project_dirs).await;
|
save_session(&project_dirs).await;
|
||||||
@@ -240,6 +237,7 @@ async fn setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info!("Cleanly shut down Stardust");
|
info!("Cleanly shut down Stardust");
|
||||||
|
Ok(exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bevy_loop(
|
fn bevy_loop(
|
||||||
@@ -249,7 +247,7 @@ fn bevy_loop(
|
|||||||
dbus_connection: Connection,
|
dbus_connection: Connection,
|
||||||
object_registry: ObjectRegistry,
|
object_registry: ObjectRegistry,
|
||||||
headless: bool,
|
headless: bool,
|
||||||
) {
|
) -> AppExit {
|
||||||
let mut bevy_app = App::new();
|
let mut bevy_app = App::new();
|
||||||
// let base = (DefaultPlugins)
|
// let base = (DefaultPlugins)
|
||||||
// .build()
|
// .build()
|
||||||
@@ -504,8 +502,9 @@ fn bevy_loop(
|
|||||||
wayland.update();
|
wayland.update();
|
||||||
};
|
};
|
||||||
bevy_app.add_systems(StardustFirst, bevy_step);
|
bevy_app.add_systems(StardustFirst, bevy_step);
|
||||||
bevy_app.run();
|
let out = bevy_app.run();
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
drop(wayland);
|
drop(wayland);
|
||||||
|
out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user