Skip to main content

euv_core/platform/miniapp/
enum.rs

1use super::*;
2
3/// All 13 supported mainstream super-app Mini-Program and Atomic Service host ecosystems.
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum MiniAppVendor {
6    /// WeChat Mini-Program (`wx`, `.wxml` / `.wxss`).
7    #[default]
8    WeChat,
9    /// Alipay Mini-Program (`my`, `.axml` / `.acss`).
10    Alipay,
11    /// Douyin / ByteDance Mini-Program (`tt`, `.ttml` / `.ttss`).
12    Douyin,
13    /// Baidu Smart Mini-Program (`swan`, `.swan` / `.css`).
14    Baidu,
15    /// QQ Mini-Program (`qq`, `.qml` / `.qss`).
16    Qq,
17    /// Kuaishou Mini-Program (`ks`, `.ksml` / `.css`).
18    Kuaishou,
19    /// JD Mini-Program (`jd`, `.jxml` / `.jxss`).
20    Jd,
21    /// Xiaohongshu Mini-Program (`xhs`, `.xhsml` / `.css`).
22    Xiaohongshu,
23    /// DingTalk Mini-Program (`dd`, `.axml` / `.acss`).
24    DingTalk,
25    /// Feishu / Lark Gadget Mini-Program (`tt`, `.ttml` / `.ttss`).
26    Feishu,
27    /// Taobao Mini-Program (`my`, `.axml` / `.acss`).
28    Taobao,
29    /// Meituan Mini-Program (`mt`, `.mxml` / `.mxss`).
30    Meituan,
31    /// HarmonyOS Atomic Service (`atomic`, `installationFree: true`, ArkTS `.ets`).
32    HarmonyAtomic,
33}
34
35/// Active rendering context exposed by the host Mini-Program `<canvas>` node.
36#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
37pub enum MiniAppCanvasMode {
38    /// Host 2D canvas context (`canvas.getContext('2d')` + `putImageData`).
39    #[default]
40    Canvas2d,
41    /// Host WebGL 1.0 context (`canvas.getContext('webgl')`).
42    WebGl,
43    /// Host WebGL 2.0 context (`canvas.getContext('webgl2')`).
44    WebGl2,
45}
46
47/// Normalized Mini-Program page and application lifecycle callbacks across all 7 vendors.
48#[derive(Clone, Debug, PartialEq)]
49pub enum MiniAppLifecycleHook {
50    /// `App.onLaunch(options)` cold start with optional query/scene deep link.
51    OnLaunch {
52        /// Optional launch deep-link or query URI.
53        query_uri: Option<String>,
54    },
55    /// `App.onShow` / `Page.onShow` foreground activation.
56    OnShow {
57        /// Optional warm-launch query or share URI.
58        query_uri: Option<String>,
59    },
60    /// `App.onHide` / `Page.onHide` background suspension (0% CPU/GPU freeze).
61    OnHide,
62    /// `Page.onUnload` tearing down the active page surface cleanly.
63    OnUnload,
64    /// `onWindowResize` reporting new logical viewport dimensions and DPR.
65    OnResize {
66        /// Updated logical viewport width in dp.
67        width: u32,
68        /// Updated logical viewport height in dp.
69        height: u32,
70        /// Updated display pixel ratio.
71        pixel_ratio: f32,
72    },
73    /// `onThemeChange` toggling Light/Dark appearance.
74    OnThemeChange(ThemeMode),
75    /// `onMemoryWarning` signaling host memory pressure level (`5`=moderate, `10`/`15`=critical).
76    OnMemoryWarning(i32),
77    /// `onKeyboardHeightChange` reporting soft keyboard height in logical dp.
78    OnKeyboardHeightChange(f32),
79    /// `onNetworkStatusChange` reporting host network status.
80    OnNetworkStatusChange(NetworkStatus),
81}
82
83/// Outbound vendor-agnostic host bridge command emitted by `MiniAppPlatform` to the thin JS/ArkTS shell.
84#[derive(Clone, Debug, PartialEq)]
85pub enum MiniAppHostCommand {
86    /// Updates host navigation bar title (`setNavigationBarTitle`).
87    SetNavigationBarTitle(String),
88    /// Writes text to host clipboard (`setClipboardData`).
89    SetClipboardData(String),
90    /// Persists key-value pair to host sandbox storage (`setStorageSync`).
91    SetStorageSync {
92        /// Storage key.
93        key: String,
94        /// Storage UTF-8 value.
95        value: String,
96    },
97    /// Removes a key from host sandbox storage (`removeStorageSync`).
98    RemoveStorageSync(String),
99    /// Clears all keys from host sandbox storage (`clearStorageSync`).
100    ClearStorageSync,
101    /// Pushes a page onto the host Mini-Program navigation stack (`navigateTo`).
102    NavigateTo(String),
103    /// Pops `delta` pages from the host Mini-Program navigation stack (`navigateBack`).
104    NavigateBack(u32),
105    /// Opens or updates the host soft keyboard / IME (`showKeyboard`).
106    ShowKeyboard {
107        /// Whether keyboard input is active.
108        enabled: bool,
109        /// Target logical input anchor rectangle.
110        rect: Rect,
111    },
112    /// Presents a rendered frame buffer dimensions notification to the host canvas context.
113    PresentCanvas {
114        /// Active canvas context mode (`Canvas2d` / `WebGl` / `WebGl2`).
115        mode: MiniAppCanvasMode,
116        /// Framebuffer physical width in pixels.
117        width: u32,
118        /// Framebuffer physical height in pixels.
119        height: u32,
120    },
121    /// Triggers a short tactile vibration pulse (`vibrateShort`).
122    VibrateShort,
123    /// Displays a lightweight host toast message (`showToast`).
124    ShowToast(String),
125    /// Opens an external URL or web-view link through the host runtime.
126    OpenUrl(String),
127}