Skip to content

OS API

System information and utilities.

Methods

getName()

Get the operating system name.

javascript
const os = await gemshell.os.getName();
// 'macOS', 'Windows', or 'Linux'

Returns: Promise<string> - Human-readable OS name

getVersion()

Get the OS version/release.

javascript
const version = await gemshell.os.getVersion();
// e.g., '14.0.0' (macOS), '10.0.22621' (Windows)

Returns: Promise<string> - OS version string

getLocale()

Get the system locale.

javascript
const locale = await gemshell.os.getLocale();
// 'en_US', 'de_DE', 'ja_JP', etc.

Returns: Promise<string> - Locale code with underscore separator

getLocaleLanguage()

Get just the language code.

javascript
const lang = await gemshell.os.getLocaleLanguage();
// 'en', 'de', 'ja', etc.

Returns: Promise<string> - Two-letter language code

openURL(url)

Open a URL in the default browser.

javascript
await gemshell.os.openURL('https://example.com');

Parameters:

  • url - The URL to open (string)

Returns: Promise<boolean> - true on success

showInFolder(path)

Show a file or folder in the system file manager.

javascript
const savesPath = await gemshell.file.getPath();
await gemshell.os.showInFolder(savesPath);

Parameters:

  • path - Path to file or folder (string)

Returns: Promise<boolean> - true on success

Examples

Platform-Specific Code

javascript
async function getPlatformInfo() {
  const os = await gemshell.os.getName();
  
  switch (os) {
    case 'macOS':
      return { modifier: 'Cmd', pathSep: '/' };
    case 'Windows':
      return { modifier: 'Ctrl', pathSep: '\\' };
    case 'Linux':
      return { modifier: 'Ctrl', pathSep: '/' };
  }
}

Localization

javascript
async function getLanguage() {
  const lang = await gemshell.os.getLocaleLanguage();
  
  const supported = ['en', 'de', 'fr', 'es', 'ja', 'zh'];
  return supported.includes(lang) ? lang : 'en';
}

async function loadTranslations() {
  const lang = await getLanguage();
  const response = await fetch(`locales/${lang}.json`);
  return response.json();
}

Show System Info

javascript
async function showSystemInfo() {
  const os = await gemshell.os.getName();
  const version = await gemshell.os.getVersion();
  const locale = await gemshell.os.getLocale();
  
  console.log(`Running on ${os} ${version}`);
  console.log(`Locale: ${locale}`);
}
javascript
function openWebsite() {
  gemshell.os.openURL('https://mygame.com');
}

function openDiscord() {
  gemshell.os.openURL('https://discord.gg/mygame');
}

function reportBug() {
  gemshell.os.openURL('https://github.com/user/mygame/issues');
}

function openSteamStore() {
  gemshell.os.openURL('https://store.steampowered.com/app/YOUR_APP_ID');
}

Open Save Folder

javascript
async function openSaveFolder() {
  const savesPath = await gemshell.file.getPath();
  await gemshell.os.showInFolder(savesPath);
}

Platform-Specific Controls Display

javascript
async function getControlsText() {
  const os = await gemshell.os.getName();
  const mod = os === 'macOS' ? '⌘' : 'Ctrl';
  
  return {
    save: `${mod}+S`,
    load: `${mod}+L`,
    quit: os === 'macOS' ? '⌘+Q' : 'Alt+F4',
    fullscreen: os === 'macOS' ? '⌃⌘+F' : 'F11'
  };
}