fix(desktop): use custom window controls on Linux

This commit is contained in:
t8y2 2026-06-26 11:10:56 +08:00
parent 676dcdb490
commit 367d3682d2
3 changed files with 31 additions and 5 deletions

View File

@ -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);
});
});

View File

@ -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;

View File

@ -68,8 +68,7 @@ fn should_show_main_window_after_setup() -> bool {
fn native_window_decorations_override(target_os: &str) -> Option<bool> {
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);
}