Skip to content

Commit 06b2ea9

Browse files
committed
feat: dock跟随设置界面
1 parent 8db357f commit 06b2ea9

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ pub fn run() {
212212
// 预创建的固定窗口:隐藏保留
213213
window.hide().unwrap();
214214
api.prevent_close();
215+
216+
// macOS:关闭偏好设置窗口时隐藏 dock 图标
217+
#[cfg(target_os = "macos")]
218+
if label == PREFERENCE_WINDOW_LABEL {
219+
let _ = window.app_handle().set_dock_visibility(false);
220+
}
215221
}
216222
}
217223
_ => {}

src-tauri/src/plugins/window/src/commands/macos.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use super::{is_main_window, shared_hide_window, shared_show_window, TOAST_WINDOW_LABEL};
1+
use super::{
2+
is_main_window, shared_hide_window, shared_show_window, PREFERENCE_WINDOW_LABEL,
3+
TOAST_WINDOW_LABEL,
4+
};
25
use crate::MAIN_WINDOW_LABEL;
36
use std::time::Duration;
47
use tauri::{command, AppHandle, Manager, PhysicalPosition, Position, Runtime, WebviewWindow};
@@ -10,12 +13,21 @@ pub enum MacOSPanelStatus {
1013
Resign,
1114
}
1215

16+
// 是否为偏好设置窗口
17+
fn is_preference_window<R: Runtime>(window: &WebviewWindow<R>) -> bool {
18+
window.label() == PREFERENCE_WINDOW_LABEL
19+
}
20+
1321
// 显示窗口
1422
#[command]
1523
pub async fn show_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWindow<R>) {
1624
if is_main_window(&window) {
1725
set_macos_panel(&app_handle, &window, MacOSPanelStatus::Show);
1826
} else {
27+
// 显示偏好设置窗口时,同时显示 dock 图标
28+
if is_preference_window(&window) {
29+
let _ = app_handle.set_dock_visibility(true);
30+
}
1931
shared_show_window(&window);
2032
}
2133
}
@@ -27,6 +39,10 @@ pub async fn hide_window<R: Runtime>(app_handle: AppHandle<R>, window: WebviewWi
2739
set_macos_panel(&app_handle, &window, MacOSPanelStatus::Hide);
2840
} else {
2941
shared_hide_window(&window);
42+
// 隐藏偏好设置窗口时,同时隐藏 dock 图标
43+
if is_preference_window(&window) {
44+
let _ = app_handle.set_dock_visibility(false);
45+
}
3046
}
3147
}
3248

src/pages/Main/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { useTauriListen } from "@/hooks/useTauriListen";
2222
import { type PasteResult, pasteToClipboard } from "@/plugins/clipboard";
2323
import {
2424
applyMainWindowLayout,
25-
showTaskbarIcon,
2625
showToastWindow,
2726
showWindow,
2827
toggleWindowVisible,
@@ -116,9 +115,6 @@ const Main = () => {
116115
},
117116
});
118117

119-
// 任务栏图标的显示与隐藏
120-
useImmediateKey(globalStore.app, "showTaskbarIcon", showTaskbarIcon);
121-
122118
// 同步配置项
123119
useTauriListen<Store>(LISTEN_KEY.STORE_CHANGED, ({ payload }) => {
124120
deepAssign(globalStore, payload.globalStore);

src/pages/Preference/components/General/index.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ const General = () => {
5656
title={t("preference.settings.app_settings.label.show_menubar_icon")}
5757
value={app.showMenubarIcon}
5858
/>
59-
60-
<ProSwitch
61-
onChange={(value) => {
62-
globalStore.app.showTaskbarIcon = value;
63-
}}
64-
title={t("preference.settings.app_settings.label.show_taskbar_icon")}
65-
value={app.showTaskbarIcon}
66-
/>
6759
</ProList>
6860

6961
<ProList header={t("preference.settings.appearance_settings.title")}>

0 commit comments

Comments
 (0)