Skip to content

App

The App API provides app-level information and events.

Try it online

getLaunchOptionsSyncgetEnv

Switch to another tab and back to see visibility entries

App API demo

getLaunchOptionsSync and getEnv; switching browser tabs appends a visibility line (simulating app foreground/background)

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:

FieldTypeDescription
pathstringPath of the launch page
queryRecord<string, string>Launch query string parameters
scenenumberScene value (e.g. 1001)
referrerInfoobjectReferrer information
ts
const options = woo.getLaunchOptionsSync()
console.log('启动路径:', options.path)
console.log('启动参数:', options.query)
console.log('场景值:', options.scene) // 1001

onAppShow

Listen for the app coming to the foreground.

ts
woo.onAppShow(callback: () => void): () => void
ts
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 / focus events)

onAppHide

Listen for the app going to the background.

ts
woo.onAppHide(callback: () => void): () => void
ts
const unsub = woo.onAppHide(() => {
  console.log('应用进入后台')
  // Pause animations, disconnect, etc.
})

vs. Lifecycle

APIScopeWhen it fires
onAppShow / onAppHideAppEntire mini program foreground/background
onShow / onHidePageCurrent 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

MethodDescriptionSignature
getAppGet the app instance() → AppInstance
getAppInfoGet app metadata() → Promise<AppInfo>
getLaunchOptionsGet launch parameters() → LaunchOptions
canIUseCheck whether an API is available(apiName: string) → boolean
getEnvGet runtime environment information() → EnvInfo

MiniDev Studio — Mini-app Development Toolkit