#[cfg(feature = "http")]
pub(crate) mod launchd;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(feature = "http")]
pub(crate) mod systemd;
#[cfg(target_os = "windows")]
mod windows;
pub(crate) fn install_keychain() -> anyhow::Result<()> {
#[cfg(target_os = "macos")]
return macos::install_keychain();
#[cfg(target_os = "windows")]
return windows::install_keychain();
#[cfg(target_os = "linux")]
return linux::install_keychain();
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
anyhow::bail!("this operating system has no supported credential store")
}
pub(crate) fn open_url(url: &str) {
#[cfg(target_os = "macos")]
let spawned = std::process::Command::new("open").arg(url).spawn();
#[cfg(target_os = "windows")]
let spawned = std::process::Command::new("cmd")
.args(["/C", "start", "", url])
.spawn();
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
let spawned = std::process::Command::new("xdg-open").arg(url).spawn();
if let Err(error) = spawned {
tracing::debug!(%error, "could not open the browser");
}
}
#[cfg(feature = "http")]
pub(crate) async fn shutdown_signal() {
#[cfg(unix)]
{
use tokio::signal::unix::{SignalKind, signal};
if let Ok(mut terminate) = signal(SignalKind::terminate()) {
tokio::select! {
_ = tokio::signal::ctrl_c() => {}
_ = terminate.recv() => {}
}
return;
}
}
let _ = tokio::signal::ctrl_c().await;
}
#[cfg(feature = "http")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Service {
Launchd,
Systemd,
}
#[cfg(feature = "http")]
impl Service {
pub(crate) const fn current() -> Option<Self> {
if cfg!(target_os = "macos") {
Some(Self::Launchd)
} else if cfg!(target_os = "linux") {
Some(Self::Systemd)
} else {
None
}
}
}