Release v0.2.10: Update package-lock.json and CI config
This commit is contained in:
41
pwa/src/utils/assetPath.ts
Normal file
41
pwa/src/utils/assetPath.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Asset Path Utility
|
||||
*
|
||||
* Resolves asset paths based on runtime environment:
|
||||
* - Electron: Returns local path (assets bundled with app)
|
||||
* - Browser: Returns full server URL
|
||||
*/
|
||||
|
||||
// Detect if running in Electron
|
||||
const isElectron = !!(window as any).electronAPI?.isElectron
|
||||
|
||||
// Base URL for remote assets (browser mode)
|
||||
const ASSET_BASE_URL = import.meta.env.VITE_ASSET_URL ||
|
||||
(import.meta.env.PROD ? 'https://api-staging.echoesoftheash.com' : '')
|
||||
|
||||
/**
|
||||
* Resolves an asset path for the current environment
|
||||
* @param path - The asset path (e.g., "images/items/knife.webp" or "/images/items/knife.webp")
|
||||
* @returns The resolved path for the current environment
|
||||
*/
|
||||
export function getAssetPath(path: string): string {
|
||||
if (!path) return ''
|
||||
|
||||
// Normalize path (ensure leading slash)
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
||||
|
||||
if (isElectron) {
|
||||
// In Electron, assets are served relative to the app
|
||||
return normalizedPath
|
||||
}
|
||||
|
||||
// In browser, prepend the server URL
|
||||
return `${ASSET_BASE_URL}${normalizedPath}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we're running in Electron
|
||||
*/
|
||||
export function isElectronApp(): boolean {
|
||||
return isElectron
|
||||
}
|
||||
Reference in New Issue
Block a user