@@ -15,6 +15,8 @@ pub struct Relay {
1515 pub id : String ,
1616 pub name : String ,
1717 pub host : String ,
18+ #[ serde( default ) ]
19+ pub fallback : bool ,
1820}
1921
2022#[ derive( Debug , Clone , Serialize , Deserialize , specta:: Type ) ]
@@ -90,46 +92,55 @@ fn get_default_relays() -> Vec<Relay> {
9092 id: "direct" . to_string( ) ,
9193 name: "Direct" . to_string( ) ,
9294 host: "direct.cm-ss13.com" . to_string( ) ,
95+ fallback: true ,
9396 } ,
9497 Relay {
9598 id: "nyc" . to_string( ) ,
9699 name: "NYC" . to_string( ) ,
97100 host: "nyc.cm-ss13.com" . to_string( ) ,
101+ fallback: false ,
98102 } ,
99103 Relay {
100104 id: "uk" . to_string( ) ,
101105 name: "UK" . to_string( ) ,
102106 host: "uk.cm-ss13.com" . to_string( ) ,
107+ fallback: false ,
103108 } ,
104109 Relay {
105110 id: "eu-e" . to_string( ) ,
106111 name: "EU East" . to_string( ) ,
107112 host: "eu-e.cm-ss13.com" . to_string( ) ,
113+ fallback: false ,
108114 } ,
109115 Relay {
110116 id: "eu-w" . to_string( ) ,
111117 name: "EU West" . to_string( ) ,
112118 host: "eu-w.cm-ss13.com" . to_string( ) ,
119+ fallback: false ,
113120 } ,
114121 Relay {
115122 id: "aus" . to_string( ) ,
116123 name: "Australia" . to_string( ) ,
117124 host: "aus.cm-ss13.com" . to_string( ) ,
125+ fallback: false ,
118126 } ,
119127 Relay {
120128 id: "us-e" . to_string( ) ,
121129 name: "US East" . to_string( ) ,
122130 host: "us-e.cm-ss13.com" . to_string( ) ,
131+ fallback: false ,
123132 } ,
124133 Relay {
125134 id: "us-w" . to_string( ) ,
126135 name: "US West" . to_string( ) ,
127136 host: "us-w.cm-ss13.com" . to_string( ) ,
137+ fallback: false ,
128138 } ,
129139 Relay {
130140 id: "asia-se" . to_string( ) ,
131141 name: "SE Asia" . to_string( ) ,
132142 host: "asia-se.cm-ss13.com" . to_string( ) ,
143+ fallback: false ,
133144 } ,
134145 ]
135146}
@@ -235,6 +246,21 @@ pub async fn init_relays(state: &Arc<RelayState>, handle: &AppHandle) {
235246 . collect ( ) ;
236247
237248 futures_util:: future:: join_all ( ping_futures) . await ;
249+
250+ let selected = state. get_selected ( ) . await ;
251+ if selected. is_empty ( ) {
252+ let relays = state. get_relays ( ) . await ;
253+ if let Some ( fallback) = relays. iter ( ) . find ( |r| r. relay . fallback ) {
254+ tracing:: warn!(
255+ "All relay pings failed, falling back to: {} ({})" ,
256+ fallback. relay. id,
257+ fallback. relay. host
258+ ) ;
259+ let id = fallback. relay . id . clone ( ) ;
260+ state. set_selected ( id. clone ( ) ) . await ;
261+ let _ = handle. emit ( "relay-selected" , & id) ;
262+ }
263+ }
238264}
239265
240266#[ tauri:: command]
0 commit comments