fix: ctrl+c in tty
This commit is contained in:
21
Cargo.lock
generated
21
Cargo.lock
generated
@@ -149,6 +149,17 @@ dependencies = [
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@@ -899,6 +910,15 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
@@ -2007,6 +2027,7 @@ dependencies = [
|
||||
name = "stardust-xr-server"
|
||||
version = "0.42.0"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"console-subscriber",
|
||||
|
||||
@@ -58,6 +58,7 @@ tracing = "0.1.37"
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||
global_counter = "0.2.2"
|
||||
rand = "0.8.5"
|
||||
atty = "0.2.14"
|
||||
|
||||
[dependencies.stereokit]
|
||||
default-features = false
|
||||
|
||||
19
src/main.rs
19
src/main.rs
@@ -18,7 +18,7 @@ use directories::ProjectDirs;
|
||||
use once_cell::sync::OnceCell;
|
||||
use stardust_xr::server;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use stereokit::{
|
||||
@@ -178,6 +178,7 @@ fn main() -> Result<()> {
|
||||
.and_then(|p| p.canonicalize().ok())
|
||||
.unwrap_or_else(|| project_dirs.config_dir().join("startup"));
|
||||
let _startup = Command::new(startup_script_path)
|
||||
.stdin(Stdio::null())
|
||||
.env(
|
||||
"FLAT_WAYLAND_DISPLAY",
|
||||
std::env::var_os("WAYLAND_DISPLAY").unwrap_or_default(),
|
||||
@@ -301,11 +302,15 @@ async fn event_loop(
|
||||
socket_path,
|
||||
});
|
||||
|
||||
let result = tokio::select! {
|
||||
biased;
|
||||
_ = tokio::signal::ctrl_c() => Ok(()),
|
||||
_ = stop_rx => Ok(()),
|
||||
};
|
||||
if atty::is(atty::Stream::Stdin) {
|
||||
stop_rx.await?;
|
||||
} else {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = tokio::signal::ctrl_c() => (),
|
||||
_ = stop_rx => (),
|
||||
};
|
||||
}
|
||||
|
||||
info!("Cleanly shut down event loop");
|
||||
|
||||
@@ -313,5 +318,5 @@ async fn event_loop(
|
||||
stereokit::sys::sk_quit();
|
||||
}
|
||||
|
||||
result
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user