fix debug setting

Seto Elkahfi committed Aug 2, 2024 at 17:21 UTC 965aa59e0caadb5caf63a512d1c17d70a23a4d59
1 file changed +22 -16
frontend/splitfire-desktop/src-tauri/src/command/settings.rs
+22 -16
@@ -1,6 +1,12 @@
1 -use log::{debug, warn};
2 -use crate::{command::constants::API_HOST_DEVELOPMENT, models::{player::TauriResponse, settings::{Environment, SetEnvironmentResponse}}};
1 use super::constants::{API_HOST_PRODUCTION, CURRENT_API_HOST};
2 +use crate::{
3 + command::constants::API_HOST_DEVELOPMENT,
4 + models::{
5 + player::TauriResponse,
6 + settings::{Environment, SetEnvironmentResponse},
7 + },
8 +};
9 +use log::{debug, warn};
10
11 #[tauri::command]
12 pub fn set_environment(environment: Environment) -> SetEnvironmentResponse {
@@ -8,16 +14,16 @@ pub fn set_environment(environment: Environment) -> SetEnvironmentResponse {
14 let api_host = match environment {
15 Environment::Development => &API_HOST_DEVELOPMENT,
16 Environment::Production => &API_HOST_PRODUCTION,
11 -
17 };
18 debug!("Will set API host to: {}", api_host);
19 unsafe {
20 + let _ = CURRENT_API_HOST.take();
21 match CURRENT_API_HOST.set(api_host) {
22 Ok(_) => debug!("Did set CURRENT_API_HOST."),
23 Err(e) => warn!("Failed to set CURRENT_API_HOST: {:?}", e),
24 };
25 };
20 -
26 +
27 SetEnvironmentResponse {
28 status: TauriResponse::Success,
29 message: "CURRENT_API_HOST set done.".to_string(),
@@ -32,21 +38,21 @@ pub fn get_environment() -> Option<Environment> {
38 _ => {
39 warn!("Unknown api host!!!");
40 return None;
35 - },
41 + }
42 };
43 debug!("Current environment: {}", env);
44 Some(env)
45 }
46
47 pub fn api_host() -> &'static str {
42 - match unsafe { CURRENT_API_HOST.get() } {
43 - Some(host) => {
44 - debug!("CURRENT_API_HOST: {}", host);
45 - host
46 - },
47 - None => {
48 - warn!("API host not set. Defaulting to production.");
49 - API_HOST_PRODUCTION
50 - },
51 - }
52 -}
\ No newline at end of file
48 + match unsafe { CURRENT_API_HOST.get() } {
49 + Some(host) => {
50 + debug!("CURRENT_API_HOST: {}", host);
51 + host
52 + }
53 + None => {
54 + warn!("API host not set. Defaulting to production.");
55 + API_HOST_PRODUCTION
56 + }
57 + }
58 +}