Skip to main content

ferrix_app/
lib.rs

1/* lib.rs
2 *
3 * Copyright 2025-2026 Michail Krasnov <mskrasnov07@ya.ru>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21pub mod export;
22pub mod i18n;
23pub mod icons;
24pub mod load_state;
25// pub mod modals;
26pub mod pages;
27pub mod styles;
28pub mod utils;
29pub mod widgets;
30
31pub mod dmi;
32pub mod kernel;
33
34// REFACTORED MODULES
35pub mod ferrix;
36pub mod messages;
37pub mod settings;
38pub mod sidebar;
39pub mod subscription;
40
41use messages::*;
42
43pub use load_state::DataLoadingState;
44pub use pages::*;
45
46use serde::Serialize;
47
48use anyhow::Result;
49use ferrix_lib::sys::{LoadAVG, Uptime, get_current_desktop, get_env_vars, get_hostname, get_lang};
50
51const SETTINGS_PATH: &str = "./ferrix.conf";
52
53#[derive(Debug, Clone, Serialize)]
54pub struct System {
55    pub hostname: Option<String>,
56    pub loadavg: Option<LoadAVG>,
57    pub uptime: Option<Uptime>,
58    pub desktop: Option<String>,
59    pub language: Option<String>,
60    pub env_vars: Vec<(String, String)>,
61}
62
63impl System {
64    pub fn new() -> Result<Self> {
65        Ok(Self {
66            hostname: get_hostname(),
67            loadavg: Some(LoadAVG::new()?),
68            uptime: Some(Uptime::new()?),
69            desktop: get_current_desktop(),
70            language: get_lang(),
71            env_vars: get_env_vars(),
72        })
73    }
74}
75
76impl Default for System {
77    fn default() -> Self {
78        Self {
79            hostname: Some("unknown-host".to_string()),
80            loadavg: None,
81            uptime: None,
82            desktop: Some("Unknown DE".to_string()),
83            language: Some("Unknown locale".to_string()),
84            env_vars: Vec::new(),
85        }
86    }
87}