From 367d3682d206a488f0c7f7ff879452728b6e40ec Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Fri, 26 Jun 2026 11:10:56 +0800 Subject: [PATCH] fix(desktop): use custom window controls on Linux --- .../__tests__/useWindowControls.spec.ts | 23 +++++++++++++++++++ .../src/composables/useWindowControls.ts | 8 +++++-- src-tauri/src/lib.rs | 5 ++-- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 apps/desktop/src/composables/__tests__/useWindowControls.spec.ts diff --git a/apps/desktop/src/composables/__tests__/useWindowControls.spec.ts b/apps/desktop/src/composables/__tests__/useWindowControls.spec.ts new file mode 100644 index 000000000..12850155f --- /dev/null +++ b/apps/desktop/src/composables/__tests__/useWindowControls.spec.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; +import { shouldReserveMacTrafficLightInset, shouldShowWindowControls } from "@/composables/useWindowControls"; + +describe("window controls", () => { + it("shows custom controls for non-macOS desktop windows", () => { + expect(shouldShowWindowControls(false, true)).toBe(true); + }); + + it("keeps macOS on native traffic lights", () => { + expect(shouldShowWindowControls(true, true)).toBe(false); + }); + + it("does not show desktop controls in web runtime", () => { + expect(shouldShowWindowControls(false, false)).toBe(false); + }); + + it("reserves traffic light inset only for non-fullscreen macOS desktop windows", () => { + expect(shouldReserveMacTrafficLightInset(true, false, true)).toBe(true); + expect(shouldReserveMacTrafficLightInset(true, true, true)).toBe(false); + expect(shouldReserveMacTrafficLightInset(false, false, true)).toBe(false); + expect(shouldReserveMacTrafficLightInset(true, false, false)).toBe(false); + }); +}); diff --git a/apps/desktop/src/composables/useWindowControls.ts b/apps/desktop/src/composables/useWindowControls.ts index abc478c58..763785ad2 100644 --- a/apps/desktop/src/composables/useWindowControls.ts +++ b/apps/desktop/src/composables/useWindowControls.ts @@ -1,17 +1,21 @@ import { ref, onMounted, onUnmounted } from "vue"; import { isTauriRuntime } from "@/lib/tauriRuntime"; -import { isMacOS, isWindows } from "@/lib/platform"; +import { isMacOS } from "@/lib/platform"; export function shouldReserveMacTrafficLightInset(isMac: boolean, isFullscreen: boolean, isDesktop = true): boolean { return isDesktop && isMac && !isFullscreen; } +export function shouldShowWindowControls(isMac: boolean, isDesktop = true): boolean { + return isDesktop && !isMac; +} + export function useWindowControls() { const isMaximized = ref(false); const isFullscreen = ref(false); const isMac = isMacOS(); const isDesktop = isTauriRuntime(); - const showControls = isDesktop && isWindows(); + const showControls = shouldShowWindowControls(isMac, isDesktop); let unlisten: (() => void) | null = null; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3d4cf078c..436cf6cf8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -68,8 +68,7 @@ fn should_show_main_window_after_setup() -> bool { fn native_window_decorations_override(target_os: &str) -> Option { match target_os { - "windows" => Some(false), - "linux" => Some(true), + "windows" | "linux" => Some(false), _ => None, } } @@ -270,7 +269,7 @@ mod tests { #[test] fn overrides_native_window_decorations_for_desktop_platforms() { assert_eq!(native_window_decorations_override("windows"), Some(false)); - assert_eq!(native_window_decorations_override("linux"), Some(true)); + assert_eq!(native_window_decorations_override("linux"), Some(false)); assert_eq!(native_window_decorations_override("macos"), None); }