add prototype FLTK GUI for ptth_server

Right now it can only start and stop the server once, due to a known
bug. Eventually I'd like it to be a user-friendly GUI with all the
required config files and maybe a folder browser so you can pick
which folder(s) are served.
main
_ 2021-07-11 10:59:48 -05:00
parent 2f2e4ef64d
commit 0d3b402050
3 changed files with 187 additions and 4 deletions

91
Cargo.lock generated
View File

@ -202,6 +202,15 @@ dependencies = [
"vec_map",
]
[[package]]
name = "cmake"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"
dependencies = [
"cc",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
@ -322,6 +331,40 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fltk"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fd9596a1677232504499345ad56fbad899093cd281eaf371d41941c638dc753"
dependencies = [
"bitflags",
"fltk-derive",
"fltk-sys",
"lazy_static",
"objc",
"raw-window-handle",
]
[[package]]
name = "fltk-derive"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7272e4cb6beabf0a37a8070f1700795d99fc3612dd7292842fa171e2f67d8b76"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "fltk-sys"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4d8037f9cea0c3ce53fe91c9b73950b559ae58c987647127450bae539014ca0"
dependencies = [
"cmake",
"libc",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -695,9 +738,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.92"
version = "0.2.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
[[package]]
name = "lock_api"
@ -717,6 +760,15 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
dependencies = [
"libc",
]
[[package]]
name = "maplit"
version = "1.0.2"
@ -848,6 +900,15 @@ dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
]
[[package]]
name = "once_cell"
version = "1.5.2"
@ -1227,6 +1288,19 @@ dependencies = [
"tracing-subscriber",
]
[[package]]
name = "ptth_server_gui"
version = "0.1.0"
dependencies = [
"anyhow",
"fltk",
"ptth_core",
"ptth_server",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "ptth_tail"
version = "0.1.0"
@ -1306,6 +1380,15 @@ dependencies = [
"rand_core",
]
[[package]]
name = "raw-window-handle"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a441a7a6c80ad6473bd4b74ec1c9a4c951794285bf941c2126f607c72e48211"
dependencies = [
"libc",
]
[[package]]
name = "redox_syscall"
version = "0.2.5"
@ -1655,9 +1738,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
[[package]]
name = "syn"
version = "1.0.68"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87"
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [
"proc-macro2",
"quote",

View File

@ -0,0 +1,15 @@
[package]
name = "ptth_server_gui"
version = "0.1.0"
authors = ["Trish"]
edition = "2018"
[dependencies]
anyhow = "1.0.38"
fltk = "1.0.1"
tokio = "1.4.0"
tracing = "0.1.25"
tracing-subscriber = "0.2.16"
ptth_core = { path = "../ptth_core" }
ptth_server = { path = "../ptth_server" }

View File

@ -0,0 +1,85 @@
use fltk::{app, button::Button, frame::Frame, prelude::*, window::Window};
async fn run_ptth_server () -> Result <(), anyhow::Error>
{
let config_file = ptth_server::ConfigFile {
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,
};
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 ()
{
use std::sync::Arc;
use tokio::sync::Mutex;
let rt = tokio::runtime::Runtime::new ().unwrap ();
let rt_handle = rt.handle ();
tracing_subscriber::fmt::init ();
let stopped_msg = "PTTH server: Stopped";
let started_msg = "PTTH server: Running";
let ptth_server_task = Arc::new (Mutex::new (None));
let app = app::App::default();
let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
let frame = Frame::new(0, 0, 400, 200, stopped_msg);
let mut but_run = Button::new (120, 210, 80, 40, "Run");
let mut but_stop = Button::new (200, 210, 80, 40, "Stop");
wind.end();
wind.show();
{
let ptth_server_task = Arc::clone (&ptth_server_task);
let mut frame = frame.clone ();
let rt_handle = rt_handle.clone ();
but_run.set_callback (move |_| {
rt_handle.block_on (async {
let mut task = ptth_server_task.lock ().await;
task.replace (Some (tokio::spawn (async {
if let Err (e) = run_ptth_server ().await {
tracing::error! ("{}", e);
}
})));
});
frame.set_label (started_msg);
});
}
{
let ptth_server_task = Arc::clone (&ptth_server_task);
let mut frame = frame.clone ();
let rt_handle = rt_handle.clone ();
but_stop.set_callback (move |_| {
rt_handle.block_on (async {
let mut task = ptth_server_task.lock ().await;
task.replace (None);
});
frame.set_label (stopped_msg);
});
}
app.run().unwrap();
}