feat: enhance platform provider with Tauri support and runtime detection

- 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.
This commit is contained in:
鲁树人 committed 2026-11-06 04:31:34 +09:00
1 parent 4d688af4ca
commit 6571dc5344
6 files changed
+362 -4

No files matched your search

+14 -2
View File
@@ -1,10 +1,22 @@
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.
* Currently always returns the browser provider; native (e.g. Tauri) switching can be added here later.
* Defaults to Browser; switches to the Tauri stub when the Tauri runtime is detected
* (or when `runtime: 'tauri'` is passed explicitly).
*/
export function createPlatformProvider(): PlatformProvider {
export function createPlatformProvider(options: CreatePlatformProviderOptions = {}): PlatformProvider {
const runtime = options.runtime ?? detectPlatformRuntime();
if (runtime === 'tauri') {
return createTauriProvider();
}
return createBrowserProvider();
}