> ## Documentation Index
> Fetch the complete documentation index at: https://docs.overlayed.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Updates

> Managing App and Site updates in your overlay

Overlayed provides two update systems: [App updates](/deployment/updates#app-updates) (the Electron app) and
[Site updates](/deployment/updates#site-updates) (your frontend).

## App Updates

The `overlayed.updater` module provides methods to check for updates, switch channels, and install updates.

### Checking for Updates

```typescript theme={null}
const result = await overlay.updater.checkForUpdates();
```

### Listening to Update Events

```typescript theme={null}
overlay.updater.on("updateAvailable", ({ info }) => {
	overlay.log.info(`Update available: ${info.version}`);
});

overlay.updater.on("updateDownloaded", ({ event }) => {
	overlay.log.info("Update downloaded, ready to install");
});

overlay.updater.on("error", ({ error, message }) => {
	overlay.log.error("Update error:", message);
});
```

### Installing Updates

After an update is downloaded, you can install it:

```typescript theme={null}
function handleUpdate() {
	const [canUpdate, reason] = overlay.updater.canUpdate();

	if (canUpdate) {
		overlay.updater.quitAndInstall(true, true);
	} else {
		overlay.log.error(`Cannot update: ${reason}`);
	}
}

overlay.updater.on("updateDownloaded", () => handleUpdate());
```

Alternatively, you can wait for the `checkForUpdates` promise to resolve:

```typescript theme={null}
const result = await overlay.updater.checkForUpdates();
if (result && result.isUpdateAvailable) {
	handleUpdate();
}
```

<Warning>
  `quitAndInstall` will throw an error if `canUpdate()` returns false. This happens when the user is currently in a
  game.
</Warning>

### Private Channels

For private update channels, you must provide an access token fetcher:

```typescript theme={null}
overlay.updater.setAccessTokenFetcher((channel) => {
	// Fetch a token for the given channel from your auth system
	return getTokenForChannel(channel);
});
```

Listen for token invalidation when they lose access and move them to the public channel:

```typescript theme={null}
overlay.updater.on("authTokenInvalid", async () => {
	await overlay.updater.checkForUpdates();
	overlay.updater.quitAndInstall(true, true);
});
```

See [Private Channels](/deployment/private-channels) for full server implementation examples.

### Switching Channels

To switch update channels (e.g., from stable to beta):

```typescript theme={null}
await overlay.updater.switchChannel("beta");
await overlay.updater.checkForUpdates();
```

## Site Updates

The `overlayed.updater.site` module handles Site updates separately from App updates.

### Automatic Updates (Default)

By default, Site updates are applied automatically. When you deploy a new Site version, users will receive it on the
next call of `BrowserWindow#loadURL`.

### Manual Updates

To control when Site updates are applied, enable manual updates:

```typescript theme={null}
const overlay = overlayed({
	site: {
		manualUpdates: true,
	},
});
```

Then listen for new versions and prompt users:

```typescript theme={null}
overlay.updater.site.on("siteUpdateReady", ({ version }) => {
	showUpdatePrompt(version);
});

function onUserClicksUpdate() {
	overlay.updater.site.allowSiteUpdateOnNextLoad();
	// Reload all windows to apply the update
	allWindows.forEach((window) => window.webContents.reload());
}
```

## Application Info

The `overlayed.application` module provides information about the current release:

```typescript theme={null}
const channel = overlay.application.getChannel();
const version = overlay.application.getVersion();
const releaseId = overlay.application.getReleaseId(); // null during development
```

We recommend showing the channel and version in your UI to help users give better feedback and bug reports.

## Update Events Reference

| Event                | Description                        |
| -------------------- | ---------------------------------- |
| `checkingForUpdates` | Started checking for updates       |
| `updateAvailable`    | An update is available             |
| `updateNotAvailable` | No update available                |
| `downloadProgress`   | Download progress update           |
| `updateDownloaded`   | Update has finished downloading    |
| `updateCancelled`    | Update was cancelled               |
| `error`              | An error occurred                  |
| `authTokenInvalid`   | Access token is invalid or expired |
