1mod linux;
13mod macos;
14mod windows;
15
16use anyhow::Result;
17use std::fmt;
18
19pub enum DaemonStatus {
21 Installed,
22 NotInstalled,
23 Unknown(String),
24}
25
26impl fmt::Display for DaemonStatus {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 DaemonStatus::Installed => write!(f, "Installed"),
30 DaemonStatus::NotInstalled => write!(f, "Not Installed"),
31 DaemonStatus::Unknown(msg) => write!(f, "Unknown: {}", msg),
32 }
33 }
34}
35
36pub fn install_daemon(interval_days: u64) -> Result<()> {
43 let interval_days = interval_days.max(1);
44 #[cfg(target_os = "windows")]
45 {
46 windows::install(interval_days)
47 }
48 #[cfg(target_os = "macos")]
49 {
50 macos::install(interval_days)
51 }
52 #[cfg(target_os = "linux")]
53 {
54 linux::install(interval_days)
55 }
56 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
57 {
58 anyhow::bail!("Unsupported operating system for daemon installation");
59 }
60}
61
62pub fn uninstall_daemon() -> Result<()> {
64 #[cfg(target_os = "windows")]
65 {
66 windows::uninstall()
67 }
68 #[cfg(target_os = "macos")]
69 {
70 macos::uninstall()
71 }
72 #[cfg(target_os = "linux")]
73 {
74 linux::uninstall()
75 }
76 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
77 {
78 anyhow::bail!("Unsupported operating system for daemon uninstallation");
79 }
80}
81
82pub fn daemon_status() -> Result<DaemonStatus> {
84 #[cfg(target_os = "windows")]
85 {
86 windows::status()
87 }
88 #[cfg(target_os = "macos")]
89 {
90 macos::status()
91 }
92 #[cfg(target_os = "linux")]
93 {
94 linux::status()
95 }
96 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
97 {
98 anyhow::bail!("Unsupported operating system for daemon status");
99 }
100}
101
102pub fn get_exe_path() -> std::path::PathBuf {
108 crate::setup::stable_exe_path()
109}
110
111pub fn registered_exe_path() -> Option<std::path::PathBuf> {
119 #[cfg(target_os = "windows")]
120 {
121 windows::registered_exe_path()
122 }
123 #[cfg(target_os = "macos")]
124 {
125 macos::registered_exe_path()
126 }
127 #[cfg(target_os = "linux")]
128 {
129 linux::registered_exe_path()
130 }
131 #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
132 {
133 None
134 }
135}
136
137#[cfg(test)]
138mod tests {
139 use super::*;
140
141 #[test]
142 fn test_daemon_status_display() {
143 assert_eq!(DaemonStatus::Installed.to_string(), "Installed");
144 assert_eq!(DaemonStatus::NotInstalled.to_string(), "Not Installed");
145 assert_eq!(
146 DaemonStatus::Unknown("error".into()).to_string(),
147 "Unknown: error"
148 );
149 }
150}