fetchium_core/setup/
checker.rs1use crate::config::FetchiumConfig;
4
5#[derive(Debug)]
7pub struct CheckItem {
8 pub name: &'static str,
9 pub status: CheckStatus,
10 pub detail: String,
11}
12
13#[derive(Debug, PartialEq, Eq)]
15pub enum CheckStatus {
16 Ok,
18 Warning,
20 Missing,
22}
23
24impl CheckStatus {
25 pub fn icon(&self) -> &'static str {
27 match self {
28 Self::Ok => "✓",
29 Self::Warning => "⚠",
30 Self::Missing => "✗",
31 }
32 }
33}
34
35pub fn run_checks(config: &FetchiumConfig) -> Vec<CheckItem> {
37 let mut items = Vec::new();
38
39 let chrome = super::chromium::resolve_chrome_path(config);
41 items.push(CheckItem {
42 name: "Chrome/Chromium",
43 status: if chrome.is_some() {
44 CheckStatus::Ok
45 } else {
46 CheckStatus::Missing
47 },
48 detail: chrome
49 .as_ref()
50 .map(|p| p.display().to_string())
51 .unwrap_or_else(|| "Not found — run: fetchium setup --headless".into()),
52 });
53
54 if let Some(ref p) = chrome {
56 let managed = config.data_dir().join("chromium");
57 let source = if p.starts_with(&managed) {
58 "(fetchium-managed)"
59 } else if p.to_string_lossy().contains("snap") {
60 "(snap)"
61 } else {
62 "(system)"
63 };
64 items.push(CheckItem {
65 name: " Chrome source",
66 status: CheckStatus::Ok,
67 detail: source.into(),
68 });
69 }
70
71 match &config.search.searxng_url {
73 Some(url) => {
74 items.push(CheckItem {
75 name: "SearXNG",
76 status: CheckStatus::Ok,
77 detail: format!("configured at {url}"),
78 });
79 }
80 None => {
81 items.push(CheckItem {
82 name: "SearXNG",
83 status: CheckStatus::Warning,
84 detail: "not configured (set search.searxng_url in config)".into(),
85 });
86 }
87 }
88
89 let data_dir = config.data_dir();
91 let dir_ok = data_dir.exists() || std::fs::create_dir_all(&data_dir).is_ok();
92 items.push(CheckItem {
93 name: "Data directory",
94 status: if dir_ok {
95 CheckStatus::Ok
96 } else {
97 CheckStatus::Missing
98 },
99 detail: data_dir.display().to_string(),
100 });
101
102 let config_path = FetchiumConfig::config_file_path();
104 items.push(CheckItem {
105 name: "Config file",
106 status: CheckStatus::Ok,
107 detail: if config_path.exists() {
108 config_path.display().to_string()
109 } else {
110 format!("{} (using defaults)", config_path.display())
111 },
112 });
113
114 items
115}