mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-31 20:03:37 +00:00
- Introduced VITE_APP_MODE variable in multiple files to manage application modes. - Updated dev.mjs and docker-compose.dev.yml to set different modes for development. - Enhanced type definitions in vite-env.d.ts to include VITE_APP_MODE options. - Modified AutomakerLogo component to display version suffix based on the current app mode. - Improved OS detection logic in use-os-detection.ts to utilize Electron's platform information. - Updated ElectronAPI interface to expose platform information. These changes provide better control over application behavior based on the mode, enhancing the development experience.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useMemo } from 'react';
|
|
|
|
export type OperatingSystem = 'mac' | 'windows' | 'linux' | 'unknown';
|
|
|
|
export interface OSDetectionResult {
|
|
readonly os: OperatingSystem;
|
|
readonly isMac: boolean;
|
|
readonly isWindows: boolean;
|
|
readonly isLinux: boolean;
|
|
}
|
|
|
|
function detectOS(): OperatingSystem {
|
|
// Check Electron's exposed platform first (via preload contextBridge)
|
|
if (typeof window !== 'undefined' && window.electronAPI?.platform) {
|
|
const platform = window.electronAPI.platform;
|
|
if (platform === 'darwin') return 'mac';
|
|
if (platform === 'win32') return 'windows';
|
|
if (platform === 'linux') return 'linux';
|
|
}
|
|
|
|
if (typeof navigator === 'undefined') {
|
|
return 'unknown';
|
|
}
|
|
|
|
// Fallback: use modern userAgentData API with fallback to navigator.platform
|
|
const nav = navigator as Navigator & { userAgentData?: { platform: string } };
|
|
const platform = (nav.userAgentData?.platform ?? navigator.platform ?? '').toLowerCase();
|
|
|
|
if (platform.includes('mac')) return 'mac';
|
|
if (platform.includes('win')) return 'windows';
|
|
if (platform.includes('linux') || platform.includes('x11')) return 'linux';
|
|
return 'unknown';
|
|
}
|
|
|
|
/**
|
|
* Hook to detect the user's operating system.
|
|
* Returns OS information and convenience boolean flags.
|
|
*/
|
|
export function useOSDetection(): OSDetectionResult {
|
|
return useMemo(() => {
|
|
const os = detectOS();
|
|
return {
|
|
os,
|
|
isMac: os === 'mac',
|
|
isWindows: os === 'windows',
|
|
isLinux: os === 'linux',
|
|
};
|
|
}, []);
|
|
}
|