Skip to content

App API

Application-level controls: name, version, paths, quit and relaunch.

Methods

getName()

Get the configured application name.

javascript
const name = await gemshell.app.getName();

Returns: Promise<string>

getVersion()

Get the application version (from app.version in gemshell.config.json).

javascript
const version = await gemshell.app.getVersion();

Returns: Promise<string>

isPackaged()

Check if the app is running as a packaged build (production) or in development.

javascript
const packaged = await gemshell.app.isPackaged();

Returns: Promise<boolean>

getPath(name)

Look up a system path. Useful for save directories, downloads, screenshots, etc.

javascript
const userData = await gemshell.app.getPath('userData');
const downloads = await gemshell.app.getPath('downloads');

Parameters:

  • name - Path name (string). Defaults to 'userData'.

Supported names:

NameDescription
userDataPer-user app data directory (default save location)
homeUser's home directory
appDataPer-user application data directory
tempTemporary directory
desktopThe current user's Desktop
documentsThe user's Documents folder
downloadsThe user's Downloads folder
musicThe user's Music folder
picturesThe user's Pictures folder
videosThe user's Videos folder
logsApp-specific log directory

Returns: Promise<string> - Empty string if the name is invalid.

quit()

Quit the application gracefully.

javascript
await gemshell.app.quit();

Returns: Promise<boolean>

relaunch()

Restart the application. The current instance exits and a fresh one is started.

javascript
await gemshell.app.relaunch();

Returns: Promise<boolean>

Examples

About Dialog

javascript
async function showAbout() {
  const name = await gemshell.app.getName();
  const version = await gemshell.app.getVersion();
  await gemshell.dialog.message(name, `Version ${version}`);
}

Open Save Folder

javascript
async function openSaveFolder() {
  const userData = await gemshell.app.getPath('userData');
  await gemshell.os.showInFolder(userData);
}

Apply Settings and Restart

javascript
async function applyLanguage(lang) {
  await gemshell.file.save('settings', { language: lang });
  const confirmed = await gemshell.dialog.confirm(
    'Restart required',
    'Restart the game now to apply the new language?'
  );
  if (confirmed) {
    await gemshell.app.relaunch();
  }
}

Confirm Before Quitting

javascript
async function quitWithConfirm() {
  const confirmed = await gemshell.dialog.confirm('Quit Game?', 'Unsaved progress will be lost.');
  if (confirmed) {
    await gemshell.app.quit();
  }
}

Dev-only Logging

javascript
async function log(...args) {
  if (!(await gemshell.app.isPackaged())) {
    console.log('[dev]', ...args);
  }
}