@@ -56,7 +56,7 @@ use url::Url;
5656use crate :: sliding_sync:: { submit_async_request, MatrixRequest , RegisterRequest } ;
5757use crate :: login:: login_screen:: LoginAction ;
5858use super :: {
59- register_status_modal:: RegisterStatusModalAction ,
59+ register_status_modal:: { RegisterStatusModalAction , RegisterStatusModalWidgetExt } ,
6060 validation:: {
6161 MIN_PASSWORD_CHARS , needs_custom_homeserver_input, normalize_custom_homeserver,
6262 normalize_username, password_has_min_chars,
@@ -409,7 +409,7 @@ live_design! {
409409 }
410410}
411411
412- #[ derive( Live , LiveHook , Widget ) ]
412+ #[ derive( Live , Widget ) ]
413413pub struct RegisterScreen {
414414 #[ deref]
415415 view : View ,
@@ -427,6 +427,12 @@ pub struct RegisterScreen {
427427 registration_token_required : bool ,
428428}
429429
430+ impl LiveHook for RegisterScreen {
431+ fn after_new_from_doc ( & mut self , _cx : & mut Cx ) {
432+ self . selected_homeserver = "matrix.org" . to_string ( ) ;
433+ }
434+ }
435+
430436impl RegisterScreen {
431437 fn toggle_homeserver_options ( & mut self , cx : & mut Cx ) {
432438 self . is_homeserver_editing = !self . is_homeserver_editing ;
@@ -436,6 +442,20 @@ impl RegisterScreen {
436442 self . redraw ( cx) ;
437443 }
438444
445+ /// Updates the radio-style homeserver option buttons to reflect the current selection.
446+ fn update_homeserver_option_buttons ( & self , cx : & mut Cx ) {
447+ let is_matrix_org = !self . pending_custom_homeserver ;
448+ let matrix_btn = self . view . button ( ids ! ( matrix_option) ) ;
449+ let other_btn = self . view . button ( ids ! ( other_option) ) ;
450+ if is_matrix_org {
451+ matrix_btn. set_text ( cx, "● matrix.org" ) ;
452+ other_btn. set_text ( cx, "○ Other homeserver" ) ;
453+ } else {
454+ matrix_btn. set_text ( cx, "○ matrix.org" ) ;
455+ other_btn. set_text ( cx, "● Other homeserver" ) ;
456+ }
457+ }
458+
439459 fn show_warning ( & self , message : & str ) {
440460 use crate :: shared:: popup_list:: { enqueue_popup_notification, PopupItem , PopupKind } ;
441461 enqueue_popup_notification ( PopupItem {
@@ -521,10 +541,7 @@ impl RegisterScreen {
521541 . set_visible ( cx, false ) ;
522542
523543 // Reset homeserver option buttons
524- let matrix_option_button = self . view . button ( ids ! ( matrix_option) ) ;
525- let other_option_button = self . view . button ( ids ! ( other_option) ) ;
526- matrix_option_button. set_text ( cx, "● matrix.org" ) ;
527- other_option_button. set_text ( cx, "○ Other homeserver" ) ;
544+ self . update_homeserver_option_buttons ( cx) ;
528545
529546 // Clear input fields
530547 self . view . text_input ( ids ! ( username_input) ) . set_text ( cx, "" ) ;
@@ -574,12 +591,6 @@ impl MatchEvent for RegisterScreen {
574591 let edit_button = self . view . button ( ids ! ( edit_button) ) ;
575592 let sso_button = self . view . button ( ids ! ( sso_button) ) ;
576593
577- // Initialize selected_homeserver if empty
578- if self . selected_homeserver . is_empty ( ) {
579- self . selected_homeserver = "matrix.org" . to_string ( ) ;
580- self . pending_custom_homeserver = false ;
581- }
582-
583594 if login_button. clicked ( actions) {
584595 cx. action ( RegisterAction :: NavigateToLogin ) ;
585596 }
@@ -596,10 +607,9 @@ impl MatchEvent for RegisterScreen {
596607 self . update_button_mask ( & sso_button, cx, 1.0 ) ;
597608
598609 // Show SSO registration modal immediately
599- let status_label = self . view . label ( ids ! ( status_modal_inner. status) ) ;
600- status_label. set_text ( cx, "Opening your browser...\n \n Please complete registration in your browser, then return to Robrix." ) ;
601- let cancel_button = self . view . button ( ids ! ( status_modal_inner. cancel_button) ) ;
602- cancel_button. set_text ( cx, "Cancel" ) ;
610+ let status_modal_inner = self . view . register_status_modal ( ids ! ( status_modal_inner) ) ;
611+ status_modal_inner. set_status ( cx, "Opening your browser...\n \n Please complete registration in your browser, then return to Robrix." ) ;
612+ status_modal_inner. button_ref ( ) . set_text ( cx, "Cancel" ) ;
603613 self . view . modal ( ids ! ( status_modal) ) . open ( cx) ;
604614 self . redraw ( cx) ;
605615
@@ -629,8 +639,7 @@ impl MatchEvent for RegisterScreen {
629639 . set_visible ( cx, false ) ;
630640
631641 // Update button styles to show selection
632- matrix_option_button. set_text ( cx, "● matrix.org" ) ;
633- other_option_button. set_text ( cx, "○ Other homeserver" ) ;
642+ self . update_homeserver_option_buttons ( cx) ;
634643
635644 self . is_homeserver_editing = false ;
636645 self . view
@@ -650,8 +659,7 @@ impl MatchEvent for RegisterScreen {
650659 . set_text ( cx, "Custom homeserver (required)" ) ;
651660
652661 // Update button styles to show selection
653- matrix_option_button. set_text ( cx, "○ matrix.org" ) ;
654- other_option_button. set_text ( cx, "● Other homeserver" ) ;
662+ self . update_homeserver_option_buttons ( cx) ;
655663 self . update_registration_mode ( cx) ;
656664 }
657665
@@ -748,12 +756,10 @@ impl MatchEvent for RegisterScreen {
748756 self . update_button_mask ( & register_button, cx, 1.0 ) ;
749757
750758 // Show registration status modal with appropriate text for password registration
751- let status_label = self . view . label ( ids ! ( status_modal_inner. status) ) ;
752- status_label. set_text ( cx, "Registering account, please wait..." ) ;
753- let title_label = self . view . label ( ids ! ( status_modal_inner. title) ) ;
754- title_label. set_text ( cx, "Registration Status" ) ;
755- let cancel_button = self . view . button ( ids ! ( status_modal_inner. cancel_button) ) ;
756- cancel_button. set_text ( cx, "Cancel" ) ;
759+ let status_modal_inner = self . view . register_status_modal ( ids ! ( status_modal_inner) ) ;
760+ status_modal_inner. set_status ( cx, "Registering account, please wait..." ) ;
761+ status_modal_inner. set_title ( cx, "Registration Status" ) ;
762+ status_modal_inner. button_ref ( ) . set_text ( cx, "Cancel" ) ;
757763 self . view . modal ( ids ! ( status_modal) ) . open ( cx) ;
758764 self . redraw ( cx) ;
759765
@@ -827,11 +833,9 @@ impl MatchEvent for RegisterScreen {
827833 RegisterAction :: SsoRegistrationStatus { status } => {
828834 // Update SSO status in modal (only if our modal is already open)
829835 if self . sso_pending {
830- let status_label = self . view . label ( ids ! ( status_modal_inner. status) ) ;
831- status_label. set_text ( cx, status) ;
832- let cancel_button =
833- self . view . button ( ids ! ( status_modal_inner. cancel_button) ) ;
834- cancel_button. set_text ( cx, "Cancel" ) ;
836+ let status_modal_inner = self . view . register_status_modal ( ids ! ( status_modal_inner) ) ;
837+ status_modal_inner. set_status ( cx, status) ;
838+ status_modal_inner. button_ref ( ) . set_text ( cx, "Cancel" ) ;
835839 self . redraw ( cx) ;
836840 }
837841 }
0 commit comments