forked from akai/readest
aa16bc09f1
Now we support Web platform
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { AppService } from '@/types/system';
|
|
|
|
export const isTauriAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'tauri';
|
|
export const isWebAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'web';
|
|
|
|
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.loadSettings();
|
|
}
|
|
return nativeAppService;
|
|
};
|
|
|
|
let webAppService: AppService | null = null;
|
|
const getWebAppService = async () => {
|
|
if (!webAppService) {
|
|
const { WebAppService } = await import('@/services/webAppService');
|
|
webAppService = new WebAppService();
|
|
await webAppService.loadSettings();
|
|
}
|
|
return webAppService;
|
|
};
|
|
|
|
const environmentConfig: EnvConfigType = {
|
|
getAppService: async () => {
|
|
if (isTauriAppPlatform()) {
|
|
return getNativeAppService();
|
|
} else {
|
|
return getWebAppService();
|
|
}
|
|
},
|
|
};
|
|
|
|
export default environmentConfig;
|