|
3 | 3 | //! relay list at the time of creating the installer.
|
4 | 4 |
|
5 | 5 | #[cfg(not(target_os = "android"))]
|
6 |
| -use mullvad_api::{ |
7 |
| - proxy::ApiConnectionMode, rest::Error as RestError, ApiEndpoint, RelayListProxy, |
8 |
| -}; |
9 |
| -#[cfg(not(target_os = "android"))] |
10 |
| -use std::process; |
11 |
| -#[cfg(not(target_os = "android"))] |
12 |
| -use talpid_types::ErrorExt; |
| 6 | +mod imp { |
| 7 | + use mullvad_api::{ |
| 8 | + proxy::ApiConnectionMode, rest::Error as RestError, ApiEndpoint, RelayListProxy, |
| 9 | + }; |
| 10 | + use std::process; |
| 11 | + use talpid_types::ErrorExt; |
| 12 | + |
| 13 | + pub async fn main() { |
| 14 | + let runtime = mullvad_api::Runtime::new( |
| 15 | + tokio::runtime::Handle::current(), |
| 16 | + &ApiEndpoint::from_env_vars(), |
| 17 | + ); |
| 18 | + |
| 19 | + let relay_list_request = RelayListProxy::new( |
| 20 | + runtime.mullvad_rest_handle(ApiConnectionMode::Direct.into_provider()), |
| 21 | + ) |
| 22 | + .relay_list(None) |
| 23 | + .await; |
| 24 | + |
| 25 | + let relay_list = match relay_list_request { |
| 26 | + Ok(relay_list) => relay_list, |
| 27 | + Err(RestError::TimeoutError) => { |
| 28 | + eprintln!("Request timed out"); |
| 29 | + process::exit(2); |
| 30 | + } |
| 31 | + Err(e @ RestError::DeserializeError(_)) => { |
| 32 | + eprintln!( |
| 33 | + "{}", |
| 34 | + e.display_chain_with_msg("Failed to deserialize relay list") |
| 35 | + ); |
| 36 | + process::exit(3); |
| 37 | + } |
| 38 | + Err(e) => { |
| 39 | + eprintln!("{}", e.display_chain_with_msg("Failed to fetch relay list")); |
| 40 | + process::exit(1); |
| 41 | + } |
| 42 | + }; |
| 43 | + println!("{}", serde_json::to_string_pretty(&relay_list).unwrap()); |
| 44 | + } |
| 45 | +} |
13 | 46 |
|
14 | 47 | #[tokio::main]
|
15 |
| -#[cfg(target_os = "android")] |
16 |
| -async fn main() {} |
17 |
| -#[tokio::main] |
18 |
| -#[cfg(not(target_os = "android"))] |
19 | 48 | async fn main() {
|
20 |
| - let runtime = mullvad_api::Runtime::new( |
21 |
| - tokio::runtime::Handle::current(), |
22 |
| - &ApiEndpoint::from_env_vars(), |
23 |
| - ); |
24 |
| - |
25 |
| - let relay_list_request = |
26 |
| - RelayListProxy::new(runtime.mullvad_rest_handle(ApiConnectionMode::Direct.into_provider())) |
27 |
| - .relay_list(None) |
28 |
| - .await; |
| 49 | + imp::main().await |
| 50 | +} |
29 | 51 |
|
30 |
| - let relay_list = match relay_list_request { |
31 |
| - Ok(relay_list) => relay_list, |
32 |
| - Err(RestError::TimeoutError) => { |
33 |
| - eprintln!("Request timed out"); |
34 |
| - process::exit(2); |
35 |
| - } |
36 |
| - Err(e @ RestError::DeserializeError(_)) => { |
37 |
| - eprintln!( |
38 |
| - "{}", |
39 |
| - e.display_chain_with_msg("Failed to deserialize relay list") |
40 |
| - ); |
41 |
| - process::exit(3); |
42 |
| - } |
43 |
| - Err(e) => { |
44 |
| - eprintln!("{}", e.display_chain_with_msg("Failed to fetch relay list")); |
45 |
| - process::exit(1); |
46 |
| - } |
47 |
| - }; |
48 |
| - println!("{}", serde_json::to_string_pretty(&relay_list).unwrap()); |
| 52 | +#[cfg(target_os = "android")] |
| 53 | +mod imp { |
| 54 | + pub async fn main() {} |
49 | 55 | }
|
0 commit comments