diff --git a/src/main.rs b/src/main.rs index 0b6124b..69b1aec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,6 +97,14 @@ fn main() -> Result<()> { let upend = Arc::new(open_result.db); + let ui_path = env::current_exe().unwrap().parent().unwrap().join("webui"); + if !ui_path.exists() { + warn!("No Web UI directory present ({:?}), disabling...", ui_path); + } + let desktop_enabled = !matches.is_present("NO_DESKTOP"); + let ui_enabled = ui_path.exists() && !matches.is_present("NO_UI"); + let browser_enabled = desktop_enabled && !matches.is_present("NO_BROWSER"); + #[cfg(feature = "previews")] let preview_store = Some(Arc::new(crate::previews::PreviewStore::new( upend.db_path.join("previews"), @@ -129,14 +137,10 @@ fn main() -> Result<()> { ), job_container: job_container.clone(), preview_store, + desktop_enabled, }; // Start HTTP server - let ui_path = env::current_exe().unwrap().parent().unwrap().join("webui"); - if !ui_path.exists() { - warn!("No Web UI directory present ({:?}), disabling...", ui_path); - } - let ui_enabled = ui_path.exists() && !matches.is_present("NO_UI"); let mut cnt = 0; let server = loop { @@ -195,7 +199,7 @@ fn main() -> Result<()> { #[cfg(feature = "desktop")] { - if !matches.is_present("NO_BROWSER") && !matches.is_present("NO_DESKTOP") && ui_enabled { + if browser_enabled && ui_enabled { let ui_result = webbrowser::open(&format!("http://localhost:{}", bind.port())); if ui_result.is_err() { warn!("Could not open UI in browser!"); diff --git a/src/routes.rs b/src/routes.rs index 43a3dab..fbaa275 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -38,6 +38,7 @@ pub struct State { pub vault_name: Option, pub job_container: Arc>, pub preview_store: Option>, + pub desktop_enabled: bool, } #[derive(Deserialize)] @@ -73,7 +74,7 @@ pub async fn get_raw( if query.native.is_none() { Ok(Either::A(NamedFile::open(file_path)?)) - } else if cfg!(feature = "desktop") { + } else if state.desktop_enabled { #[cfg(feature = "desktop")] { info!("Opening {:?}...", file_path);