gui fixes
This commit is contained in:
+16
-16
@@ -25,21 +25,23 @@ use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() >= 2 && args[1].eq_ignore_ascii_case("pdf-import") {
|
||||
return run_pdf_import(&args[2..]).await;
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
return rt.block_on(run_pdf_import(&args[2..]));
|
||||
}
|
||||
if args.len() >= 2 && args[1].eq_ignore_ascii_case("cli") {
|
||||
return run_cli().await;
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
return rt.block_on(run_cli());
|
||||
}
|
||||
|
||||
if args.iter().any(|a| a == "--browser") {
|
||||
run_browser_mode().await
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
rt.block_on(run_browser_mode())
|
||||
} else {
|
||||
run_gui_mode().await
|
||||
run_gui_mode_main_thread()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,28 +118,26 @@ async fn run_browser_mode() -> Result<()> {
|
||||
start_server(addr, state, true).await
|
||||
}
|
||||
|
||||
async fn run_gui_mode() -> Result<()> {
|
||||
let state = build_state().await?;
|
||||
fn run_gui_mode_main_thread() -> Result<()> {
|
||||
let rt = tokio::runtime::Runtime::new()?;
|
||||
|
||||
let state = rt.block_on(build_state())?;
|
||||
|
||||
// Start the web server in background (not blocking, no browser open)
|
||||
let addr = "127.0.0.1:3000";
|
||||
let server_state = state.clone();
|
||||
let server_handle = tokio::spawn(async move {
|
||||
let server_handle = rt.spawn(async move {
|
||||
if let Err(e) = start_server(addr, server_state, false).await {
|
||||
eprintln!("Server error: {e}");
|
||||
}
|
||||
});
|
||||
|
||||
// Let the server start
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
|
||||
// Run the egui GUI in a blocking task
|
||||
// Run the egui GUI on the main thread (winit/eframe requires this)
|
||||
let http_url = "http://127.0.0.1:3001".to_string();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
crate::gui::run_gui(&http_url);
|
||||
})
|
||||
.await
|
||||
.ok();
|
||||
crate::gui::run_gui(&http_url);
|
||||
|
||||
server_handle.abort();
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user