App
The App API provides app-level information and events.
Try it online
Switch to another tab and back to see visibility entries
Import
ts
import woo from 'mini-sdk'
// 或
import { app } from 'mini-sdk'API reference
getLaunchOptionsSync
Synchronously get mini program launch parameters.
ts
const options = woo.getLaunchOptionsSync()Return value LaunchOptions:
| Field | Type | Description |
|---|---|---|
path | string | Path of the launch page |
query | Record<string, string> | Launch query string parameters |
scene | number | Scene value (e.g. 1001) |
referrerInfo | object | Referrer information |
ts
const options = woo.getLaunchOptionsSync()
console.log('启动路径:', options.path)
console.log('启动参数:', options.query)
console.log('场景值:', options.scene) // 1001onAppShow
Listen for the app coming to the foreground.
ts
woo.onAppShow(callback: () => void): () => voidts
const unsub = woo.onAppShow(() => {
console.log('应用进入前台')
// Refresh data, resume connections, etc.
})When it fires
onAppShow runs in these cases:
- Switching from background to foreground
- The window regains focus (
visibilitychange/focusevents)
onAppHide
Listen for the app going to the background.
ts
woo.onAppHide(callback: () => void): () => voidts
const unsub = woo.onAppHide(() => {
console.log('应用进入后台')
// Pause animations, disconnect, etc.
})vs. Lifecycle
| API | Scope | When it fires |
|---|---|---|
onAppShow / onAppHide | App | Entire mini program foreground/background |
onShow / onHide | Page | Current page show/hide |
ts
// App-level — register once globally
woo.onAppShow(() => console.log('App Show'))
woo.onAppHide(() => console.log('App Hide'))
// Page-level — register per page
woo.onShow(() => console.log('Page Show'))
woo.onHide(() => console.log('Page Hide'))Quick reference
| Method | Description | Signature |
|---|---|---|
getApp | Get the app instance | () → AppInstance |
getAppInfo | Get app metadata | () → Promise<AppInfo> |
getLaunchOptions | Get launch parameters | () → LaunchOptions |
canIUse | Check whether an API is available | (apiName: string) → boolean |
getEnv | Get runtime environment information | () → EnvInfo |