Skip to main content
The platform abstraction layer enables the Spacedrive interface to run on multiple platforms (Web, Tauri, React Native) while accessing platform-specific features.

Problem

Spacedrive runs on:
  • Desktop via Tauri (native file pickers, native dialogs)
  • Web via browser (limited native APIs)
  • Mobile via React Native (different native APIs)
We need a single codebase that works everywhere without if (isTauri) checks scattered throughout.

Solution

The Platform type and usePlatform() hook provide a clean abstraction:

Platform Type

Usage

Setup

Wrap your app with PlatformProvider:

Using in Components

Confirmation Dialogs

Checking Platform Type

Optional Methods Pattern

All platform-specific methods are optional (marked with ?). This enables:
  1. Graceful degradation - Components can check availability and provide fallbacks
  2. Type safety - TypeScript enforces checking before calling
  3. Platform flexibility - New platforms can implement only what they support

Adding New Platform Methods

To add a new platform capability:
  1. Update the Platform type in platform.tsx
  2. Implement for each platform (Tauri, Web, React Native)
  3. Use with optional chaining in components

Best Practices

Provide Fallbacks

Always have a fallback for platforms without the feature:

Don’t Check Platform String

Avoid checking platform.platform directly. Check method availability instead:

Keep Platform Logic Minimal

Platform-specific code should be minimal. Most logic should be platform-agnostic:

Use Context, Not Props

Use usePlatform() hook instead of prop drilling:

Platform Implementations

Tauri

Web

React Native (Future)

Error Handling

Summary

The platform abstraction layer:
  • Single codebase works on Web, Tauri, and React Native
  • Clean API via usePlatform() hook
  • Type-safe with optional methods
  • Graceful degradation with feature detection
  • Minimal boilerplate using React Context
  • Easy to extend with new platform methods
Use it whenever you need platform-specific functionality like native dialogs, file pickers, or shell commands.