feat: proper ctrl+c stop
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2088,6 +2088,7 @@ dependencies = [
|
||||
"glam 0.23.0",
|
||||
"global_counter",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"mint",
|
||||
"nanoid",
|
||||
"once_cell",
|
||||
|
||||
@@ -61,6 +61,7 @@ rand = "0.8.5"
|
||||
atty = "0.2.14"
|
||||
xkbcommon = { version = "0.6.0", default-features = false, optional = true }
|
||||
ctrlc = "3.4.1"
|
||||
libc = "0.2.148"
|
||||
|
||||
[dependencies.smithay]
|
||||
# git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
||||
|
||||
20
src/main.rs
20
src/main.rs
@@ -19,7 +19,9 @@ use self::core::eventloop::EventLoop;
|
||||
use clap::Parser;
|
||||
use directories::ProjectDirs;
|
||||
use once_cell::sync::OnceCell;
|
||||
use smithay::reexports::nix;
|
||||
use stardust_xr::server;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
@@ -88,7 +90,12 @@ fn setup_tracing() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
ctrlc::set_handler(|| STOP_NOTIFIER.notify_waiters()).unwrap();
|
||||
ctrlc::set_handler(|| {
|
||||
if atty::isnt(atty::Stream::Stdout) {
|
||||
STOP_NOTIFIER.notify_waiters()
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
setup_tracing();
|
||||
|
||||
@@ -210,7 +217,9 @@ fn main() {
|
||||
.clone()
|
||||
.and_then(|p| p.canonicalize().ok())
|
||||
.unwrap_or_else(|| project_dirs.config_dir().join("startup"));
|
||||
let mut startup_command = Command::new(startup_script_path);
|
||||
let mut startup_command = Command::new("bash");
|
||||
startup_command.arg(startup_script_path);
|
||||
startup_command.arg("&");
|
||||
|
||||
startup_command.stdin(Stdio::null());
|
||||
startup_command.stdout(Stdio::null());
|
||||
@@ -239,6 +248,13 @@ fn main() {
|
||||
startup_command.env("CLUTTER_BACKEND", "wayland");
|
||||
startup_command.env("SDL_VIDEODRIVER", "wayland");
|
||||
}
|
||||
unsafe {
|
||||
startup_command.pre_exec(|| {
|
||||
nix::unistd::setsid()
|
||||
.map(|_| ())
|
||||
.map_err(|_| std::io::ErrorKind::Other.into())
|
||||
})
|
||||
};
|
||||
let child = startup_command.spawn().ok()?;
|
||||
Some(child)
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user