From 0727b3e0531fae6c4501ebe4930b98bd54949c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 29 Jul 2023 17:19:36 +0200 Subject: [PATCH] feat: add daemonize to fork off --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 7 +++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90edaa7..f817b60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,6 +345,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "daemonize" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8bfdaacb3c887a54d41bdf48d3af8873b3f5566469f8ba21b92057509f116e" +dependencies = [ + "libc", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1123,6 +1132,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "daemonize", "humantime", "notify-rust", "serde", diff --git a/Cargo.toml b/Cargo.toml index 66307d1..6626413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] anyhow = "1.0.71" clap = { version = "4.3.4", features = ["derive"] } +daemonize = "0.5.0" humantime = "2.1.0" notify-rust = "4.8.0" serde = { version = "1.0.164", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index b7cb0ac..3143354 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ mod cli; mod daemon; +mod notification; mod pomodoro; mod timer; -mod notification; use crate::cli::{send_command, Cli, Command as CliCommand}; use crate::daemon::{Command as DaemonCommand, Daemon}; @@ -12,7 +12,10 @@ use cli::PomodoroCommand; fn main() -> Result<(), anyhow::Error> { let args = Cli::parse(); let daemon_command = match args.command { - CliCommand::Daemon { no_notify } => return Daemon::new(args.socket, no_notify)?.run(), + CliCommand::Daemon { no_notify } => { + daemonize::Daemonize::new().start()?; + return Daemon::new(args.socket, no_notify)?.run(); + } CliCommand::Add { name, duration } => { DaemonCommand::Add(name.into_boxed_str(), duration.into()) }