Skip to content

Commit

Permalink
#115 fix locale
Browse files Browse the repository at this point in the history
  • Loading branch information
angel-git committed Apr 11, 2024
1 parent 7e9f789 commit e985169
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 32 additions & 5 deletions src-tauri/src/app/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,32 @@ pub async fn load_profile_from_spt(
internal_state.session_id = Some(session.id.clone());
}

let locale_from_settings = {
let internal_state = state.state.lock().unwrap();
let store = internal_state.store.as_ref().unwrap();
store
.get(SETTING_LOCALE)
.unwrap()
.as_str()
.unwrap()
.to_owned()
};

let bsg_items = load_bsg_items_from_server(&server_props).await.unwrap();
let globals = load_globals_from_server(&server_props).await.unwrap();
let profile = load_profile_from_server(&server_props, &session)
.await
.unwrap();
// TODO locale from settings
let locale = load_locale_from_server(&server_props, "en").await.unwrap();
let locale = load_locale_from_server(&server_props, locale_from_settings.as_str())
.await
.unwrap();

let ui_profile_result = convert_profile_to_ui(profile, &bsg_items, &locale, &globals);

{
let mut internal_state = state.state.lock().unwrap();
internal_state.bsg_items = Some(bsg_items);
internal_state.globals = Some(globals);
internal_state.locale = Some(locale);
}

match ui_profile_result {
Expand Down Expand Up @@ -110,6 +121,23 @@ pub async fn refresh_profile_from_spt(
.expect("Server details not found!")
};

let locale_from_settings = {
let internal_state = state.state.lock().unwrap();
let store = internal_state.store.as_ref().unwrap();
store
.get(SETTING_LOCALE)
.unwrap()
.as_str()
.unwrap()
.to_owned()
};

let locale_root = {
load_locale_from_server(&server_props, locale_from_settings.as_str())
.await
.unwrap()
};

{
let mut internal_state = state.state.lock().unwrap();
internal_state.session_id = Some(session.id.clone());
Expand All @@ -122,9 +150,8 @@ pub async fn refresh_profile_from_spt(
let ui_profile_result = {
let internal_state = state.state.lock().unwrap();
let bsg_items = internal_state.bsg_items.as_ref().unwrap();
let locale = internal_state.locale.as_ref().unwrap();
let globals = internal_state.globals.as_ref().unwrap();
convert_profile_to_ui(profile, bsg_items, locale, globals)
convert_profile_to_ui(profile, bsg_items, &locale_root, globals)
};

match ui_profile_result {
Expand Down
2 changes: 0 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub struct MutexState {
pub server_spt_version: Option<String>,
pub bsg_items: Option<HashMap<String, Value>>,
pub globals: Option<HashMap<String, Value>>,
pub locale: Option<HashMap<String, Value>>,
pub store: Option<Store<Wry>>,
}

Expand All @@ -65,7 +64,6 @@ fn main() {
server_props: None,
bsg_items: None,
globals: None,
locale: None,
server_file_path: None,
session_id: None,
server_spt_version: None,
Expand Down

0 comments on commit e985169

Please sign in to comment.