just disable Ctrl+C graceful shutdown in the GUI for now

main
_ 2021-07-11 23:33:47 +00:00
parent 41d5b896a9
commit 04975ee6c0
1 changed files with 22 additions and 11 deletions

View File

@ -12,8 +12,14 @@ use fltk::{
use tokio::{ use tokio::{
sync::Mutex, sync::Mutex,
sync::oneshot,
}; };
struct ServerInstance {
task: tokio::task::JoinHandle <()>,
shutdown_tx: oneshot::Sender <()>,
}
fn main () fn main ()
{ {
let rt = tokio::runtime::Runtime::new ().unwrap (); let rt = tokio::runtime::Runtime::new ().unwrap ();
@ -24,9 +30,9 @@ fn main ()
let stopped_msg = "PTTH server: Stopped"; let stopped_msg = "PTTH server: Stopped";
let started_msg = "PTTH server: Running"; let started_msg = "PTTH server: Running";
let ptth_server_task = Arc::new (Mutex::new (None)); let server_instance = Arc::new (Mutex::new (None));
let shutdown_rx = ptth_core::graceful_shutdown::init (); // let shutdown_rx = ptth_core::graceful_shutdown::init ();
let app = app::App::default(); let app = app::App::default();
let mut wind = Window::new(100, 100, 400, 300, "Hello from rust"); let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
@ -37,14 +43,16 @@ fn main ()
wind.show(); wind.show();
{ {
let ptth_server_task = Arc::clone (&ptth_server_task); let server_instance = Arc::clone (&server_instance);
let mut frame = frame.clone (); let mut frame = frame.clone ();
let rt_handle = rt_handle.clone (); let rt_handle = rt_handle.clone ();
but_run.set_callback (move |_| { but_run.set_callback (move |_| {
rt_handle.block_on (async { rt_handle.block_on (async {
let mut task = ptth_server_task.lock ().await; let mut server_instance = server_instance.lock ().await;
task.replace (Some (tokio::spawn (async { let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel ();
let task = tokio::spawn (async {
let config_file = ptth_server::ConfigFile { let config_file = ptth_server::ConfigFile {
name: "ptth_server".into (), name: "ptth_server".into (),
api_key: ptth_core::gen_key (), api_key: ptth_core::gen_key (),
@ -53,8 +61,6 @@ fn main ()
throttle_upload: false, throttle_upload: false,
}; };
let (_tx, shutdown_rx) = tokio::sync::oneshot::channel ();
if let Err (e) = ptth_server::run_server ( if let Err (e) = ptth_server::run_server (
config_file, config_file,
shutdown_rx, shutdown_rx,
@ -64,7 +70,12 @@ fn main ()
{ {
tracing::error! ("ptth_server crashed: {}", e); tracing::error! ("ptth_server crashed: {}", e);
} }
}))); });
server_instance.replace (Some (ServerInstance {
task,
shutdown_tx,
}));
}); });
frame.set_label (started_msg); frame.set_label (started_msg);
@ -72,14 +83,14 @@ fn main ()
} }
{ {
let ptth_server_task = Arc::clone (&ptth_server_task); let server_instance = Arc::clone (&server_instance);
let mut frame = frame.clone (); let mut frame = frame.clone ();
let rt_handle = rt_handle.clone (); let rt_handle = rt_handle.clone ();
but_stop.set_callback (move |_| { but_stop.set_callback (move |_| {
rt_handle.block_on (async { rt_handle.block_on (async {
let mut task = ptth_server_task.lock ().await; let mut server_instance = server_instance.lock ().await;
task.replace (None); server_instance.replace (None);
}); });
frame.set_label (stopped_msg); frame.set_label (stopped_msg);