Skip to content

Notification API

Show native system notifications.

Methods

show(title, body)

Display a system notification.

javascript
await gemshell.notification.show('Achievement Unlocked', 'You reached level 10!');

Parameters:

  • title - Notification title (string)
  • body - Notification body text (string)

Returns: Promise<void>

isSupported()

Check if notifications are supported on the current platform.

javascript
if (await gemshell.notification.isSupported()) {
  await gemshell.notification.show('Hello', 'Notifications work!');
}

Returns: Promise<boolean>

Examples

Achievement Notification

javascript
async function unlockAchievement(achievement) {
  achievements[achievement.id] = true;
  await gemshell.file.save('achievements', achievements);
  
  await gemshell.notification.show(
    'Achievement Unlocked!',
    achievement.name
  );
}

Game Events

javascript
// Notify when game is minimized
async function onMinimized() {
  await gemshell.notification.show(
    'Game Paused',
    'Click to return to the game'
  );
}

// Notify on background completion
async function onCraftingComplete(item) {
  if (!document.hasFocus()) {
    await gemshell.notification.show(
      'Crafting Complete',
      `Your ${item.name} is ready!`
    );
  }
}

Download Complete

javascript
async function onDownloadComplete(filename) {
  await gemshell.notification.show(
    'Download Complete',
    `${filename} has been downloaded`
  );
}

Turn-Based Games

javascript
async function onNewTurn() {
  if (!document.hasFocus()) {
    await gemshell.notification.show(
      'Your Turn',
      "It's your turn in the game!"
    );
  }
}

Conditional Notifications

javascript
async function notifyIfSupported(title, body) {
  if (await gemshell.notification.isSupported()) {
    await gemshell.notification.show(title, body);
  } else {
    // Fallback to in-game notification
    showInGameNotification(title, body);
  }
}

Auto-Save Notification

javascript
async function autoSave() {
  await gemshell.file.save('autosave', getGameState());
  
  // Only notify if window not focused
  if (!document.hasFocus()) {
    await gemshell.notification.show(
      'Auto-Saved',
      'Your progress has been saved'
    );
  }
}

Notes

  • Notifications appear in the system notification center
  • The user may have disabled notifications in system settings
  • Use sparingly to avoid notification fatigue
  • Consider only showing notifications when the game window is not focused