Skip to content

Mobile API & Capacitor Plugins

GemShell Desktop API on Mobile

The GemShell JavaScript API (file system, Steam, window, dialog, etc.) is desktop-only — it's not available in mobile builds. Mobile apps run in a native WebView and don't have access to the desktop runtime.

For mobile-specific device features, use Capacitor plugins.

Capacitor Core APIs

Capacitor provides built-in APIs available in every GemShell mobile build:

js
import { App } from '@capacitor/app'
import { Device } from '@capacitor/device'
import { Haptics } from '@capacitor/haptics'
import { Preferences } from '@capacitor/preferences'
import { ScreenOrientation } from '@capacitor/screen-orientation'
PluginWhat it does
@capacitor/appApp state, back button, deep links
@capacitor/deviceDevice info, platform, OS version
@capacitor/preferencesKey-value storage (replaces localStorage for persistence)
@capacitor/hapticsVibration / haptic feedback
@capacitor/screen-orientationLock/unlock screen orientation at runtime
@capacitor/keyboardKeyboard visibility and behavior
@capacitor/status-barShow/hide/style the status bar
@capacitor/splash-screenControl the splash screen

Full list: capacitorjs.com/docs/apis

Adding Capacitor Plugins

Add plugins via gemshell.config.json — GemShell installs them automatically during build:

json
{
  "mobile": {
    "capacitor_plugins": [
      "@capacitor/haptics",
      "@capacitor/screen-orientation"
    ]
  }
}

Then use them in your game:

js
import { Haptics, ImpactStyle } from '@capacitor/haptics'

// On touch/collision
async function onImpact() {
  await Haptics.impact({ style: ImpactStyle.Medium })
}

Platform Detection

js
import { Capacitor } from '@capacitor/core'

if (Capacitor.isNativePlatform()) {
  // Running on iOS or Android
  const platform = Capacitor.getPlatform() // 'ios' | 'android' | 'web'
}

Saving Game Data

On mobile, localStorage can be cleared by the OS. Use @capacitor/preferences for persistent save data:

js
import { Preferences } from '@capacitor/preferences'

// Save
await Preferences.set({ key: 'save_slot_1', value: JSON.stringify(saveData) })

// Load
const { value } = await Preferences.get({ key: 'save_slot_1' })
const saveData = value ? JSON.parse(value) : null

// Delete
await Preferences.remove({ key: 'save_slot_1' })

Screen Orientation

GemShell sets the orientation at build time based on your window size. To change it at runtime:

js
import { ScreenOrientation } from '@capacitor/screen-orientation'

// Lock to landscape
await ScreenOrientation.lock({ orientation: 'landscape' })

// Unlock (follow device orientation)
await ScreenOrientation.unlock()

Add @capacitor/screen-orientation to capacitor_plugins in your config first.

Community Plugins

Browse hundreds of community Capacitor plugins at capawesome.io and github.com/capacitor-community.

Popular ones for games:

PluginPurpose
@capacitor-community/admobGoogle AdMob ads
@capacitor-community/in-app-purchases-2iOS/Android in-app purchases
@capawesome/capacitor-firebaseFirebase (analytics, auth, Firestore)
@capacitor-community/sqliteSQLite database

TypeScript Types

All official Capacitor plugins ship with TypeScript definitions. Install the plugin via capacitor_plugins and import directly — types are included.

For type-safe platform detection:

ts
import { Capacitor } from '@capacitor/core'

const isIos = Capacitor.getPlatform() === 'ios'
const isAndroid = Capacitor.getPlatform() === 'android'
const isNative = Capacitor.isNativePlatform()