Skip to content

Commit 398ea4d

Browse files
committed
refactor(locale): simplify visibility lookup and align shell locale API
1 parent 958606a commit 398ea4d

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

src-tauri/src/desktop_bridge_commands.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ pub(crate) fn desktop_bridge_set_shell_locale(
154154
app_handle: AppHandle,
155155
locale: Option<String>,
156156
) -> BackendBridgeResult {
157+
let packaged_root_dir = runtime_paths::default_packaged_root_dir();
157158
match shell_locale::write_cached_shell_locale(
158159
locale.as_deref(),
159-
runtime_paths::default_packaged_root_dir(),
160+
packaged_root_dir.as_deref(),
160161
) {
161162
Ok(()) => {
162163
tray_labels::update_tray_menu_labels(
@@ -169,9 +170,12 @@ pub(crate) fn desktop_bridge_set_shell_locale(
169170
reason: None,
170171
}
171172
}
172-
Err(error) => BackendBridgeResult {
173-
ok: false,
174-
reason: Some(error),
175-
},
173+
Err(error) => {
174+
append_desktop_log(&format!("failed to persist shell locale: {error}"));
175+
BackendBridgeResult {
176+
ok: false,
177+
reason: Some(error),
178+
}
179+
}
176180
}
177181
}

src-tauri/src/shell_locale.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ fn read_cached_shell_locale(packaged_root_dir: Option<&Path>) -> Option<&'static
9696

9797
pub(crate) fn write_cached_shell_locale(
9898
locale: Option<&str>,
99-
packaged_root_dir: Option<PathBuf>,
99+
packaged_root_dir: Option<&Path>,
100100
) -> Result<(), String> {
101-
let Some(state_path) = desktop_state_path_for_locale(packaged_root_dir.as_deref()) else {
101+
let Some(state_path) = desktop_state_path_for_locale(packaged_root_dir) else {
102102
return Ok(());
103103
};
104104

src-tauri/src/tray_labels.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ pub fn update_tray_menu_labels_with_visibility<F>(
4141
runtime_paths::default_packaged_root_dir(),
4242
);
4343
let shell_texts = shell_locale::shell_texts_for_locale(locale);
44-
let window_visibility = app_handle
45-
.get_webview_window("main")
46-
.and_then(|window| window.is_visible().ok());
47-
let is_visible = window_visibility.unwrap_or(true);
48-
let effective_visible = visible_override.unwrap_or(is_visible);
44+
let effective_visible = if let Some(visible) = visible_override {
45+
visible
46+
} else {
47+
app_handle
48+
.get_webview_window("main")
49+
.and_then(|window| window.is_visible().ok())
50+
.unwrap_or(true)
51+
};
4952

5053
let toggle_label = if effective_visible {
5154
shell_texts.tray_hide

0 commit comments

Comments
 (0)