From 821f042fd90f54a3b56c206fbb5845d263d32998 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Fri, 4 Nov 2022 19:28:30 +0800 Subject: [PATCH] opt: add join handler to prevent server stopped --- src/core_main.rs | 6 ++++-- src/tray.rs | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index b89f4a2b1..2baff12ad 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -158,10 +158,12 @@ pub fn core_main() -> Option> { std::thread::spawn(move || crate::start_server(true)); // to-do: for flutter, starting tray not ready yet, or we can reuse sciter's tray implementation. } - #[cfg(all(target_os = "linux", feature = "flutter"))] + #[cfg(all(target_os = "linux"))] { - std::thread::spawn(move || crate::start_server(true)); + let handler = std::thread::spawn(move || crate::start_server(true)); crate::tray::start_tray(crate::ui_interface::OPTIONS.clone()); + // revent server exit when encountering errors from tray + handler.join(); } } else if args[0] == "--import-config" { if args.len() == 2 { diff --git a/src/tray.rs b/src/tray.rs index c96eda684..4f45dc7bb 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -91,7 +91,6 @@ pub fn start_tray(options: Arc>>) { // init gtk context if let Err(err) = gtk::init() { error!("Error when starting the tray: {}", err); - gtk::main_quit(); return; } if let Some(mut appindicator) = get_default_app_indicator() { @@ -116,7 +115,7 @@ pub fn start_tray(options: Arc>>) { info!("Setting tray event loop"); gtk::main(); } else { - eprintln!("tray process exit now"); + error!("Tray process exit now"); } }