// ============================================================ // 主进程平台判定工具 —— 直接使用 Node.js process.platform // ============================================================ import type { Platform } from '../../../shared/types'; /** 获取当前平台标识 */ export function getPlatform(): Platform { return process.platform as Platform; } /** 是否为 macOS */ export function isMacOS(): boolean { return process.platform === 'darwin'; } /** 是否为 Windows */ export function isWindows(): boolean { return process.platform === 'win32'; } /** 是否为 Linux */ export function isLinux(): boolean { return process.platform === 'linux'; } /** 获取平台名称(中文) */ export function getPlatformName(): string { if (isMacOS()) return 'macOS'; if (isWindows()) return 'Windows'; if (isLinux()) return 'Linux'; return '未知平台'; } /** 获取平台专用的快捷键修饰符描述(macOS 用 ⌘,Windows/Linux 用 Ctrl) */ export function getShortcutModifier(): string { return isMacOS() ? 'Cmd' : 'Ctrl'; } /** 判断是否需要在任务栏显示图标(macOS 不需要,Windows/Linux 需要) */ export function shouldShowTaskbarIcon(): boolean { return !isMacOS(); } /** 获取用户数据目录的基础路径 */ export function getUserDataPath(): string { // Electron app.getPath('userData') 在各平台自动适配 // 此处仅作为工具函数的补充 const home = process.env.HOME || process.env.USERPROFILE || ''; if (isMacOS()) return `${home}/Library/Application Support`; if (isWindows()) return process.env.APPDATA || `${home}\\AppData\\Roaming`; return `${home}/.config`; }