| import { AppService } from '@/types/system'; |
| import { READEST_NODE_BASE_URL, READEST_WEB_BASE_URL } from './constants'; |
|
|
| declare global { |
| interface Window { |
| __READEST_CLI_ACCESS?: boolean; |
| } |
| } |
|
|
| export const isTauriAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'tauri'; |
| export const isWebAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'web'; |
| export const hasCli = () => window.__READEST_CLI_ACCESS === true; |
| export const isPWA = () => window.matchMedia('(display-mode: standalone)').matches; |
| export const getBaseUrl = () => process.env['NEXT_PUBLIC_API_BASE_URL'] ?? READEST_WEB_BASE_URL; |
| export const getNodeBaseUrl = () => |
| process.env['NEXT_PUBLIC_NODE_BASE_URL'] ?? READEST_NODE_BASE_URL; |
|
|
| export const isMacPlatform = () => |
| typeof window !== 'undefined' && /Mac|iPod|iPhone|iPad/.test(navigator.platform); |
|
|
| export const getCommandPaletteShortcut = () => (isMacPlatform() ? '⌘⇧P' : 'Ctrl+Shift+P'); |
|
|
| const isWebDevMode = () => process.env['NODE_ENV'] === 'development' && isWebAppPlatform(); |
|
|
| |
| |
| |
| export const getAPIBaseUrl = () => (isWebDevMode() ? '/api' : `${getBaseUrl()}/api`); |
|
|
| |
| export const getNodeAPIBaseUrl = () => (isWebDevMode() ? '/api' : `${getNodeBaseUrl()}/api`); |
|
|
| export interface EnvConfigType { |
| getAppService: () => Promise<AppService>; |
| } |
|
|
| let nativeAppService: AppService | null = null; |
| const getNativeAppService = async () => { |
| if (!nativeAppService) { |
| const { NativeAppService } = await import('@/services/nativeAppService'); |
| nativeAppService = new NativeAppService(); |
| await nativeAppService.init(); |
| } |
| return nativeAppService; |
| }; |
|
|
| let webAppService: AppService | null = null; |
| const getWebAppService = async () => { |
| if (!webAppService) { |
| const { WebAppService } = await import('@/services/webAppService'); |
| webAppService = new WebAppService(); |
| await webAppService.init(); |
| } |
| return webAppService; |
| }; |
|
|
| const environmentConfig: EnvConfigType = { |
| getAppService: async () => { |
| if (isTauriAppPlatform()) { |
| return getNativeAppService(); |
| } else { |
| return getWebAppService(); |
| } |
| }, |
| }; |
|
|
| export default environmentConfig; |
|
|