#[cfg(target_os = "windows")]
pub mod detection;
#[cfg(target_os = "windows")]
pub mod installer;
#[cfg(target_os = "windows")]
pub mod ui;
#[cfg(not(target_os = "windows"))]
pub mod ui {
#[derive(Debug, Clone, PartialEq)]
#[allow(dead_code)]
pub enum SetupResult {
Installed,
RunWithout,
Cancelled,
}
}
pub fn maybe_show_setup_wizard() -> anyhow::Result<bool> {
#[cfg(target_os = "windows")]
{
if detection::is_installed() {
return start_installed_service();
}
let result = ui::show_setup_dialog()?;
match result {
ui::SetupResult::Installed => Ok(true),
ui::SetupResult::RunWithout => Ok(false), ui::SetupResult::Cancelled => Ok(true),
}
}
#[cfg(not(target_os = "windows"))]
{
Ok(false)
}
}
#[cfg(target_os = "windows")]
fn start_installed_service() -> anyhow::Result<bool> {
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
let exe = std::env::current_exe()?;
let status = std::process::Command::new(&exe)
.args(["service", "start"])
.creation_flags(CREATE_NO_WINDOW)
.status();
match status {
Ok(s) if s.success() => Ok(true), Ok(_) => {
eprintln!("Warning: could not start Freenet service, falling back to console mode");
Ok(false)
}
Err(e) => {
eprintln!(
"Warning: could not start Freenet service ({e}), falling back to console mode"
);
Ok(false)
}
}
}