Packaging · interface
DriftHostBridge
The single surface the renderer can see, and the only one it ever gets.
Explained in Packaging an application.
interface DriftHostBridgeimport type { DriftHostBridge } from '@driftengine/package';In depth
This file is a security boundary, and it is deliberately small enough to read in full.
contextIsolation is on and nodeIntegration is off, so a game — which may run third-party
code, a shader from a URL, or a mod — reaches the operating system through exactly these
members and nothing else. Adding one is a decision about what a compromised renderer can do.
storeSnapshot is a snapshot, not a live view. KeyValueStore.read is synchronous by the
engine's contract, because preferences are read during boot and an await there is a visible
flicker on every load. IPC is asynchronous. So the main process reads the store from disk once,
before the window exists, and hands it over whole; writes go the other way and do not block.
What this costs: two windows of one application would not see each other's writes, which is
why the main process makes the application single-instance.
Properties
| Name | Type | Description |
|---|---|---|
storeSnapshotreadonly | Readonly<Record<string, string>> | |
canQuit | boolean | Whether requestQuit ends the process here. False on a platform that does not exit. |
platformreadonly | { readonly available: boolean; unlockAchievement(id: string): void; setRichPresence(text: string): void; } | A store's own features, when there is a store and it answered.MoreThe SDK lives in the main process and can only live there.
|
Methods
writeKey
writeKey(key: string, value: string): void| Parameter | Type | Description |
|---|---|---|
key | string | |
value | string |
removeKey
removeKey(key: string): void| Parameter | Type | Description |
|---|---|---|
key | string |
setFullscreen
setFullscreen(on: boolean): Promise<void>| Parameter | Type | Description |
|---|---|---|
on | boolean |
isFullscreen
isFullscreen(): booleanrefreshHz
refreshHz(): number | nullA call rather than a value, unlike the store snapshot beside it.
More
Every other read here is taken once at preload because it cannot change; these can. A window dragged to a second monitor changes its refresh rate, its size and which display it is on, and a settings screen showing the value from boot would be showing the wrong monitor's.
mode
mode(): WindowModesetMode
setMode(mode: WindowMode): Promise<boolean>| Parameter | Type | Description |
|---|---|---|
mode | WindowMode |
size
size(): { width: number; height: number; }canSetSize
canSetSize(): booleanWhether setSize would work right now.
More
Synchronous like size() beside it, and for the same reason: a settings screen asks while it
is drawing a control, and an answer that arrived a frame later would draw the control twice.
The main process decides it with the same function that decides whether setSize refuses —
two conditions written twice would drift into a greyed control that works.
setSize
setSize(width: number, height: number): Promise<boolean>| Parameter | Type | Description |
|---|---|---|
width | number | |
height | number |
displays
displays(): readonly DisplayInfo[]onFocusChange
onFocusChange(handler: (focused: boolean) => void): () => void| Parameter | Type | Description |
|---|---|---|
handler | (focused: boolean) => void |
onQuitRequest
onQuitRequest(handler: () => void): () => void| Parameter | Type | Description |
|---|---|---|
handler | () => void |
requestQuit
requestQuit(): voidopenFile
openFile(accept: readonly string[]): Promise<{ name: string; bytes: Uint8Array; } | null>| Parameter | Type | Description |
|---|---|---|
accept | readonly string[] |
saveFile
saveFile(name: string, bytes: Uint8Array): Promise<boolean>| Parameter | Type | Description |
|---|---|---|
name | string | |
bytes | Uint8Array |