Skip to content

GemShell API

Native desktop features available in your game at runtime.

Access via the global gemshell object in your game code.

Overview

javascript
// Check if running in GemShell
if (typeof gemshell !== 'undefined') {
  // Native features available
  const os = await gemshell.os.getName();
  console.log(`Running on ${os}`);
}

Available APIs

Core (always available)

APIDescription
FileSave/load game data (key-value store)
AssetsExternal asset loading: drop a mods/ folder for hot-swap + Steam Workshop auto-mount
WindowWindow size, position, fullscreen, frameless, opacity
AppApp name/version, paths, quit, relaunch
ScreenDisplay info and cursor position
InputPointer lock for FPS games
DialogNative file/folder dialogs
ClipboardCopy/paste text
NotificationSystem notifications
OSSystem info, open URLs

Steamworks (when enabled in gemshell.config.json)

APIDescription
OverviewInit, callbacks, lifecycle
User InfoSteam ID, persona name, friends, avatars
AchievementsUnlock, query, stats
Cloud SavesSteam Cloud file storage
LeaderboardsFind, upload, download scores
Lobbies & P2PMatchmaking and peer-to-peer networking
Rich PresenceSet "playing as..." text
OverlaySteam in-game overlay
InputController and Steam Input API
Utils & DLCDLC, Big Picture, Steam Deck, server time

Tooling

TypeScript SupportOfficial .d.ts for autocomplete + type-checking

Game Version

javascript
console.log(gemshell.version);  // e.g. '1.0.0'

Returns your game's version, taken from app.version in your gemshell.config.json. Synchronous shortcut for await gemshell.app.getVersion().

Quick Examples

Save Game Data

javascript
const gameState = {
  level: currentLevel,
  score: playerScore,
  inventory: playerInventory
};
await gemshell.file.save('savegame', gameState);

Load Game Data

javascript
const save = await gemshell.file.load('savegame');
if (save) {
  currentLevel = save.level;
  playerScore = save.score;
  playerInventory = save.inventory;
}

Toggle Fullscreen

javascript
await gemshell.window.toggleFullscreen();

// Or check and set
const isFullscreen = await gemshell.window.isFullscreen();
await gemshell.window.setFullscreen(!isFullscreen);

Get System Info

javascript
const os = await gemshell.os.getName();     // 'macOS', 'Windows', 'Linux'
const locale = await gemshell.os.getLocale(); // 'en_US', 'de_DE', etc.

Show Confirmation

javascript
const confirmed = await gemshell.dialog.confirm(
  'Delete Save?',
  'This cannot be undone.'
);

if (confirmed) {
  await gemshell.file.delete('savegame');
}
javascript
await gemshell.os.openURL('https://mygame.com');

Feature Detection

Always check for availability to support both web and native:

javascript
// Check if GemShell is available
function hasGemShell() {
  return typeof gemshell !== 'undefined';
}

// Save with fallback to localStorage
async function saveGame(data) {
  if (hasGemShell()) {
    await gemshell.file.save('savegame', data);
  } else {
    localStorage.setItem('savegame', JSON.stringify(data));
  }
}

// Load with fallback
async function loadGame() {
  if (hasGemShell()) {
    return await gemshell.file.load('savegame');
  } else {
    const saved = localStorage.getItem('savegame');
    return saved ? JSON.parse(saved) : null;
  }
}

TypeScript Support

Official type definitions covering the entire API (including Steamworks) are available as a single file:

Download gemshell.d.ts - or read the full setup guide.

ts
/// <reference path="./gemshell.d.ts" />

if (gemshell) {
  const size = await gemshell.window.getSize();
  // Autocomplete, parameter hints and type-checking everywhere
}