Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ directories = "6.0"
oo7 = "0.6"
chrono = "0.4"
cairo-rs = { version = "0.22", features = ["use_glib"] }
serde_json = "1.0.149"

[profile.release]
opt-level = 3
Expand Down
43 changes: 43 additions & 0 deletions src/config_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,49 @@ pub fn expand_tilde(path: &str) -> PathBuf {
PathBuf::from(path)
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct AppConfig {
pub monitor_refresh_rate: u32, // index: 0=1s, 1=3s, 2=5s, 3=10s
pub terminal_font: String,
pub terminal_scrollback: u32,
pub confirm_tab_close: bool,
}

impl Default for AppConfig {
fn default() -> Self {
Self {
monitor_refresh_rate: 1, // 3s
terminal_font: "Monospace 11".to_string(),
terminal_scrollback: 10000,
confirm_tab_close: false,
}
}
}

pub fn get_app_config_path() -> Option<PathBuf> {
directories::ProjectDirs::from("org", "rustmius", "Rustmius")
.map(|dirs| dirs.config_dir().join("config.json"))
}

pub fn load_app_config() -> AppConfig {
if let Some(path) = get_app_config_path()
&& path.exists()
&& let Ok(content) = fs::read_to_string(path) {
return serde_json::from_str(&content).unwrap_or_default();
}
AppConfig::default()
}

pub fn save_app_config(config: &AppConfig) -> anyhow::Result<()> {
let path = get_app_config_path().ok_or_else(|| anyhow::anyhow!("Could not find app config path"))?;
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
let content = serde_json::to_string_pretty(config)?;
fs::write(path, content)?;
Ok(())
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SshHost {
pub alias: String,
Expand Down
5 changes: 4 additions & 1 deletion src/ui/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ impl SystemMonitor {
let toolbar = gtk4::Box::new(gtk4::Orientation::Horizontal, 12);
let refresh_label = gtk4::Label::new(Some("Refresh Rate:"));
let refresh_dropdown = gtk4::DropDown::from_strings(&["1s", "3s", "5s", "10s"]);
refresh_dropdown.set_selected(1);

let app_config = crate::config_observer::load_app_config();
refresh_dropdown.set_selected(app_config.monitor_refresh_rate);

toolbar.append(&refresh_label);
toolbar.append(&refresh_dropdown);
toolbar.set_halign(gtk4::Align::End);
Expand Down
Loading