mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-27 23:56:59 +00:00
- Added `detectPlatformRuntime` function to determine if the app is running in a Tauri environment. - Updated `createPlatformProvider` to switch between browser and Tauri providers based on runtime detection or explicit options. - Introduced `TauriProvider` with default capabilities and methods, currently returning `NotImplementedError` for unimplemented features. - Enhanced type definitions in `vite-env.d.ts` to include Tauri-specific environment variables. - Added tests for Tauri provider functionality and runtime detection to ensure correct behavior across platforms.
23 lines
895 B
TypeScript
23 lines
895 B
TypeScript
import { createBrowserProvider } from './browser/BrowserProvider';
|
|
import { detectPlatformRuntime, type PlatformRuntime } from './detectPlatform';
|
|
import type { PlatformProvider } from './PlatformProvider';
|
|
import { createTauriProvider } from './tauri/TauriProvider';
|
|
|
|
export interface CreatePlatformProviderOptions {
|
|
/** Override runtime detection (tests). Defaults to {@link detectPlatformRuntime}. */
|
|
runtime?: PlatformRuntime;
|
|
}
|
|
|
|
/**
|
|
* Resolve the active platform backend.
|
|
* Defaults to Browser; switches to the Tauri stub when the Tauri runtime is detected
|
|
* (or when `runtime: 'tauri'` is passed explicitly).
|
|
*/
|
|
export function createPlatformProvider(options: CreatePlatformProviderOptions = {}): PlatformProvider {
|
|
const runtime = options.runtime ?? detectPlatformRuntime();
|
|
if (runtime === 'tauri') {
|
|
return createTauriProvider();
|
|
}
|
|
return createBrowserProvider();
|
|
}
|