Chuyển tới nội dung chính

SDK 1.0.0

Sự kiện (Events)

The app posts events to your page as CustomEvents on window, named CatholicMiniApp:<name>.

EventDetailWhen
CatholicMiniApp:nativeReady{ title, theme, locale, sdkVersion, safeArea, onCloseAction?, deepLinkPath? }after every page load
CatholicMiniApp:themeChange{ theme: 'light' | 'dark' }the user switched theme
CatholicMiniApp:resume{}the app came back to the foreground
CatholicMiniApp:pointsUpdate{ points: number }the user's point total changed
import { onceSDKEvent, onSDKEvent, whenNativeReady } from '@i-catholic/mini-app-sdk'

const off = onSDKEvent('CatholicMiniApp:themeChange', ({ theme }) => {
document.documentElement.classList.toggle('dark', theme === 'dark')
})
off() // unsubscribe

onSDKEvent('CatholicMiniApp:resume', () => refreshData())

const { points } = await onceSDKEvent('CatholicMiniApp:pointsUpdate') // next one only

whenNativeReady()​

import { whenNativeReady } from '@i-catholic/mini-app-sdk'

const ready = whenNativeReady() // call at module top level
// … boot your app …
const { deepLinkPath, locale, theme } = await ready

It resolves on the next nativeReady event. The app keeps no "already ready" flag, so if you subscribe after the event has fired, you cannot tell you missed it, and the promise waits for the next page load. Subscribe early. For values you need later, ask directly with getTheme(), getLocale() and getSafeArea(). Outside the app it rejects immediately.