| 1 | import { desktopHost } from "./desktopHost"; |
| 2 | |
| 3 | export type DesktopPlatform = "darwin" | "windows" | "linux"; |
| 4 | const MACOS_WORKBENCH_TITLEBAR_HEIGHT = 46; |
| 5 | |
| 6 | export function normalizeDesktopPlatform(value: string): DesktopPlatform { |
| 7 | if (value === "darwin" || value === "windows") return value; |
| 8 | return "linux"; |
| 9 | } |
| 10 | |
| 11 | export function browserPlatformOverride(): DesktopPlatform | null { |
| 12 | if (typeof window === "undefined" || desktopHost().kind !== "none") return null; |
| 13 | const value = new URLSearchParams(window.location.search).get("platform"); |
| 14 | if (value === "darwin" || value === "windows" || value === "linux") return value; |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | export function detectBrowserPlatform(): DesktopPlatform { |
| 19 | const override = browserPlatformOverride(); |
| 20 | if (override) return override; |
| 21 | if (typeof navigator === "undefined") return "linux"; |
| 22 | const marker = `${navigator.platform} ${navigator.userAgent}`; |
| 23 | if (/Win/i.test(marker)) return "windows"; |
| 24 | if (/Mac/i.test(marker)) return "darwin"; |
| 25 | return "linux"; |
| 26 | } |
| 27 | |
| 28 | export function isMacOSWorkbenchSidebarTitlebar(target: HTMLElement | null, clientY: number, platform: DesktopPlatform): boolean { |
| 29 | if (platform !== "darwin") return false; |
| 30 | const sidebar = target?.closest(".sidebar--workbench"); |
| 31 | if (!(sidebar instanceof HTMLElement)) return false; |
| 32 | const offsetY = clientY - sidebar.getBoundingClientRect().top; |
| 33 | return offsetY >= 0 && offsetY < MACOS_WORKBENCH_TITLEBAR_HEIGHT; |
| 34 | } |
| 35 |