Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

chore(sdk): the lifecycle's host path states its contract, and the snapshot names the new seams

esengine8dafa4019e5c
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index de0c35380..57cf644c2 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -5015,9 +5015,11 @@ hideLoading: (() => void) | undefined
loadSubpackage: ((opts: { name: string; success?: () => void; fail?: (err: unknown) => void; complete?: () => void; }) => void) | undefined
login: ((opts: { success?: (res: { code: string; }) => void; fail?: (err: unknown) => void; timeout?: number; }) => void) | undefined
offError: ((cb: (error: string | { message?: string; stack?: string; }) => void) => void) | undefined
+offHide: ((cb: () => void) => void) | undefined
offKeyDown: ((cb: (res: MiniGameKeyEvent) => void) => void) | undefined
offKeyUp: ((cb: (res: MiniGameKeyEvent) => void) => void) | undefined
offMemoryWarning: ((cb: () => void) => void) | undefined
+offShow: ((cb: () => void) => void) | undefined
offTouchCancel: ((cb: (res: MiniGameTouchEvent) => void) => void) | undefined
offTouchEnd: (cb: (res: MiniGameTouchEvent) => void) => void
offTouchMove: (cb: (res: MiniGameTouchEvent) => void) => void
@@ -5107,6 +5109,8 @@ loadSubpackage: (name: string) => Promise<void>
login: () => Promise<string>
name: PlatformName
now: () => number
+onAppHide: (callback: () => void) => () => void
+onAppShow: (callback: () => void) => () => void
onMemoryWarning: (callback: () => void) => () => void
onShareRequest: (provide: () => PlatformShareOptions) => void
onUnhandledError: (callback: (error: unknown) => void) => () => void
diff --git a/sdk/src/ecs/lifecycle.ts b/sdk/src/ecs/lifecycle.ts
index bc79912ab..7462d8139 100644
--- a/sdk/src/ecs/lifecycle.ts
+++ b/sdk/src/ecs/lifecycle.ts
@@ -181,11 +181,9 @@ function setupWebLifecycle_(manager: LifecycleManager, app: AppLike): () => void
// =============================================================================
/**
- * No DOM visibility event: the host pushes foreground/background through the
- * platform adapter (a mini-game's onShow/onHide, the native bridge). On native
- * the audio device is suspended by the host directly on background — correct
- * even while the JS tick is paused — so this only drives the game tick and the
- * lifecycle events.
+ * The host pushes foreground/background through the adapter (a mini-game's
+ * onShow/onHide, the native bridge). Native suspends audio itself on background,
+ * so this only drives the game tick and the lifecycle events.
*/
function setupHostLifecycle_(manager: LifecycleManager, app: AppLike): () => void {
let pausedByLifecycle = false;
diff --git a/sdk/tests/minigame-lifecycle.test.ts b/sdk/tests/minigame-lifecycle.test.ts
index 9d8616372..f5d7209cf 100644
--- a/sdk/tests/minigame-lifecycle.test.ts
+++ b/sdk/tests/minigame-lifecycle.test.ts
@@ -4,9 +4,8 @@
* @file Lifecycle on a mini-game host that is not WeChat.
*
* Every mini-game runs with a `document` stub (wxgame-pre.js) that has no
- * addEventListener. The plugin used to branch on the vendor name, so any other
- * vendor fell through to the web path and threw at boot — which is how a vivo
- * quick game first died on an emulator. The host's own onShow/onHide drive it.
+ * addEventListener, so the web path must never be taken from one; the host's
+ * own onShow/onHide drive it, whichever vendor it is.
*/
import { describe, it, expect, afterEach } from 'vitest';
import { App } from '../src/app/app';