@@ -8,7 +8,7 @@ use moonraker_rs::moonraker_connection::{GeneralEvent, MoonrakerEvent, PrinterEv
88use slint:: { Image , Model , ModelRc , PlatformError , Rgb8Pixel , Rgba8Pixel , SharedPixelBuffer , SharedString , VecModel } ;
99use tokio:: sync:: Mutex ;
1010
11- use crate :: { application_error:: ApplicationError , hardware:: init_display} ;
11+ use crate :: { application_error:: ApplicationError , config :: MoonrakerConfig , hardware:: init_display} ;
1212
1313
1414mod config;
@@ -29,8 +29,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
2929
3030 let config_str = fs:: read_to_string ( & config_path) . unwrap ( ) ;
3131 let config = toml:: from_str :: < config:: Config > ( & config_str) . unwrap ( ) ;
32+ let moonraker_config = config. moonraker . unwrap_or ( MoonrakerConfig :: default ( ) ) ;
3233
33- let moonraker_connection = Arc :: new ( moonraker_rs:: moonraker_connection:: MoonrakerConnection :: new ( "localhost" , 7125 ) ) ;
34+ let moonraker_connection = Arc :: new ( moonraker_rs:: moonraker_connection:: MoonrakerConnection :: new ( & moonraker_config . host , moonraker_config . port ) ) ;
3435 let moonraker_connection_clone = moonraker_connection. clone ( ) ;
3536 let moonraker_connection_clone_2 = moonraker_connection. clone ( ) ;
3637
@@ -53,7 +54,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
5354 //println!("Received Moonraker event: {:?}", event);
5455 //connection_ref.get_listener();
5556
56- if let GeneralEvent :: MoonrakerEvent ( moonraker_event) = & * event
57+ if let GeneralEvent :: Connected = & * event
58+ {
59+ ui_weak. upgrade_in_event_loop ( move |ui| ui. global :: < AppState > ( ) . set_moonraker_connected ( true ) ) . unwrap ( ) ;
60+ }
61+ else if let GeneralEvent :: Disconnected = & * event
62+ {
63+ ui_weak. upgrade_in_event_loop ( move |ui| ui. global :: < AppState > ( ) . set_moonraker_connected ( false ) ) . unwrap ( ) ;
64+ }
65+ else if let GeneralEvent :: MoonrakerEvent ( moonraker_event) = & * event
5766 {
5867 if let MoonrakerEvent :: NotifyStatusUpdate ( status_update) = moonraker_event
5968 {
@@ -222,6 +231,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
222231 SharedString :: from ( format ! ( "{:.2} {}" , value, units[ idx] ) )
223232 } ) ;
224233
234+ ui. global :: < AppState > ( ) . set_moonraker_connected ( false ) ;
235+
225236 tokio:: task:: block_in_place ( || {
226237 ui. run ( ) . unwrap ( ) ;
227238 } ) ;
0 commit comments