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"
|
futures = "0.3"
|
||||||
hostname = "0.3"
|
hostname = "0.3"
|
||||||
rust-embed = "8.0"
|
rust-embed = "8.0"
|
||||||
tray-icon = "0.19"
|
tray-icon = { version = "0.19", optional = true }
|
||||||
notify = "6.1"
|
notify = { version = "6.1", optional = true }
|
||||||
notify-debouncer-mini = "0.4"
|
notify-debouncer-mini = { version = "0.4", optional = true }
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
eframe = "0.29"
|
eframe = { version = "0.29", optional = true }
|
||||||
egui = "0.29"
|
egui = { version = "0.29", optional = true }
|
||||||
winit = "0.30"
|
winit = { version = "0.30", optional = true }
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
urlencoding = "2.1"
|
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 log::info;
|
||||||
use tray_icon::menu::MenuEvent;
|
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
mod api;
|
mod api;
|
||||||
mod admin;
|
mod admin;
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
mod settings;
|
mod settings;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
mod tray;
|
mod tray;
|
||||||
|
|
||||||
// Re-exports for backward compatibility and external usage
|
// Re-exports for backward compatibility and external usage
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use settings::run_settings_window;
|
pub use settings::run_settings_window;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub use tray::run_tray_app;
|
pub use tray::run_tray_app;
|
||||||
|
|
||||||
// User events for GUI communication
|
// User events for GUI communication
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum UserEvent {
|
pub enum UserEvent {
|
||||||
TrayIconEvent,
|
TrayIconEvent,
|
||||||
MenuEvent(MenuEvent),
|
MenuEvent(tray_icon::menu::MenuEvent),
|
||||||
ConfigFileChanged,
|
ConfigFileChanged,
|
||||||
UpdateMenu,
|
UpdateMenu,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run GUI application in tray mode
|
/// Run GUI application in tray mode
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
pub async fn run_gui() -> std::io::Result<()> {
|
pub async fn run_gui() -> std::io::Result<()> {
|
||||||
info!("Starting KHM tray application");
|
info!("Starting KHM tray application");
|
||||||
run_tray_app().await
|
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};
|
use log::{error, info};
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use notify::RecursiveMode;
|
use notify::RecursiveMode;
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
use notify_debouncer_mini::{new_debouncer, DebounceEventResult};
|
use notify_debouncer_mini::{new_debouncer, DebounceEventResult};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -24,6 +27,7 @@ pub struct TrayApplication {
|
|||||||
menu_ids: Option<TrayMenuIds>,
|
menu_ids: Option<TrayMenuIds>,
|
||||||
settings: Arc<Mutex<KhmSettings>>,
|
settings: Arc<Mutex<KhmSettings>>,
|
||||||
sync_status: Arc<Mutex<SyncStatus>>,
|
sync_status: Arc<Mutex<SyncStatus>>,
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
_debouncer: Option<notify_debouncer_mini::Debouncer<notify::RecommendedWatcher>>,
|
_debouncer: Option<notify_debouncer_mini::Debouncer<notify::RecommendedWatcher>>,
|
||||||
proxy: EventLoopProxy<crate::gui::UserEvent>,
|
proxy: EventLoopProxy<crate::gui::UserEvent>,
|
||||||
auto_sync_handle: Option<std::thread::JoinHandle<()>>,
|
auto_sync_handle: Option<std::thread::JoinHandle<()>>,
|
||||||
@@ -36,12 +40,14 @@ impl TrayApplication {
|
|||||||
menu_ids: None,
|
menu_ids: None,
|
||||||
settings: Arc::new(Mutex::new(load_settings())),
|
settings: Arc::new(Mutex::new(load_settings())),
|
||||||
sync_status: Arc::new(Mutex::new(SyncStatus::default())),
|
sync_status: Arc::new(Mutex::new(SyncStatus::default())),
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
_debouncer: None,
|
_debouncer: None,
|
||||||
proxy,
|
proxy,
|
||||||
auto_sync_handle: None,
|
auto_sync_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gui")]
|
||||||
fn setup_file_watcher(&mut self) {
|
fn setup_file_watcher(&mut self) {
|
||||||
let config_path = get_config_path();
|
let config_path = get_config_path();
|
||||||
let (tx, rx) = std::sync::mpsc::channel::<DebounceEventResult>();
|
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
|
// Settings UI mode - just show settings window and exit
|
||||||
if args.settings_ui {
|
if args.settings_ui {
|
||||||
info!("Running settings UI window");
|
#[cfg(feature = "gui")]
|
||||||
gui::run_settings_window();
|
{
|
||||||
return Ok(());
|
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
|
// GUI mode has priority
|
||||||
|
Reference in New Issue
Block a user