♻️ refactor
parent
97ef6d7fce
commit
16b86ff45c
|
@ -17,6 +17,8 @@ use protocol::PeerId;
|
|||
|
||||
#[derive (Debug, StructOpt)]
|
||||
struct Opt {
|
||||
#[structopt (long)]
|
||||
window_title: Option <String>,
|
||||
#[structopt (long)]
|
||||
relay_addr: Option <String>,
|
||||
#[structopt (long)]
|
||||
|
@ -38,7 +40,9 @@ fn main () -> anyhow::Result <()> {
|
|||
let (fltk_tx, fltk_rx) = app::channel::<Message> ();
|
||||
|
||||
let app = app::App::default ();
|
||||
let mut wind = Window::new (100, 100, 800, 600, "PTTH client proxy");
|
||||
let window_title = opt.window_title.clone ().unwrap_or_else (|| "PTTH client proxy".to_string ());
|
||||
let mut wind = Window::new (100, 100, 800, 600, None)
|
||||
.with_label (&window_title);
|
||||
|
||||
let margin = 10;
|
||||
let h = 30;
|
||||
|
@ -47,13 +51,6 @@ fn main () -> anyhow::Result <()> {
|
|||
|
||||
let mut frame_status;
|
||||
|
||||
|
||||
let mut input_client_port;
|
||||
let mut input_server_id;
|
||||
let mut input_server_port;
|
||||
let mut but_open;
|
||||
let mut but_close;
|
||||
|
||||
{
|
||||
frame_status = Frame::new (10, 10, 800 - 20, 30, "Forwarding 0 ports");
|
||||
}
|
||||
|
@ -78,47 +75,7 @@ fn main () -> anyhow::Result <()> {
|
|||
y += h + margin;
|
||||
x = margin;
|
||||
|
||||
{
|
||||
let w = 80;
|
||||
input_client_port = Input::new (x, y, w, h, "");
|
||||
x += w + margin;
|
||||
|
||||
let w = 120;
|
||||
input_server_id = Input::new (x, y, w, h, "");
|
||||
x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
input_server_port = Input::new (x, y, w, h, "");
|
||||
x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
but_open = Button::new (x, y, w, h, "Open");
|
||||
x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
but_close = Button::new (x, y, w, h, "Close");
|
||||
// x += w + margin;
|
||||
|
||||
input_client_port.set_value ("5901");
|
||||
input_server_id.set_value ("bogus_server");
|
||||
input_server_port.set_value ("5900");
|
||||
|
||||
but_open.set_trigger (CallbackTrigger::Changed);
|
||||
but_open.emit (fltk_tx, Message::OpenPort);
|
||||
but_close.set_trigger (CallbackTrigger::Changed);
|
||||
but_close.emit (fltk_tx, Message::ClosePort);
|
||||
|
||||
set_active (&mut but_open, true);
|
||||
set_active (&mut but_close, false);
|
||||
}
|
||||
|
||||
let mut gui_port = GuiPort {
|
||||
input_client_port,
|
||||
input_server_id,
|
||||
input_server_port,
|
||||
but_open,
|
||||
but_close,
|
||||
};
|
||||
let mut gui_port = GuiPort::new (fltk_tx, &mut x, y);
|
||||
|
||||
// y += h + margin;
|
||||
|
||||
|
@ -329,6 +286,51 @@ struct ForwardingParams {
|
|||
}
|
||||
|
||||
impl GuiPort {
|
||||
fn new (fltk_tx: fltk::app::Sender <Message>, x: &mut i32, y: i32) -> Self {
|
||||
let margin = 10;
|
||||
let h = 30;
|
||||
|
||||
let w = 80;
|
||||
let mut input_client_port = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 120;
|
||||
let mut input_server_id = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
let mut input_server_port = Input::new (*x, y, w, h, "");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
let mut but_open = Button::new (*x, y, w, h, "Open");
|
||||
*x += w + margin;
|
||||
|
||||
let w = 80;
|
||||
let mut but_close = Button::new (*x, y, w, h, "Close");
|
||||
// *x += w + margin;
|
||||
|
||||
input_client_port.set_value ("5901");
|
||||
input_server_id.set_value ("bogus_server");
|
||||
input_server_port.set_value ("5900");
|
||||
|
||||
but_open.set_trigger (CallbackTrigger::Changed);
|
||||
but_open.emit (fltk_tx, Message::OpenPort);
|
||||
but_close.set_trigger (CallbackTrigger::Changed);
|
||||
but_close.emit (fltk_tx, Message::ClosePort);
|
||||
|
||||
set_active (&mut but_open, true);
|
||||
set_active (&mut but_close, false);
|
||||
|
||||
Self {
|
||||
input_client_port,
|
||||
input_server_id,
|
||||
input_server_port,
|
||||
but_open,
|
||||
but_close,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_params (&self) -> anyhow::Result <ForwardingParams>
|
||||
{
|
||||
let client_tcp_port = u16::from_str (&self.input_client_port.value ())?;
|
||||
|
|
Loading…
Reference in New Issue