♻️ refactor: load server GUI config before creating the GUI

main
Trisha 2022-03-25 15:24:45 -05:00
parent 1d9ef8f510
commit 8c4e7d484c
1 changed files with 10 additions and 3 deletions

View File

@ -42,7 +42,9 @@ fn main ()
let app = app::App::default();
let mut wind = Window::new (100, 100, 500, 180, "PTTH server");
let mut gui = Gui::new (fltk_tx);
let config_file_opt = ptth_server::load_toml::load::<ConfigFile, _> ("./config/ptth_server.toml").ok ();
let mut gui = Gui::new (fltk_tx, config_file_opt.as_ref ());
gui.set_server_running (false);
wind.end ();
@ -111,7 +113,12 @@ pub struct ConfigFile {
}
impl Gui {
fn new (fltk_tx: app::Sender <Message>) -> Self {
fn new (
fltk_tx: app::Sender <Message>,
config_file_opt: Option <&ConfigFile>,
)
-> Self
{
let mut input_name = Input::new (200, 10, 290, 20, "name");
input_name.set_value ("my_ptth_server");
@ -134,7 +141,7 @@ impl Gui {
but_stop.set_trigger (CallbackTrigger::Changed);
but_stop.emit (fltk_tx, Message::StopServer);
if let Ok (config_file) = ptth_server::load_toml::load::<ConfigFile, _> ("./config/ptth_server.toml")
if let Some (config_file) = config_file_opt
{
if let Some (v) = config_file.name.as_ref () {
input_name.set_value (v);