Host · interface

Lifecycle

Focus, and the end of the process.

Explained in Display and the host.

interface Lifecycle
import type { Lifecycle } from '@driftengine/core';

In depth

The engine needs to know when it stopped being looked at — a paused simulation, a muted mixer — and a shell additionally needs to be told to close. A browser cannot close its own tab, so requestQuit warns rather than silently doing nothing: a silent no-op reads as a working call, which is the failure AGENTS.md names where an unimplemented capability returns a plausible answer instead of a defined one.

Every subscription returns its own unsubscribe. Nothing here is called per frame.

Properties

NameTypeDescription
canQuitreadonlybooleanWhether requestQuit will actually end the process.
More

This is what an exit button should be drawn from. A browser cannot close its own tab and iOS applications do not exit programmatically, so a menu that always shows Exit has a button that does nothing on two of the platforms a game ships to — and a game that instead branches on "am I in a shell" has hard-coded an assumption that stops being true. Ask the capability.

Methods

onFocusChange

onFocusChange(handler: (focused: boolean) => void): () => void
ParameterTypeDescription
handler(focused: boolean) => void

onQuitRequest

onQuitRequest(handler: () => void): () => void

The shell is closing and the game may finish what it is doing.

ParameterTypeDescription
handler() => void
More

A shell calls the handler on a window-close request and waits; a browser never calls it, because a tab closing gives nothing that can be waited on.

requestQuit

requestQuit(): void