From 326e9757489e6818e0e6745ac4fead92b4030c57 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 25 Aug 2025 10:33:19 +0800 Subject: [PATCH] feat: use @tauri-apps/api/os for reliable platform detection (mac body class) --- src/main.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index d22f8b0..9d59af2 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -4,11 +4,16 @@ import App from './App' import './index.css' // 导入 Tauri API(自动绑定到 window.api) import './lib/tauri-api' +import { platform as osPlatform } from '@tauri-apps/api/os' // 根据平台添加 body class,便于平台特定样式 -if (window.platform?.isMac) { - document.body.classList.add('is-mac') -} +osPlatform().then((p) => { + if (p === 'darwin') { + document.body.classList.add('is-mac') + } +}).catch(() => { + // 忽略平台检测失败 +}) ReactDOM.createRoot(document.getElementById('root')!).render(