feat: add daemonize to fork off

This commit is contained in:
Moritz Böhme 2023-07-29 17:19:36 +02:00
parent b53689584a
commit 0727b3e053
Signed by: moritz
GPG key ID: 970C6E89EB0547A9
3 changed files with 16 additions and 2 deletions

10
Cargo.lock generated
View file

@ -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",

View file

@ -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"] }

View file

@ -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())
}