@@ -64,7 +64,12 @@ pub fn router(state: ServerState) -> axum::Router {
6464 )
6565 . merge (
6666 axum:: Router :: new ( )
67- . route ( "/connect" , get ( get_control_status) . post ( request_control) )
67+ . route (
68+ "/connect" ,
69+ get ( get_control_status)
70+ . post ( request_control)
71+ . put ( update_website_info) ,
72+ )
6873 . route (
6974 "/version" ,
7075 get ( || async { Json ( env ! ( "CARGO_PKG_VERSION" ) ) } ) ,
@@ -405,6 +410,62 @@ async fn request_control(
405410 }
406411}
407412
413+ async fn update_website_info (
414+ State ( state) : State < ServerState > , headers : HeaderMap ,
415+ axum:: Json ( scope_data) : axum:: Json < ScopeData > ,
416+ ) -> Result < impl IntoResponse , ( StatusCode , String ) > {
417+ let req_scope = headers
418+ . get ( "Origin" )
419+ . and_then ( |h| h. to_str ( ) . ok ( ) )
420+ . unwrap_or_default ( )
421+ . to_owned ( ) ;
422+ let mut scopes = state. scopes . write ( ) . await ;
423+ if let Some ( scope) = scopes. iter_mut ( ) . find ( |s| s. host == req_scope) {
424+ scope. name = scope_data. name . clone ( ) ;
425+ scope. features = scope_data. features . clone ( ) ;
426+ let state_d = scope. state . clone ( ) ;
427+
428+ match slint:: invoke_from_event_loop ( move || {
429+ let ui_handle = state. ui . upgrade ( ) . unwrap ( ) ;
430+ let scope_bridge = ui_handle. global :: < ScopeBridge > ( ) ;
431+ let scopes = scope_bridge. get_scopes ( ) ;
432+ let scopes = scopes. as_any ( ) . downcast_ref :: < VecModel < Scope > > ( ) . unwrap ( ) ;
433+ let mut index = 0 ;
434+ for i in scopes. iter ( ) {
435+ if i. host == req_scope {
436+ break ;
437+ }
438+ index += 1 ;
439+ }
440+ let scope = Scope {
441+ host : req_scope. clone ( ) . into ( ) ,
442+ name : scope_data. name . clone ( ) . into ( ) ,
443+ state : state_d. into ( ) ,
444+ features : scope_data. features . join ( "," ) . into ( ) ,
445+ } ;
446+ scopes. set_row_data ( index, scope) ;
447+ } ) {
448+ Ok ( _) => {
449+ debug ! ( "Updated scope in UI" ) ;
450+ }
451+ Err ( e) => {
452+ debug ! ( "Failed to update UI: {e}" ) ;
453+ return Err ( (
454+ StatusCode :: INTERNAL_SERVER_ERROR ,
455+ "failed to update UI" . to_owned ( ) ,
456+ ) ) ;
457+ }
458+ }
459+
460+ Ok ( StatusCode :: OK )
461+ } else {
462+ Err ( (
463+ StatusCode :: FORBIDDEN ,
464+ format ! ( "Scope {} not found" , req_scope) ,
465+ ) )
466+ }
467+ }
468+
408469async fn popup_window (
409470 State ( state) : State < ServerState > ,
410471) -> Result < impl IntoResponse , ( StatusCode , String ) > {
0 commit comments