Support --no-daemon flag to prevent daemonizing

This commit is contained in:
Jeremy Soller 2024-11-14 09:28:13 -07:00
parent 738e6eeb7b
commit 8885d295bb
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -82,25 +82,19 @@ pub fn desktop() -> Result<(), Box<dyn std::error::Error>> {
/// Runs application with these settings
#[rustfmt::skip]
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(all(unix, not(target_os = "redox")))]
match fork::daemon(true, true) {
Ok(fork::Fork::Child) => (),
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
Err(err) => {
eprintln!("failed to daemonize: {:?}", err);
process::exit(1);
}
}
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
localize::localize();
let (config_handler, config) = Config::load();
let mut daemonize = true;
let mut locations = Vec::new();
for arg in env::args().skip(1) {
let location = if &arg == "--trash" {
let location = if &arg == "--no-daemon" {
daemonize = false;
continue;
} else if &arg == "--trash" {
Location::Trash
} else {
match fs::canonicalize(&arg) {
@ -114,6 +108,18 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
locations.push(location);
}
if daemonize {
#[cfg(all(unix, not(target_os = "redox")))]
match fork::daemon(true, true) {
Ok(fork::Fork::Child) => (),
Ok(fork::Fork::Parent(_child_pid)) => process::exit(0),
Err(err) => {
eprintln!("failed to daemonize: {:?}", err);
process::exit(1);
}
}
}
let mut settings = Settings::default();
settings = settings.theme(config.app_theme.theme());
settings = settings.size_limits(Limits::NONE.min_width(360.0).min_height(180.0));