mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
feat: add VITE_APP_MODE environment variable support
- 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.
This commit is contained in:
@@ -1,13 +1,30 @@
|
|||||||
import type { NavigateOptions } from '@tanstack/react-router';
|
import type { NavigateOptions } from '@tanstack/react-router';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import { useOSDetection } from '@/hooks/use-os-detection';
|
||||||
|
|
||||||
interface AutomakerLogoProps {
|
interface AutomakerLogoProps {
|
||||||
sidebarOpen: boolean;
|
sidebarOpen: boolean;
|
||||||
navigate: (opts: NavigateOptions) => void;
|
navigate: (opts: NavigateOptions) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOSAbbreviation(os: string): string {
|
||||||
|
switch (os) {
|
||||||
|
case 'mac':
|
||||||
|
return 'M';
|
||||||
|
case 'windows':
|
||||||
|
return 'W';
|
||||||
|
case 'linux':
|
||||||
|
return 'L';
|
||||||
|
default:
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function AutomakerLogo({ sidebarOpen, navigate }: AutomakerLogoProps) {
|
export function AutomakerLogo({ sidebarOpen, navigate }: AutomakerLogoProps) {
|
||||||
const appVersion = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0';
|
const appVersion = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0';
|
||||||
|
const { os } = useOSDetection();
|
||||||
|
const appMode = import.meta.env.VITE_APP_MODE || '?';
|
||||||
|
const versionSuffix = `${getOSAbbreviation(os)}${appMode}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -69,7 +86,7 @@ export function AutomakerLogo({ sidebarOpen, navigate }: AutomakerLogoProps) {
|
|||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
<span className="text-[0.625rem] text-muted-foreground leading-none font-medium">
|
<span className="text-[0.625rem] text-muted-foreground leading-none font-medium">
|
||||||
v{appVersion}
|
v{appVersion} {versionSuffix}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -125,7 +142,7 @@ export function AutomakerLogo({ sidebarOpen, navigate }: AutomakerLogoProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[0.625rem] text-muted-foreground leading-none font-medium ml-[38.8px]">
|
<span className="text-[0.625rem] text-muted-foreground leading-none font-medium ml-[38.8px]">
|
||||||
v{appVersion}
|
v{appVersion} {versionSuffix}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ export interface OSDetectionResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function detectOS(): OperatingSystem {
|
function detectOS(): OperatingSystem {
|
||||||
// Check Electron's process.platform first (most reliable in Electron apps)
|
// Check Electron's exposed platform first (via preload contextBridge)
|
||||||
if (typeof process !== 'undefined' && process.platform) {
|
if (typeof window !== 'undefined' && window.electronAPI?.platform) {
|
||||||
if (process.platform === 'darwin') return 'mac';
|
const platform = window.electronAPI.platform;
|
||||||
if (process.platform === 'win32') return 'windows';
|
if (platform === 'darwin') return 'mac';
|
||||||
if (process.platform === 'linux') return 'linux';
|
if (platform === 'win32') return 'windows';
|
||||||
|
if (platform === 'linux') return 'linux';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof navigator === 'undefined') {
|
if (typeof navigator === 'undefined') {
|
||||||
|
|||||||
4
apps/ui/src/types/electron.d.ts
vendored
4
apps/ui/src/types/electron.d.ts
vendored
@@ -466,6 +466,10 @@ export interface AutoModeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ElectronAPI {
|
export interface ElectronAPI {
|
||||||
|
// Platform info (exposed from preload)
|
||||||
|
platform?: 'darwin' | 'win32' | 'linux';
|
||||||
|
isElectron?: boolean;
|
||||||
|
|
||||||
ping: () => Promise<string>;
|
ping: () => Promise<string>;
|
||||||
getApiKey?: () => Promise<string | null>;
|
getApiKey?: () => Promise<string | null>;
|
||||||
quit?: () => Promise<void>;
|
quit?: () => Promise<void>;
|
||||||
|
|||||||
2
apps/ui/src/vite-env.d.ts
vendored
2
apps/ui/src/vite-env.d.ts
vendored
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_SERVER_URL?: string;
|
readonly VITE_SERVER_URL?: string;
|
||||||
// Add other VITE_ prefixed env vars here as needed
|
readonly VITE_APP_MODE?: '1' | '2' | '3' | '4';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extend ImportMeta to include env property
|
// Extend ImportMeta to include env property
|
||||||
|
|||||||
2
dev.mjs
2
dev.mjs
@@ -133,6 +133,7 @@ async function main() {
|
|||||||
env: {
|
env: {
|
||||||
TEST_PORT: String(webPort),
|
TEST_PORT: String(webPort),
|
||||||
VITE_SERVER_URL: `http://localhost:${serverPort}`,
|
VITE_SERVER_URL: `http://localhost:${serverPort}`,
|
||||||
|
VITE_APP_MODE: '1',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__dirname
|
__dirname
|
||||||
@@ -159,6 +160,7 @@ async function main() {
|
|||||||
PORT: String(serverPort),
|
PORT: String(serverPort),
|
||||||
VITE_SERVER_URL: `http://localhost:${serverPort}`,
|
VITE_SERVER_URL: `http://localhost:${serverPort}`,
|
||||||
CORS_ORIGIN: corsOriginEnv,
|
CORS_ORIGIN: corsOriginEnv,
|
||||||
|
VITE_APP_MODE: '2',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__dirname
|
__dirname
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ services:
|
|||||||
- VITE_SERVER_URL=http://localhost:3008
|
- VITE_SERVER_URL=http://localhost:3008
|
||||||
- TEST_PORT=3007
|
- TEST_PORT=3007
|
||||||
- VITE_SKIP_ELECTRON=true
|
- VITE_SKIP_ELECTRON=true
|
||||||
|
- VITE_APP_MODE=3
|
||||||
volumes:
|
volumes:
|
||||||
# Mount source code for live reload
|
# Mount source code for live reload
|
||||||
- .:/app:cached
|
- .:/app:cached
|
||||||
|
|||||||
@@ -986,6 +986,7 @@ export async function launchDockerDevServerContainer({ baseDir, processes }) {
|
|||||||
SKIP_EMBEDDED_SERVER: 'true',
|
SKIP_EMBEDDED_SERVER: 'true',
|
||||||
PORT: '3008',
|
PORT: '3008',
|
||||||
VITE_SERVER_URL: 'http://localhost:3008',
|
VITE_SERVER_URL: 'http://localhost:3008',
|
||||||
|
VITE_APP_MODE: '4',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user