mirror of
https://github.com/house-of-vanity/khm.git
synced 2025-08-21 22:27:14 +00:00
Works with egui
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use dirs::home_dir;
|
||||
use eframe::egui;
|
||||
use log::{debug, error, info};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
@@ -21,8 +22,8 @@ impl Default for KhmSettings {
|
||||
flow: String::new(),
|
||||
known_hosts: "~/.ssh/known_hosts".to_string(),
|
||||
basic_auth: String::new(),
|
||||
in_place: false,
|
||||
auto_sync_interval_minutes: 60, // Default to 1 hour
|
||||
in_place: true,
|
||||
auto_sync_interval_minutes: 60,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,17 +58,6 @@ pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos::run_settings_window;
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
mod cross;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub use cross::run_settings_window;
|
||||
|
||||
// Helper function to expand tilde in path
|
||||
pub fn expand_path(path: &str) -> String {
|
||||
if path.starts_with("~/") {
|
||||
if let Some(home) = home_dir() {
|
||||
@@ -76,3 +66,86 @@ pub fn expand_path(path: &str) -> String {
|
||||
}
|
||||
path.to_string()
|
||||
}
|
||||
|
||||
struct KhmSettingsWindow {
|
||||
settings: KhmSettings,
|
||||
auto_sync_interval_str: String,
|
||||
}
|
||||
|
||||
impl eframe::App for KhmSettingsWindow {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("KHM Settings");
|
||||
ui.separator();
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Host URL:");
|
||||
ui.text_edit_singleline(&mut self.settings.host);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Flow Name:");
|
||||
ui.text_edit_singleline(&mut self.settings.flow);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Known Hosts:");
|
||||
ui.text_edit_singleline(&mut self.settings.known_hosts);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Basic Auth:");
|
||||
ui.text_edit_singleline(&mut self.settings.basic_auth);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Auto sync interval (min):");
|
||||
ui.text_edit_singleline(&mut self.auto_sync_interval_str);
|
||||
// Parse the string and update settings
|
||||
if let Ok(value) = self.auto_sync_interval_str.parse::<u32>() {
|
||||
self.settings.auto_sync_interval_minutes = value;
|
||||
}
|
||||
});
|
||||
|
||||
ui.checkbox(&mut self.settings.in_place, "Update known_hosts file in-place after sync");
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Save").clicked() {
|
||||
if let Err(e) = save_settings(&self.settings) {
|
||||
error!("Failed to save KHM settings: {}", e);
|
||||
} else {
|
||||
info!("KHM settings saved successfully");
|
||||
}
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
|
||||
if ui.button("Cancel").clicked() {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_settings_window() {
|
||||
let settings = load_settings();
|
||||
let auto_sync_interval_str = settings.auto_sync_interval_minutes.to_string();
|
||||
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_title("KHM Settings")
|
||||
.with_inner_size([450.0, 385.0]),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let _ = eframe::run_native(
|
||||
"KHM Settings",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::new(KhmSettingsWindow {
|
||||
settings,
|
||||
auto_sync_interval_str,
|
||||
}))),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user