🐛 bug: the GUI can now restart `ptth_server` properly
parent
0d3b402050
commit
41d5b896a9
|
@ -1,34 +1,21 @@
|
||||||
use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
|
use std::{
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
async fn run_ptth_server () -> Result <(), anyhow::Error>
|
use fltk::{
|
||||||
{
|
app,
|
||||||
let config_file = ptth_server::ConfigFile {
|
button::Button,
|
||||||
name: "ptth_server".into (),
|
frame::Frame,
|
||||||
api_key: ptth_core::gen_key (),
|
prelude::*,
|
||||||
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
|
window::Window
|
||||||
file_server_root: Some (".".into ()),
|
};
|
||||||
throttle_upload: false,
|
|
||||||
};
|
use tokio::{
|
||||||
|
sync::Mutex,
|
||||||
tracing::debug! ("Running PTTH server task");
|
};
|
||||||
|
|
||||||
ptth_server::run_server (
|
|
||||||
config_file,
|
|
||||||
ptth_core::graceful_shutdown::init (),
|
|
||||||
None,
|
|
||||||
None
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
tracing::debug! ("Ended PTTH server task");
|
|
||||||
|
|
||||||
Ok (())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main ()
|
fn main ()
|
||||||
{
|
{
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
let rt = tokio::runtime::Runtime::new ().unwrap ();
|
let rt = tokio::runtime::Runtime::new ().unwrap ();
|
||||||
let rt_handle = rt.handle ();
|
let rt_handle = rt.handle ();
|
||||||
|
|
||||||
|
@ -39,6 +26,8 @@ fn main ()
|
||||||
|
|
||||||
let ptth_server_task = Arc::new (Mutex::new (None));
|
let ptth_server_task = Arc::new (Mutex::new (None));
|
||||||
|
|
||||||
|
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");
|
||||||
let frame = Frame::new(0, 0, 400, 200, stopped_msg);
|
let frame = Frame::new(0, 0, 400, 200, stopped_msg);
|
||||||
|
@ -56,8 +45,24 @@ fn main ()
|
||||||
rt_handle.block_on (async {
|
rt_handle.block_on (async {
|
||||||
let mut task = ptth_server_task.lock ().await;
|
let mut task = ptth_server_task.lock ().await;
|
||||||
task.replace (Some (tokio::spawn (async {
|
task.replace (Some (tokio::spawn (async {
|
||||||
if let Err (e) = run_ptth_server ().await {
|
let config_file = ptth_server::ConfigFile {
|
||||||
tracing::error! ("{}", e);
|
name: "ptth_server".into (),
|
||||||
|
api_key: ptth_core::gen_key (),
|
||||||
|
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
|
||||||
|
file_server_root: Some (".".into ()),
|
||||||
|
throttle_upload: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let (_tx, shutdown_rx) = tokio::sync::oneshot::channel ();
|
||||||
|
|
||||||
|
if let Err (e) = ptth_server::run_server (
|
||||||
|
config_file,
|
||||||
|
shutdown_rx,
|
||||||
|
None,
|
||||||
|
None
|
||||||
|
).await
|
||||||
|
{
|
||||||
|
tracing::error! ("ptth_server crashed: {}", e);
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
});
|
});
|
||||||
|
@ -81,5 +86,5 @@ fn main ()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
app.run().unwrap();
|
app.run ().unwrap ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue