mirror of
https://github.com/house-of-vanity/khm.git
synced 2025-08-21 14:27:14 +00:00
UI code reworked
This commit is contained in:
17
Cargo.toml
17
Cargo.toml
@@ -27,13 +27,18 @@ trust-dns-resolver = "0.23"
|
||||
futures = "0.3"
|
||||
hostname = "0.3"
|
||||
rust-embed = "8.0"
|
||||
tray-icon = "0.19"
|
||||
notify = "6.1"
|
||||
notify-debouncer-mini = "0.4"
|
||||
tray-icon = { version = "0.19", optional = true }
|
||||
notify = { version = "6.1", optional = true }
|
||||
notify-debouncer-mini = { version = "0.4", optional = true }
|
||||
dirs = "5.0"
|
||||
eframe = "0.29"
|
||||
egui = "0.29"
|
||||
winit = "0.30"
|
||||
eframe = { version = "0.29", optional = true }
|
||||
egui = { version = "0.29", optional = true }
|
||||
winit = { version = "0.30", optional = true }
|
||||
env_logger = "0.11"
|
||||
urlencoding = "2.1"
|
||||
|
||||
[features]
|
||||
default = ["gui"]
|
||||
gui = ["tray-icon", "eframe", "egui", "winit", "notify", "notify-debouncer-mini"]
|
||||
server = []
|
||||
|
||||
|
@@ -1,28 +1,43 @@
|
||||
use log::info;
|
||||
use tray_icon::menu::MenuEvent;
|
||||
|
||||
// Modules
|
||||
mod api;
|
||||
mod admin;
|
||||
mod common;
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
mod settings;
|
||||
#[cfg(feature = "gui")]
|
||||
mod tray;
|
||||
|
||||
// Re-exports for backward compatibility and external usage
|
||||
#[cfg(feature = "gui")]
|
||||
pub use settings::run_settings_window;
|
||||
#[cfg(feature = "gui")]
|
||||
pub use tray::run_tray_app;
|
||||
|
||||
// User events for GUI communication
|
||||
#[cfg(feature = "gui")]
|
||||
#[derive(Debug)]
|
||||
pub enum UserEvent {
|
||||
TrayIconEvent,
|
||||
MenuEvent(MenuEvent),
|
||||
MenuEvent(tray_icon::menu::MenuEvent),
|
||||
ConfigFileChanged,
|
||||
UpdateMenu,
|
||||
}
|
||||
|
||||
/// Run GUI application in tray mode
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn run_gui() -> std::io::Result<()> {
|
||||
info!("Starting KHM tray application");
|
||||
run_tray_app().await
|
||||
}
|
||||
|
||||
/// Stub function when GUI is disabled
|
||||
#[cfg(not(feature = "gui"))]
|
||||
pub async fn run_gui() -> std::io::Result<()> {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Unsupported,
|
||||
"GUI features not compiled. Install system dependencies and rebuild with --features gui"
|
||||
));
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
use log::{error, info};
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
use notify::RecursiveMode;
|
||||
#[cfg(feature = "gui")]
|
||||
use notify_debouncer_mini::{new_debouncer, DebounceEventResult};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
@@ -24,6 +27,7 @@ pub struct TrayApplication {
|
||||
menu_ids: Option<TrayMenuIds>,
|
||||
settings: Arc<Mutex<KhmSettings>>,
|
||||
sync_status: Arc<Mutex<SyncStatus>>,
|
||||
#[cfg(feature = "gui")]
|
||||
_debouncer: Option<notify_debouncer_mini::Debouncer<notify::RecommendedWatcher>>,
|
||||
proxy: EventLoopProxy<crate::gui::UserEvent>,
|
||||
auto_sync_handle: Option<std::thread::JoinHandle<()>>,
|
||||
@@ -36,12 +40,14 @@ impl TrayApplication {
|
||||
menu_ids: None,
|
||||
settings: Arc::new(Mutex::new(load_settings())),
|
||||
sync_status: Arc::new(Mutex::new(SyncStatus::default())),
|
||||
#[cfg(feature = "gui")]
|
||||
_debouncer: None,
|
||||
proxy,
|
||||
auto_sync_handle: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn setup_file_watcher(&mut self) {
|
||||
let config_path = get_config_path();
|
||||
let (tx, rx) = std::sync::mpsc::channel::<DebounceEventResult>();
|
||||
|
17
src/main.rs
17
src/main.rs
@@ -154,9 +154,20 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
// Settings UI mode - just show settings window and exit
|
||||
if args.settings_ui {
|
||||
info!("Running settings UI window");
|
||||
gui::run_settings_window();
|
||||
return Ok(());
|
||||
#[cfg(feature = "gui")]
|
||||
{
|
||||
info!("Running settings UI window");
|
||||
gui::run_settings_window();
|
||||
return Ok(());
|
||||
}
|
||||
#[cfg(not(feature = "gui"))]
|
||||
{
|
||||
error!("GUI features not compiled. Install system dependencies and rebuild with --features gui");
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Unsupported,
|
||||
"GUI features not compiled"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// GUI mode has priority
|
||||
|
Reference in New Issue
Block a user