#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
use anyhow::Result;
use std::fmt;
pub enum DaemonStatus {
Installed,
NotInstalled,
Unknown(String),
}
impl fmt::Display for DaemonStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DaemonStatus::Installed => write!(f, "Installed"),
DaemonStatus::NotInstalled => write!(f, "Not Installed"),
DaemonStatus::Unknown(msg) => write!(f, "Unknown: {}", msg),
}
}
}
pub fn install_daemon(interval_days: u64) -> Result<()> {
let interval_days = interval_days.max(1);
#[cfg(target_os = "windows")]
{
windows::install(interval_days)
}
#[cfg(target_os = "macos")]
{
macos::install(interval_days)
}
#[cfg(target_os = "linux")]
{
linux::install(interval_days)
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
anyhow::bail!("Unsupported operating system for daemon installation");
}
}
pub fn uninstall_daemon() -> Result<()> {
#[cfg(target_os = "windows")]
{
windows::uninstall()
}
#[cfg(target_os = "macos")]
{
macos::uninstall()
}
#[cfg(target_os = "linux")]
{
linux::uninstall()
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
anyhow::bail!("Unsupported operating system for daemon uninstallation");
}
}
pub fn daemon_status() -> Result<DaemonStatus> {
#[cfg(target_os = "windows")]
{
windows::status()
}
#[cfg(target_os = "macos")]
{
macos::status()
}
#[cfg(target_os = "linux")]
{
linux::status()
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
anyhow::bail!("Unsupported operating system for daemon status");
}
}
pub fn get_exe_path() -> std::path::PathBuf {
crate::setup::stable_exe_path()
}
pub fn wants_hidden_upgrade() -> bool {
#[cfg(target_os = "windows")]
{
windows::wants_hidden_upgrade()
}
#[cfg(not(target_os = "windows"))]
{
false
}
}
pub fn refresh_hidden_twin() {
#[cfg(target_os = "windows")]
{
windows::refresh_hidden_twin();
}
}
pub fn registered_exe_path() -> Option<std::path::PathBuf> {
#[cfg(target_os = "windows")]
{
windows::registered_exe_path()
}
#[cfg(target_os = "macos")]
{
macos::registered_exe_path()
}
#[cfg(target_os = "linux")]
{
linux::registered_exe_path()
}
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
None
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_daemon_status_display() {
assert_eq!(DaemonStatus::Installed.to_string(), "Installed");
assert_eq!(DaemonStatus::NotInstalled.to_string(), "Not Installed");
assert_eq!(
DaemonStatus::Unknown("error".into()).to_string(),
"Unknown: error"
);
}
}