WIP: i18n implementation - fix items.json syntax, add useTranslation hooks to components
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
* Asset Path Utility
|
||||
*
|
||||
* Resolves asset paths based on runtime environment:
|
||||
* - Electron: Returns local path (assets bundled with app)
|
||||
* - Electron: Returns relative path (assets bundled with app, using ./)
|
||||
* - Browser: Returns full server URL
|
||||
*/
|
||||
|
||||
// Detect if running in Electron
|
||||
const isElectron = !!(window as any).electronAPI?.isElectron
|
||||
// Detect if running in Electron - check at runtime, not module load time
|
||||
function checkIsElectron(): boolean {
|
||||
return !!(window as any).electronAPI?.isElectron ||
|
||||
window.location.protocol === 'file:'
|
||||
}
|
||||
|
||||
// Base URL for remote assets (browser mode)
|
||||
const ASSET_BASE_URL = import.meta.env.VITE_ASSET_URL ||
|
||||
@@ -21,21 +24,21 @@ const ASSET_BASE_URL = import.meta.env.VITE_ASSET_URL ||
|
||||
export function getAssetPath(path: string): string {
|
||||
if (!path) return ''
|
||||
|
||||
// Normalize path (ensure leading slash)
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
||||
// Normalize path (remove leading slash for Electron compatibility)
|
||||
const cleanPath = path.startsWith('/') ? path.slice(1) : path
|
||||
|
||||
if (isElectron) {
|
||||
// In Electron, assets are served relative to the app
|
||||
return normalizedPath
|
||||
if (checkIsElectron()) {
|
||||
// In Electron with base: './', use relative paths
|
||||
return `./${cleanPath}`
|
||||
}
|
||||
|
||||
// In browser, prepend the server URL
|
||||
return `${ASSET_BASE_URL}${normalizedPath}`
|
||||
return `${ASSET_BASE_URL}/${cleanPath}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we're running in Electron
|
||||
*/
|
||||
export function isElectronApp(): boolean {
|
||||
return isElectron
|
||||
return checkIsElectron()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user