euv_core/platform/miniapp/impl.rs
1use super::*;
2
3/// Canonical identifier, global JS namespace, template extension, and tag helpers for `MiniAppVendor`.
4impl MiniAppVendor {
5 /// Returns the canonical lowercase vendor string identifier.
6 ///
7 /// # Arguments
8 ///
9 /// - `&Self` - Mini-program vendor variant.
10 ///
11 /// # Returns
12 ///
13 /// - `&'static str` - Canonical vendor identifier.
14 #[must_use]
15 pub const fn as_str(&self) -> &'static str {
16 match *self {
17 Self::WeChat => MINIAPP_VENDOR_WECHAT,
18 Self::Alipay => MINIAPP_VENDOR_ALIPAY,
19 Self::Douyin => MINIAPP_VENDOR_DOUYIN,
20 Self::Baidu => MINIAPP_VENDOR_BAIDU,
21 Self::Qq => MINIAPP_VENDOR_QQ,
22 Self::Kuaishou => MINIAPP_VENDOR_KUAISHOU,
23 Self::Jd => MINIAPP_VENDOR_JD,
24 Self::Xiaohongshu => MINIAPP_VENDOR_XHS,
25 Self::DingTalk => MINIAPP_VENDOR_DINGTALK,
26 Self::Feishu => MINIAPP_VENDOR_FEISHU,
27 Self::Taobao => MINIAPP_VENDOR_TAOBAO,
28 Self::Meituan => MINIAPP_VENDOR_MEITUAN,
29 Self::HarmonyAtomic => MINIAPP_VENDOR_HARMONY_ATOMIC,
30 }
31 }
32
33 /// Parses a canonical Mini-Program vendor identifier or alias into a `MiniAppVendor`.
34 ///
35 /// # Arguments
36 ///
37 /// - `&str` - Vendor identifier or alias (case-insensitive).
38 ///
39 /// # Returns
40 ///
41 /// - `Option<Self>` - Matching `MiniAppVendor`, if recognized.
42 #[must_use]
43 pub fn from_str_id(name: &str) -> Option<Self> {
44 let lower: String = name.trim().to_ascii_lowercase();
45 match lower.as_str() {
46 MINIAPP_VENDOR_WECHAT | MINIAPP_GLOBAL_WECHAT => Some(Self::WeChat),
47 MINIAPP_VENDOR_ALIPAY | MINIAPP_GLOBAL_ALIPAY => Some(Self::Alipay),
48 MINIAPP_VENDOR_DOUYIN | MINIAPP_GLOBAL_DOUYIN | MINIAPP_ALIAS_BYTEDANCE => {
49 Some(Self::Douyin)
50 }
51 MINIAPP_VENDOR_BAIDU | MINIAPP_GLOBAL_BAIDU => Some(Self::Baidu),
52 MINIAPP_VENDOR_QQ => Some(Self::Qq),
53 MINIAPP_VENDOR_KUAISHOU | MINIAPP_GLOBAL_KUAISHOU => Some(Self::Kuaishou),
54 MINIAPP_VENDOR_JD | MINIAPP_ALIAS_JINGDONG => Some(Self::Jd),
55 MINIAPP_VENDOR_XHS | MINIAPP_ALIAS_XIAOHONGSHU | MINIAPP_ALIAS_RED => {
56 Some(Self::Xiaohongshu)
57 }
58 MINIAPP_VENDOR_DINGTALK | MINIAPP_GLOBAL_DINGTALK => Some(Self::DingTalk),
59 MINIAPP_VENDOR_FEISHU | MINIAPP_ALIAS_LARK => Some(Self::Feishu),
60 MINIAPP_VENDOR_TAOBAO | MINIAPP_ALIAS_TB => Some(Self::Taobao),
61 MINIAPP_VENDOR_MEITUAN | MINIAPP_GLOBAL_MEITUAN => Some(Self::Meituan),
62 MINIAPP_VENDOR_HARMONY_ATOMIC | MINIAPP_ALIAS_ATOMIC => Some(Self::HarmonyAtomic),
63 _ => None,
64 }
65 }
66
67 /// Returns the vendor's global runtime API object name (`wx`, `my`, `tt`, `swan`, `qq`, `ks`, `jd`, `xhs`, `dd`, `mt`, `atomic`).
68 ///
69 /// # Arguments
70 ///
71 /// - `&Self` - Mini-program vendor variant.
72 ///
73 /// # Returns
74 ///
75 /// - `&'static str` - Global JS/ArkTS host namespace identifier.
76 #[must_use]
77 pub const fn global_namespace(&self) -> &'static str {
78 match *self {
79 Self::WeChat => MINIAPP_GLOBAL_WECHAT,
80 Self::Alipay => MINIAPP_GLOBAL_ALIPAY,
81 Self::Douyin => MINIAPP_GLOBAL_DOUYIN,
82 Self::Baidu => MINIAPP_GLOBAL_BAIDU,
83 Self::Qq => MINIAPP_GLOBAL_QQ,
84 Self::Kuaishou => MINIAPP_GLOBAL_KUAISHOU,
85 Self::Jd => MINIAPP_GLOBAL_JD,
86 Self::Xiaohongshu => MINIAPP_GLOBAL_XHS,
87 Self::DingTalk => MINIAPP_GLOBAL_DINGTALK,
88 Self::Feishu => MINIAPP_GLOBAL_FEISHU,
89 Self::Taobao => MINIAPP_GLOBAL_TAOBAO,
90 Self::Meituan => MINIAPP_GLOBAL_MEITUAN,
91 Self::HarmonyAtomic => MINIAPP_GLOBAL_HARMONY_ATOMIC,
92 }
93 }
94
95 /// Returns the host page markup file extension used by the vendor shell generator.
96 ///
97 /// # Arguments
98 ///
99 /// - `&Self` - Mini-program vendor variant.
100 ///
101 /// # Returns
102 ///
103 /// - `&'static str` - Template extension without leading dot.
104 #[must_use]
105 pub const fn template_extension(&self) -> &'static str {
106 match *self {
107 Self::WeChat => MINIAPP_EXT_WXML,
108 Self::Alipay | Self::DingTalk | Self::Taobao => MINIAPP_EXT_AXML,
109 Self::Douyin | Self::Feishu => MINIAPP_EXT_TTML,
110 Self::Baidu => MINIAPP_EXT_SWAN,
111 Self::Qq => MINIAPP_EXT_QML,
112 Self::Kuaishou => MINIAPP_EXT_KSML,
113 Self::Jd => MINIAPP_EXT_JXML,
114 Self::Xiaohongshu => MINIAPP_EXT_XHSML,
115 Self::Meituan => MINIAPP_EXT_MXML,
116 Self::HarmonyAtomic => MINIAPP_EXT_ETS,
117 }
118 }
119
120 /// Returns the host stylesheet file extension used by the vendor shell generator.
121 ///
122 /// # Arguments
123 ///
124 /// - `&Self` - Mini-program vendor variant.
125 ///
126 /// # Returns
127 ///
128 /// - `&'static str` - Stylesheet extension without leading dot.
129 #[must_use]
130 pub const fn style_extension(&self) -> &'static str {
131 match *self {
132 Self::WeChat => MINIAPP_STYLE_WXSS,
133 Self::Alipay | Self::DingTalk | Self::Taobao => MINIAPP_STYLE_ACSS,
134 Self::Douyin | Self::Feishu => MINIAPP_STYLE_TTSS,
135 Self::Baidu | Self::Kuaishou | Self::Xiaohongshu => MINIAPP_STYLE_CSS,
136 Self::Qq => MINIAPP_STYLE_QSS,
137 Self::Jd => MINIAPP_STYLE_JXSS,
138 Self::Meituan => MINIAPP_STYLE_MXSS,
139 Self::HarmonyAtomic => MINIAPP_STYLE_ETS,
140 }
141 }
142
143 /// Returns the vendor IDE project configuration filename.
144 ///
145 /// # Arguments
146 ///
147 /// - `&Self` - Mini-program vendor variant.
148 ///
149 /// # Returns
150 ///
151 /// - `&'static str` - Project config filename.
152 #[must_use]
153 pub const fn config_file_name(&self) -> &'static str {
154 match *self {
155 Self::Alipay | Self::DingTalk | Self::Taobao => MINIAPP_CFG_MINI_PROJECT,
156 Self::Baidu => MINIAPP_CFG_PROJECT_SWAN,
157 Self::HarmonyAtomic => MINIAPP_CFG_MODULE_JSON5,
158 _ => MINIAPP_CFG_PROJECT_CONFIG,
159 }
160 }
161
162 /// Returns `true` when the vendor template language uses Alipay-style `onTouchStart` attributes rather than `bindtouchstart`.
163 ///
164 /// # Arguments
165 ///
166 /// - `&Self` - Mini-program vendor variant.
167 ///
168 /// # Returns
169 ///
170 /// - `bool` - `true` for Alipay, DingTalk, and Taobao Mini-Programs.
171 #[must_use]
172 pub const fn uses_alipay_event_syntax(&self) -> bool {
173 matches!(*self, Self::Alipay | Self::DingTalk | Self::Taobao)
174 }
175
176 /// Returns the host WebAssembly global namespace identifier used to instantiate `.wasm` modules.
177 ///
178 /// # Arguments
179 ///
180 /// - `&Self` - Mini-program vendor variant.
181 ///
182 /// # Returns
183 ///
184 /// - `&'static str` - Host WebAssembly global identifier.
185 #[must_use]
186 pub const fn wasm_global_name(&self) -> &'static str {
187 match *self {
188 Self::WeChat => MINIAPP_WASM_WX,
189 Self::Alipay | Self::DingTalk | Self::Taobao => MINIAPP_WASM_MY,
190 Self::Douyin | Self::Feishu => MINIAPP_WASM_TT,
191 Self::Qq => MINIAPP_WASM_QQ,
192 _ => MINIAPP_WASM_STD,
193 }
194 }
195
196 /// Returns a compact ABI tag byte stored in `RawWindowHandle::MiniAppCanvas`.
197 ///
198 /// # Arguments
199 ///
200 /// - `&Self` - Mini-program vendor variant.
201 ///
202 /// # Returns
203 ///
204 /// - `u8` - Numeric vendor discriminant (`1..=13`).
205 #[must_use]
206 pub const fn tag(&self) -> u8 {
207 match *self {
208 Self::WeChat => 1,
209 Self::Alipay => 2,
210 Self::Douyin => 3,
211 Self::Baidu => 4,
212 Self::Qq => 5,
213 Self::Kuaishou => 6,
214 Self::HarmonyAtomic => 7,
215 Self::Jd => 8,
216 Self::Xiaohongshu => 9,
217 Self::DingTalk => 10,
218 Self::Feishu => 11,
219 Self::Taobao => 12,
220 Self::Meituan => 13,
221 }
222 }
223
224 /// Returns all 13 supported mainstream Mini-Program and Atomic Service vendors.
225 ///
226 /// # Returns
227 ///
228 /// - `[Self; 13]` - Complete array of Mini-Program vendors.
229 #[must_use]
230 pub const fn all_vendors() -> [Self; 13] {
231 [
232 Self::WeChat,
233 Self::Alipay,
234 Self::Douyin,
235 Self::Baidu,
236 Self::Qq,
237 Self::Kuaishou,
238 Self::Jd,
239 Self::Xiaohongshu,
240 Self::DingTalk,
241 Self::Feishu,
242 Self::Taobao,
243 Self::Meituan,
244 Self::HarmonyAtomic,
245 ]
246 }
247}
248
249/// Default `MiniAppSystemInfo` modeling a modern 390x844@3x smartphone Mini-Program container with floating capsule.
250impl Default for MiniAppSystemInfo {
251 /// Creates default WeChat Mini-Program system info metrics.
252 ///
253 /// # Returns
254 ///
255 /// - `Self` - Default `MiniAppSystemInfo`.
256 fn default() -> Self {
257 Self::for_vendor(MiniAppVendor::WeChat)
258 }
259}
260
261/// Preset builders for `MiniAppSystemInfo`.
262impl MiniAppSystemInfo {
263 /// Creates realistic default system metrics including floating capsule button geometry for `vendor`.
264 ///
265 /// # Arguments
266 ///
267 /// - `MiniAppVendor` - Target Mini-Program vendor.
268 ///
269 /// # Returns
270 ///
271 /// - `Self` - Normalized `MiniAppSystemInfo` preset.
272 #[must_use]
273 pub fn for_vendor(vendor: MiniAppVendor) -> Self {
274 let top: f32 = MINIAPP_DEFAULT_STATUS_BAR_DP + 4.0;
275 let right: f32 = (MINIAPP_DEFAULT_WIDTH as f32) - MINIAPP_DEFAULT_CAPSULE_RIGHT_MARGIN;
276 let left: f32 = right - MINIAPP_DEFAULT_CAPSULE_W;
277 let bottom: f32 = top + MINIAPP_DEFAULT_CAPSULE_H;
278 let capsule: MiniAppCapsuleRect = MiniAppCapsuleRect::new(
279 top,
280 right,
281 bottom,
282 left,
283 MINIAPP_DEFAULT_CAPSULE_W,
284 MINIAPP_DEFAULT_CAPSULE_H,
285 );
286 let canvas_mode: MiniAppCanvasMode = match vendor {
287 MiniAppVendor::HarmonyAtomic => MiniAppCanvasMode::WebGl2,
288 _ => MiniAppCanvasMode::Canvas2d,
289 };
290 Self {
291 vendor,
292 window_width: MINIAPP_DEFAULT_WIDTH,
293 window_height: MINIAPP_DEFAULT_HEIGHT,
294 pixel_ratio: MINIAPP_DEFAULT_DPR,
295 status_bar_height: MINIAPP_DEFAULT_STATUS_BAR_DP,
296 safe_area: SafeAreaInsets::new(
297 MINIAPP_DEFAULT_STATUS_BAR_DP,
298 0.0,
299 MINIAPP_DEFAULT_SAFE_BOTTOM_DP,
300 0.0,
301 ),
302 capsule,
303 theme: ThemeMode::Light,
304 language: MINIAPP_DEFAULT_LANGUAGE.to_string(),
305 canvas_mode,
306 }
307 }
308}
309
310/// Default `MiniAppPlatform` targeting WeChat (`MiniAppVendor::WeChat`).
311impl Default for MiniAppPlatform {
312 /// Creates a default WeChat Mini-Program host adapter.
313 ///
314 /// # Returns
315 ///
316 /// - `Self` - Default `MiniAppPlatform`.
317 fn default() -> Self {
318 Self::for_vendor(MiniAppVendor::WeChat)
319 }
320}
321
322/// Vendor constructors, touch/IME/lifecycle translation, and outbound bridge queue helpers for `MiniAppPlatform`.
323impl MiniAppPlatform {
324 /// Creates a `MiniAppPlatform` configured for `vendor` with capsule-cleared safe-area insets.
325 ///
326 /// # Arguments
327 ///
328 /// - `MiniAppVendor` - Target Mini-Program host vendor.
329 ///
330 /// # Returns
331 ///
332 /// - `Self` - Configured Mini-Program backend.
333 #[must_use]
334 pub fn for_vendor(vendor: MiniAppVendor) -> Self {
335 Self::from_system_info(MiniAppSystemInfo::for_vendor(vendor))
336 }
337
338 /// Creates a `MiniAppPlatform` from concrete host `MiniAppSystemInfo`.
339 ///
340 /// # Arguments
341 ///
342 /// - `MiniAppSystemInfo` - Runtime system info reported by the host shell.
343 ///
344 /// # Returns
345 ///
346 /// - `Self` - Configured Mini-Program backend.
347 #[must_use]
348 pub fn from_system_info(system_info: MiniAppSystemInfo) -> Self {
349 let safe_area: SafeAreaInsets = resolve_miniapp_safe_area(&system_info, true);
350 Self {
351 system_info,
352 resolved_safe_area: safe_area,
353 next_id: 1,
354 primary_window: None,
355 windows: HashMap::new(),
356 touch_tracker: TouchPointerTracker::default(),
357 pending_events: Vec::new(),
358 outbound_commands: Vec::new(),
359 storage: HashMap::new(),
360 route_stack: vec![MINIAPP_DEFAULT_ROUTE.to_string()],
361 clipboard: None,
362 pump_paused: false,
363 capture_last_frame: false,
364 refresh_rate_hz: HIGH_REFRESH_DEFAULT_HZ,
365 }
366 }
367
368 /// Updates the Mini-Program host display refresh rate without imposing any artificial upper ceiling.
369 ///
370 /// # Arguments
371 ///
372 /// - `&Self` - Mutable Mini-program platform.
373 /// - `f32` - Reported host hardware display refresh rate in Hertz.
374 pub fn update_refresh_rate_hz(&mut self, hz: f32) {
375 if !hz.is_finite() || hz < MIN_REFRESH_RATE_HZ {
376 return;
377 }
378 self.set_refresh_rate_hz(hz);
379 let rounded_hz: u32 = hz.round() as u32;
380 for rec in self.get_mut_windows().values_mut() {
381 rec.get_mut_state()
382 .get_mut_display()
383 .set_refresh_rate_hz(rounded_hz);
384 }
385 }
386
387 /// Enables or disables retaining a cloned snapshot of the last presented framebuffer.
388 ///
389 /// # Arguments
390 ///
391 /// - `Self` - Mini-program platform value.
392 /// - `bool` - `true` to capture snapshots on each present; `false` for zero-clone production mode.
393 ///
394 /// # Returns
395 ///
396 /// - `Self` - Updated Mini-Program platform backend.
397 #[must_use]
398 pub fn with_capture_last_frame(mut self, enabled: bool) -> Self {
399 self.set_capture_last_frame(enabled);
400 self
401 }
402
403 /// Returns the last presented framebuffer snapshot for `id` when `capture_last_frame` is enabled.
404 ///
405 /// # Arguments
406 ///
407 /// - `&Self` - Mini-program platform reference.
408 /// - `WindowId` - Canvas window identifier.
409 ///
410 /// # Returns
411 ///
412 /// - `Option<&Framebuffer>` - Cloned framebuffer reference when capture is enabled and `id` exists.
413 #[must_use]
414 pub fn last_framebuffer(&self, id: WindowId) -> Option<&Framebuffer> {
415 if !self.get_capture_last_frame() {
416 return None;
417 }
418 self.get_windows()
419 .get(&id)
420 .map(MiniAppWindowRecord::get_last_frame)
421 }
422
423 /// Returns the primary Mini-Program canvas window identifier, if created.
424 ///
425 /// # Arguments
426 ///
427 /// - `&Self` - Mini-program platform reference.
428 ///
429 /// # Returns
430 ///
431 /// - `Option<WindowId>` - Primary canvas window handle.
432 #[must_use]
433 pub fn primary_window_id(&self) -> Option<WindowId> {
434 let Self { primary_window, .. } = self;
435 *primary_window
436 }
437
438 /// Drains all queued outbound host bridge commands for execution by the thin JS/ArkTS shell.
439 ///
440 /// # Arguments
441 ///
442 /// - `&Self` - Mutable Mini-program platform.
443 ///
444 /// # Returns
445 ///
446 /// - `Vec<MiniAppHostCommand>` - Ordered host commands.
447 pub fn drain_host_commands(&mut self) -> Vec<MiniAppHostCommand> {
448 take(self.get_mut_outbound_commands())
449 }
450
451 /// Updates host `MiniAppSystemInfo` (e.g. after orientation change or capsule query) and emits `SafeAreaChanged`.
452 ///
453 /// # Arguments
454 ///
455 /// - `&Self` - Mutable Mini-program platform.
456 /// - `MiniAppSystemInfo` - Updated host system info.
457 pub fn update_system_info(&mut self, info: MiniAppSystemInfo) {
458 let wid: WindowId = self.primary_window_id().unwrap_or(WindowId::new(1));
459 let safe: SafeAreaInsets = resolve_miniapp_safe_area(&info, true);
460 let width_val: u32 = info.get_window_width().max(1);
461 let height_val: u32 = info.get_window_height().max(1);
462 let dpr: f32 = clamp_viewport_scale(info.get_pixel_ratio());
463 self.set_system_info(info);
464 self.set_resolved_safe_area(safe);
465 for rec in self.get_mut_windows().values_mut() {
466 rec.get_mut_state()
467 .set_logical_width(width_val as f32)
468 .set_logical_height(height_val as f32)
469 .set_physical_width(((width_val as f32) * dpr).round() as u32)
470 .set_physical_height(((height_val as f32) * dpr).round() as u32)
471 .set_scale_factor(dpr)
472 .set_safe_area(safe);
473 }
474 self.get_mut_pending_events()
475 .push(WindowEvent::SafeAreaChanged(wid, safe));
476 self.get_mut_pending_events()
477 .push(WindowEvent::System(SystemEvent::SafeAreaChanged(safe)));
478 }
479
480 /// Translates Mini-Program `<canvas>` touch callbacks (`touchstart`/`touchmove`/`touchend`/`touchcancel`) into EUV pointer events.
481 ///
482 /// # Arguments
483 ///
484 /// - `&Self` - Mutable Mini-program platform.
485 /// - `i32` - Normalized action (`ANDROID_ACTION_DOWN` / `MOVE` / `UP` / `CANCEL`).
486 /// - `&[(i32, f32, f32)]` - Active touch contact tuples `(identifier, logical_x, logical_y)`.
487 ///
488 /// # Returns
489 ///
490 /// - `Vec<WindowEvent>` - Normalized pointer events also enqueued for `poll_events()`.
491 pub fn handle_touch(&mut self, action: i32, touches: &[(i32, f32, f32)]) -> Vec<WindowEvent> {
492 let wid: WindowId = self.primary_window_id().unwrap_or(WindowId::new(1));
493 let events: Vec<WindowEvent> = self
494 .get_mut_touch_tracker()
495 .handle_android_motion(wid, action, 0, touches);
496 self.get_mut_pending_events().extend(events.clone());
497 events
498 }
499
500 /// Dispatches UTF-8 text input received from a hidden Mini-Program `<input>` or `onKeyboardInput` bridge.
501 ///
502 /// # Arguments
503 ///
504 /// - `&Self` - Mutable Mini-program platform.
505 /// - `String` - Committed UTF-8 text.
506 /// - `bool` - When `true`, also emits `KeyCode::Enter` confirmation.
507 pub fn handle_ime_input(&mut self, text: String, confirmed: bool) {
508 let wid: WindowId = self.primary_window_id().unwrap_or(WindowId::new(1));
509 if !text.is_empty() {
510 self.get_mut_pending_events()
511 .push(WindowEvent::Ime(wid, ImeEvent::Commit(text.clone())));
512 self.get_mut_pending_events()
513 .push(WindowEvent::TextInput(wid, text));
514 }
515 if confirmed {
516 self.get_mut_pending_events().push(WindowEvent::KeyDown(
517 wid,
518 KeyEvent::new(KeyCode::Enter, Modifiers::default(), false),
519 ));
520 }
521 }
522
523 /// Enqueues a host accelerometer/gyroscope `DeviceMotionSample` received from a Mini-Program sensor listener.
524 ///
525 /// # Arguments
526 ///
527 /// - `&Self` - Mutable Mini-program platform.
528 /// - `DeviceMotionSample` - 6-DOF device motion sample.
529 pub fn handle_device_motion(&mut self, sample: DeviceMotionSample) {
530 self.get_mut_pending_events()
531 .push(WindowEvent::System(SystemEvent::DeviceMotion(sample)));
532 }
533
534 /// Queues a host toast notification command (`showToast`).
535 ///
536 /// # Arguments
537 ///
538 /// - `&Self` - Mutable Mini-program platform.
539 /// - `&str` - Short message text.
540 pub fn show_toast(&mut self, message: &str) {
541 self.get_mut_outbound_commands()
542 .push(MiniAppHostCommand::ShowToast(message.to_string()));
543 }
544
545 /// Queues an external URL open request for the host Mini-Program bridge.
546 ///
547 /// # Arguments
548 ///
549 /// - `&Self` - Mutable Mini-program platform.
550 /// - `&str` - Target URL string.
551 pub fn open_url(&mut self, url: &str) {
552 self.get_mut_outbound_commands()
553 .push(MiniAppHostCommand::OpenUrl(url.to_string()));
554 }
555
556 /// Translates Mini-Program `onLaunch` / `onShow` / `onHide` / `onUnload` and system hooks into canonical EUV `SystemEvent`s.
557 ///
558 /// # Arguments
559 ///
560 /// - `&Self` - Mutable Mini-program platform.
561 /// - `MiniAppLifecycleHook` - Vendor-neutral lifecycle hook payload.
562 ///
563 /// # Returns
564 ///
565 /// - `Vec<WindowEvent>` - Normalized events also enqueued for `poll_events()`.
566 pub fn handle_lifecycle_hook(&mut self, hook: MiniAppLifecycleHook) -> Vec<WindowEvent> {
567 let wid: WindowId = self.primary_window_id().unwrap_or(WindowId::new(1));
568 let mut emitted: Vec<WindowEvent> = Vec::new();
569 match hook {
570 MiniAppLifecycleHook::OnLaunch { query_uri } => {
571 self.set_pump_paused(false);
572 if let Some(uri) = query_uri
573 && !uri.is_empty()
574 {
575 emitted.push(WindowEvent::System(SystemEvent::DeepLink(uri)));
576 }
577 }
578 MiniAppLifecycleHook::OnShow { query_uri } => {
579 self.set_pump_paused(false);
580 emitted.push(WindowEvent::System(SystemEvent::Appear));
581 emitted.push(WindowEvent::System(SystemEvent::Foreground));
582 if let Some(uri) = query_uri
583 && !uri.is_empty()
584 {
585 emitted.push(WindowEvent::System(SystemEvent::DeepLink(uri)));
586 }
587 }
588 MiniAppLifecycleHook::OnHide => {
589 self.set_pump_paused(true);
590 let cancels: Vec<WindowEvent> =
591 self.get_mut_touch_tracker().cancel_all_on_focus_loss(wid);
592 emitted.extend(cancels);
593 emitted.push(WindowEvent::System(SystemEvent::Disappear));
594 emitted.push(WindowEvent::System(SystemEvent::Background));
595 }
596 MiniAppLifecycleHook::OnUnload => {
597 self.set_pump_paused(true);
598 let cancels: Vec<WindowEvent> =
599 self.get_mut_touch_tracker().cancel_all_on_focus_loss(wid);
600 emitted.extend(cancels);
601 emitted.push(WindowEvent::System(SystemEvent::Terminate));
602 }
603 MiniAppLifecycleHook::OnResize {
604 width,
605 height,
606 pixel_ratio,
607 } => {
608 let width_val: u32 = width.max(1);
609 let height_val: u32 = height.max(1);
610 let dpr: f32 = clamp_viewport_scale(pixel_ratio);
611 self.get_mut_system_info()
612 .set_window_width(width_val)
613 .set_window_height(height_val)
614 .set_pixel_ratio(dpr);
615 for rec in self.get_mut_windows().values_mut() {
616 rec.get_mut_state()
617 .set_logical_width(width_val as f32)
618 .set_logical_height(height_val as f32)
619 .set_physical_width(((width_val as f32) * dpr).round() as u32)
620 .set_physical_height(((height_val as f32) * dpr).round() as u32)
621 .set_scale_factor(dpr);
622 }
623 emitted.push(WindowEvent::Resized(wid, width_val, height_val, dpr));
624 emitted.push(WindowEvent::System(SystemEvent::Resize {
625 width: width_val as f32,
626 height: height_val as f32,
627 scale_factor: dpr,
628 }));
629 }
630 MiniAppLifecycleHook::OnThemeChange(theme) => {
631 self.get_mut_system_info().set_theme(theme);
632 emitted.push(WindowEvent::ThemeChanged(wid, theme));
633 emitted.push(WindowEvent::System(SystemEvent::ThemeChanged(theme)));
634 }
635 MiniAppLifecycleHook::OnMemoryWarning(level) => {
636 let pressure: MemoryPressure = miniapp_memory_level_to_pressure(level);
637 emitted.push(WindowEvent::System(SystemEvent::MemoryWarning(pressure)));
638 }
639 MiniAppLifecycleHook::OnKeyboardHeightChange(height) => {
640 let span_height: f32 = if height.is_finite() {
641 height.max(0.0)
642 } else {
643 0.0
644 };
645 emitted.push(WindowEvent::System(
646 SystemEvent::KeyboardVisibilityChanged {
647 visible: span_height > 0.0,
648 height: span_height,
649 },
650 ));
651 }
652 MiniAppLifecycleHook::OnNetworkStatusChange(status) => {
653 emitted.push(WindowEvent::System(SystemEvent::NetworkStatusChanged(
654 status,
655 )));
656 }
657 }
658 self.get_mut_pending_events().extend(emitted.clone());
659 emitted
660 }
661}
662
663/// `WindowController` implementation for `MiniAppPlatform`.
664impl WindowController for MiniAppPlatform {
665 /// Applies a `WindowCommand` and emits corresponding `MiniAppHostCommand`s when relevant.
666 ///
667 /// # Arguments
668 ///
669 /// - `&Self` - Mutable Mini-program platform.
670 /// - `WindowCommand` - Command to apply.
671 ///
672 /// # Returns
673 ///
674 /// - `Result<(), PlatformError>` - Execution status.
675 fn apply_command(&mut self, command: WindowCommand) -> Result<(), PlatformError> {
676 match command {
677 WindowCommand::SetTitle(id, title) => {
678 let rec: &mut MiniAppWindowRecord = self
679 .get_mut_windows()
680 .get_mut(&id)
681 .ok_or(PlatformError::WindowNotFound(id.get_value()))?;
682 rec.get_mut_config().set_title(title.clone());
683 self.get_mut_outbound_commands()
684 .push(MiniAppHostCommand::SetNavigationBarTitle(title));
685 Ok(())
686 }
687 WindowCommand::SetIme(id, enabled, rect) => {
688 if !self.get_windows().contains_key(&id) {
689 return Err(PlatformError::WindowNotFound(id.get_value()));
690 }
691 self.get_mut_outbound_commands()
692 .push(MiniAppHostCommand::ShowKeyboard { enabled, rect });
693 Ok(())
694 }
695 WindowCommand::SetRenderMode(id, mode) => {
696 let rec: &mut MiniAppWindowRecord = self
697 .get_mut_windows()
698 .get_mut(&id)
699 .ok_or(PlatformError::WindowNotFound(id.get_value()))?;
700 rec.get_mut_config().get_mut_render().set_mode(mode);
701 let next_canvas: MiniAppCanvasMode = match mode {
702 RenderMode::Software => MiniAppCanvasMode::Canvas2d,
703 RenderMode::Hardware | RenderMode::Hybrid | RenderMode::Auto => {
704 MiniAppCanvasMode::WebGl2
705 }
706 };
707 rec.set_canvas_mode(next_canvas);
708 Ok(())
709 }
710 WindowCommand::RequestRedraw(id) => {
711 if !self.get_windows().contains_key(&id) {
712 return Err(PlatformError::WindowNotFound(id.get_value()));
713 }
714 self.get_mut_pending_events()
715 .push(WindowEvent::RedrawRequested(id));
716 Ok(())
717 }
718 WindowCommand::Close(id) => {
719 if self.get_mut_windows().remove(&id).is_none() {
720 return Err(PlatformError::WindowNotFound(id.get_value()));
721 }
722 Ok(())
723 }
724 WindowCommand::SetSize(id, _, _)
725 | WindowCommand::SetPosition(id, _, _)
726 | WindowCommand::SetResizable(id, _)
727 | WindowCommand::SetDecorations(id, _)
728 | WindowCommand::SetAlwaysOnTop(id, _)
729 | WindowCommand::SetFullscreen(id, _)
730 | WindowCommand::SetVisible(id, _)
731 | WindowCommand::SetCursor(id, _)
732 | WindowCommand::SetStatusBarStyle(id, _) => {
733 if !self.get_windows().contains_key(&id) {
734 return Err(PlatformError::WindowNotFound(id.get_value()));
735 }
736 Ok(())
737 }
738 }
739 }
740}
741
742/// `PlatformBackend` implementation for `MiniAppPlatform`.
743impl PlatformBackend for MiniAppPlatform {
744 /// Returns `PlatformKind::MiniApp`.
745 ///
746 /// # Arguments
747 ///
748 /// - `&Self` - Mini-program platform reference.
749 ///
750 /// # Returns
751 ///
752 /// - `PlatformKind` - `PlatformKind::MiniApp`.
753 fn kind(&self) -> PlatformKind {
754 PlatformKind::MiniApp
755 }
756
757 /// Returns Mini-Program container capability flags (`capsule_chrome = true`, `local_storage = true`).
758 ///
759 /// # Arguments
760 ///
761 /// - `&Self` - Mini-program platform reference.
762 ///
763 /// # Returns
764 ///
765 /// - `PlatformCapabilities` - Mini-Program capabilities.
766 fn capabilities(&self) -> PlatformCapabilities {
767 PlatformCapabilities::for_platform(PlatformKind::MiniApp)
768 }
769
770 /// Creates a canvas window sized to the host Mini-Program viewport with capsule-cleared safe-area insets.
771 ///
772 /// # Arguments
773 ///
774 /// - `&Self` - Mutable Mini-program platform.
775 /// - `&WindowConfig` - Declarative window config.
776 ///
777 /// # Returns
778 ///
779 /// - `Result<WindowState, PlatformError>` - Created canvas window state.
780 fn create_window(&mut self, config: &WindowConfig) -> Result<WindowState, PlatformError> {
781 let id: WindowId = WindowId::new(self.get_next_id());
782 self.set_next_id(self.get_next_id().wrapping_add(1));
783 let mut mini_cfg: WindowConfig = config.clone();
784 mini_cfg.set_size(
785 self.get_system_info().get_window_width(),
786 self.get_system_info().get_window_height(),
787 );
788 let dpr: f32 = self.get_system_info().get_pixel_ratio();
789 let mut state: WindowState = WindowState::from_config(id, &mini_cfg, dpr);
790 state.set_safe_area(self.get_resolved_safe_area());
791 state.set_system_theme(self.get_system_info().get_theme());
792 state
793 .get_mut_display()
794 .set_refresh_rate_hz(self.get_refresh_rate_hz().round() as u32);
795 let record: MiniAppWindowRecord = MiniAppWindowRecord {
796 config: mini_cfg,
797 state,
798 canvas_id: id.get_value() as u32,
799 canvas_mode: self.get_system_info().get_canvas_mode(),
800 last_frame: Framebuffer::allocate(1, 1),
801 present_count: 0,
802 };
803 self.get_mut_windows().insert(id, record);
804 if self.primary_window_id().is_none() {
805 self.set_primary_window(Some(id));
806 }
807 Ok(state)
808 }
809
810 /// Queries live `WindowState` for `id`.
811 ///
812 /// # Arguments
813 ///
814 /// - `&Self` - Mini-program platform reference.
815 /// - `WindowId` - Window identifier.
816 ///
817 /// # Returns
818 ///
819 /// - `Option<WindowState>` - Live window state if open.
820 fn window_state(&self, id: WindowId) -> Option<WindowState> {
821 self.get_windows()
822 .get(&id)
823 .map(MiniAppWindowRecord::get_state)
824 }
825
826 /// Returns `RawWindowHandle::MiniAppCanvas` tagged with the active `MiniAppVendor`.
827 ///
828 /// # Arguments
829 ///
830 /// - `&Self` - Mini-program platform reference.
831 /// - `WindowId` - Window identifier.
832 ///
833 /// # Returns
834 ///
835 /// - `RawWindowHandle` - Mini-Program canvas handle.
836 fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle {
837 match self.get_windows().get(&id) {
838 Some(rec) => RawWindowHandle::MiniAppCanvas {
839 canvas_id: rec.get_canvas_id(),
840 vendor_tag: self.get_system_info().get_vendor().tag(),
841 },
842 None => RawWindowHandle::Headless,
843 }
844 }
845
846 /// Drains queued Mini-Program touch, IME, resize, and lifecycle events.
847 ///
848 /// # Arguments
849 ///
850 /// - `&Self` - Mutable Mini-program platform.
851 ///
852 /// # Returns
853 ///
854 /// - `Vec<WindowEvent>` - Pending events.
855 fn poll_events(&mut self) -> Vec<WindowEvent> {
856 take(self.get_mut_pending_events())
857 }
858
859 /// Pauses or resumes the Mini-Program canvas frame pump flag.
860 ///
861 /// # Arguments
862 ///
863 /// - `&Self` - Mutable Mini-program platform.
864 /// - `bool` - `true` when hidden.
865 fn set_frame_pump_paused(&mut self, paused: bool) {
866 self.set_pump_paused(paused);
867 }
868
869 /// Returns whether the Mini-Program frame pump is paused.
870 ///
871 /// # Arguments
872 ///
873 /// - `&Self` - Mini-program platform reference.
874 ///
875 /// # Returns
876 ///
877 /// - `bool` - Pause state.
878 fn is_frame_pump_paused(&self) -> bool {
879 self.get_pump_paused()
880 }
881
882 /// Stores `framebuffer` and queues a `MiniAppHostCommand::PresentCanvas` command for the host canvas context.
883 ///
884 /// # Arguments
885 ///
886 /// - `&Self` - Mutable Mini-program platform.
887 /// - `WindowId` - Window identifier.
888 /// - `&Framebuffer` - Rendered RGBA8 framebuffer.
889 ///
890 /// # Returns
891 ///
892 /// - `Result<(), PlatformError>` - Presentation status.
893 fn present_framebuffer(
894 &mut self,
895 id: WindowId,
896 framebuffer: &Framebuffer,
897 ) -> Result<(), PlatformError> {
898 let capture: bool = self.get_capture_last_frame();
899 let mode: MiniAppCanvasMode = {
900 let rec: &mut MiniAppWindowRecord = self
901 .get_mut_windows()
902 .get_mut(&id)
903 .ok_or(PlatformError::WindowNotFound(id.get_value()))?;
904 if capture {
905 rec.set_last_frame(framebuffer.clone());
906 }
907 rec.set_present_count(rec.get_present_count().wrapping_add(1));
908 rec.get_canvas_mode()
909 };
910 self.get_mut_outbound_commands()
911 .push(MiniAppHostCommand::PresentCanvas {
912 mode,
913 width: framebuffer.get_width(),
914 height: framebuffer.get_height(),
915 });
916 Ok(())
917 }
918
919 /// Reads cached clipboard text.
920 ///
921 /// # Arguments
922 ///
923 /// - `&Self` - Mini-program platform reference.
924 ///
925 /// # Returns
926 ///
927 /// - `Option<String>` - Cached clipboard string.
928 fn read_clipboard(&self) -> Option<String> {
929 let Self { clipboard, .. } = self;
930 clipboard.clone()
931 }
932
933 /// Writes `text` to the clipboard cache and queues `MiniAppHostCommand::SetClipboardData`.
934 ///
935 /// # Arguments
936 ///
937 /// - `&Self` - Mutable Mini-program platform.
938 /// - `&str` - Clipboard text.
939 ///
940 /// # Returns
941 ///
942 /// - `Result<(), PlatformError>` - Write status.
943 fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError> {
944 self.set_clipboard(Some(text.to_string()));
945 self.get_mut_outbound_commands()
946 .push(MiniAppHostCommand::SetClipboardData(text.to_string()));
947 Ok(())
948 }
949
950 /// Returns the active Mini-Program host theme mode.
951 ///
952 /// # Arguments
953 ///
954 /// - `&Self` - Mini-program platform reference.
955 ///
956 /// # Returns
957 ///
958 /// - `ThemeMode` - Active theme mode.
959 fn system_theme(&self) -> ThemeMode {
960 self.get_system_info().get_theme()
961 }
962
963 /// Returns the uncapped Mini-Program host display refresh rate in Hertz.
964 ///
965 /// # Arguments
966 ///
967 /// - `&Self` - Mini-program platform reference.
968 ///
969 /// # Returns
970 ///
971 /// - `f32` - Active host display refresh rate in Hertz.
972 fn display_refresh_rate_hz(&self) -> f32 {
973 self.get_refresh_rate_hz()
974 }
975}
976
977/// `PlatformStorage` implementation for `MiniAppPlatform`.
978impl PlatformStorage for MiniAppPlatform {
979 /// Reads `key` from mirrored Mini-Program sandbox storage.
980 ///
981 /// # Arguments
982 ///
983 /// - `&Self` - Mini-program platform reference.
984 /// - `&str` - Storage key.
985 ///
986 /// # Returns
987 ///
988 /// - `Option<String>` - Stored value, if present.
989 fn storage_get(&self, key: &str) -> Option<String> {
990 self.get_storage().get(key).cloned()
991 }
992
993 /// Writes `(key, value)` to mirrored storage and emits `MiniAppHostCommand::SetStorageSync`.
994 ///
995 /// # Arguments
996 ///
997 /// - `&Self` - Mutable Mini-program platform.
998 /// - `&str` - Storage key.
999 /// - `&str` - Value to store.
1000 ///
1001 /// # Returns
1002 ///
1003 /// - `Result<(), PlatformError>` - Storage status.
1004 fn storage_set(&mut self, key: &str, value: &str) -> Result<(), PlatformError> {
1005 let _: Option<String> = self
1006 .get_mut_storage()
1007 .insert(key.to_string(), value.to_string());
1008 self.get_mut_outbound_commands()
1009 .push(MiniAppHostCommand::SetStorageSync {
1010 key: key.to_string(),
1011 value: value.to_string(),
1012 });
1013 Ok(())
1014 }
1015
1016 /// Removes `key` from mirrored storage and emits `MiniAppHostCommand::RemoveStorageSync`.
1017 ///
1018 /// # Arguments
1019 ///
1020 /// - `&Self` - Mutable Mini-program platform.
1021 /// - `&str` - Storage key.
1022 ///
1023 /// # Returns
1024 ///
1025 /// - `Result<(), PlatformError>` - Removal status.
1026 fn storage_remove(&mut self, key: &str) -> Result<(), PlatformError> {
1027 let _: Option<String> = self.get_mut_storage().remove(key);
1028 self.get_mut_outbound_commands()
1029 .push(MiniAppHostCommand::RemoveStorageSync(key.to_string()));
1030 Ok(())
1031 }
1032
1033 /// Clears mirrored storage and emits `MiniAppHostCommand::ClearStorageSync`.
1034 ///
1035 /// # Arguments
1036 ///
1037 /// - `&Self` - Mutable Mini-program platform.
1038 ///
1039 /// # Returns
1040 ///
1041 /// - `Result<(), PlatformError>` - Clear status.
1042 fn storage_clear(&mut self) -> Result<(), PlatformError> {
1043 self.get_mut_storage().clear();
1044 self.get_mut_outbound_commands()
1045 .push(MiniAppHostCommand::ClearStorageSync);
1046 Ok(())
1047 }
1048}
1049
1050/// `PlatformNavigation` implementation for `MiniAppPlatform`.
1051impl PlatformNavigation for MiniAppPlatform {
1052 /// Pushes `route` onto the Mini-Program navigation stack and emits `MiniAppHostCommand::NavigateTo`.
1053 ///
1054 /// # Arguments
1055 ///
1056 /// - `&Self` - Mutable Mini-program platform.
1057 /// - `&str` - Target page route.
1058 ///
1059 /// # Returns
1060 ///
1061 /// - `Result<(), PlatformError>` - Navigation status.
1062 fn navigate_to(&mut self, route: &str) -> Result<(), PlatformError> {
1063 if !route.is_empty() {
1064 self.get_mut_route_stack().push(route.to_string());
1065 self.get_mut_outbound_commands()
1066 .push(MiniAppHostCommand::NavigateTo(route.to_string()));
1067 }
1068 Ok(())
1069 }
1070
1071 /// Pops `delta` entries from the navigation stack and emits `MiniAppHostCommand::NavigateBack`.
1072 ///
1073 /// # Arguments
1074 ///
1075 /// - `&Self` - Mutable Mini-program platform.
1076 /// - `u32` - Pages to pop.
1077 ///
1078 /// # Returns
1079 ///
1080 /// - `Result<(), PlatformError>` - Navigation status.
1081 fn navigate_back(&mut self, delta: u32) -> Result<(), PlatformError> {
1082 let steps: u32 = delta.max(1);
1083 for _ in 0..steps {
1084 if self.get_route_stack().len() > 1 {
1085 let _: Option<String> = self.get_mut_route_stack().pop();
1086 }
1087 }
1088 self.get_mut_outbound_commands()
1089 .push(MiniAppHostCommand::NavigateBack(steps));
1090 Ok(())
1091 }
1092
1093 /// Returns the currently active Mini-Program route path.
1094 ///
1095 /// # Arguments
1096 ///
1097 /// - `&Self` - Mini-program platform reference.
1098 ///
1099 /// # Returns
1100 ///
1101 /// - `&str` - Active route path.
1102 fn current_route(&self) -> &str {
1103 self.get_route_stack()
1104 .last()
1105 .map(String::as_str)
1106 .unwrap_or(MINIAPP_DEFAULT_ROUTE)
1107 }
1108}
1109
1110/// `PlatformLifecycleBridge` implementation for `MiniAppPlatform`.
1111impl PlatformLifecycleBridge for MiniAppPlatform {
1112 /// Maps Mini-Program `onHide` into unified freeze semantics.
1113 ///
1114 /// # Arguments
1115 ///
1116 /// - `&Self` - Mutable Mini-program platform.
1117 ///
1118 /// # Returns
1119 ///
1120 /// - `Vec<WindowEvent>` - Normalized freeze events.
1121 fn freeze_surface(&mut self) -> Vec<WindowEvent> {
1122 self.handle_lifecycle_hook(MiniAppLifecycleHook::OnHide)
1123 }
1124
1125 /// Maps Mini-Program `onShow` into unified resume semantics.
1126 ///
1127 /// # Arguments
1128 ///
1129 /// - `&Self` - Mutable Mini-program platform.
1130 ///
1131 /// # Returns
1132 ///
1133 /// - `Vec<WindowEvent>` - Normalized resume events.
1134 fn resume_surface(&mut self) -> Vec<WindowEvent> {
1135 self.handle_lifecycle_hook(MiniAppLifecycleHook::OnShow { query_uri: None })
1136 }
1137
1138 /// Maps Mini-Program `onUnload` into unified destroy semantics.
1139 ///
1140 /// # Arguments
1141 ///
1142 /// - `&Self` - Mutable Mini-program platform.
1143 ///
1144 /// # Returns
1145 ///
1146 /// - `Vec<WindowEvent>` - Normalized destroy events.
1147 fn destroy_surface(&mut self) -> Vec<WindowEvent> {
1148 self.handle_lifecycle_hook(MiniAppLifecycleHook::OnUnload)
1149 }
1150}
1151
1152/// `PlatformHostAdapter` implementation for `MiniAppPlatform`.
1153impl PlatformHostAdapter for MiniAppPlatform {
1154 /// Returns `DeviceFormFactor::MiniProgram`.
1155 ///
1156 /// # Arguments
1157 ///
1158 /// - `&Self` - Mini-program platform reference.
1159 ///
1160 /// # Returns
1161 ///
1162 /// - `DeviceFormFactor` - `DeviceFormFactor::MiniProgram`.
1163 fn device_form_factor(&self) -> DeviceFormFactor {
1164 DeviceFormFactor::MiniProgram
1165 }
1166
1167 /// Returns the active Mini-Program vendor identifier (`"wechat"`, `"alipay"`, `"douyin"`, etc.).
1168 ///
1169 /// # Arguments
1170 ///
1171 /// - `&Self` - Mini-program platform reference.
1172 ///
1173 /// # Returns
1174 ///
1175 /// - `&'static str` - Canonical vendor identifier.
1176 fn host_vendor_name(&self) -> &'static str {
1177 self.get_system_info().get_vendor().as_str()
1178 }
1179}
1180
1181/// Unified host-channel capability and visual-equivalence queries for `MiniAppPlatform`.
1182impl MiniAppPlatform {
1183 /// Returns the truthful `HostChannelCapabilities` declared by this Mini-Program host.
1184 ///
1185 /// A `Canvas2d`-only host locks single-channel mode (`supported_channels.len() == 1`) and NEVER probes WebGL;
1186 /// off-device/simulated profiles ALWAYS set `simulated_profile = true` and `direct_gpu_verified_on_device = false`.
1187 ///
1188 /// # Returns
1189 ///
1190 /// - `HostChannelCapabilities` - Declared MiniApp channels, visual gate, and honesty flags.
1191 #[must_use]
1192 pub fn host_channel_capabilities(&self) -> HostChannelCapabilities {
1193 let simulated: bool = !cfg!(target_arch = "wasm32");
1194 let (channels, preferred): (Vec<HostRenderChannel>, HostRenderChannel) =
1195 match self.get_system_info().get_canvas_mode() {
1196 MiniAppCanvasMode::Canvas2d => (
1197 vec![HostRenderChannel::Canvas2d],
1198 HostRenderChannel::Canvas2d,
1199 ),
1200 MiniAppCanvasMode::WebGl => (
1201 vec![HostRenderChannel::WebGl, HostRenderChannel::Canvas2d],
1202 HostRenderChannel::WebGl,
1203 ),
1204 MiniAppCanvasMode::WebGl2 => (
1205 vec![HostRenderChannel::WebGl2, HostRenderChannel::Canvas2d],
1206 HostRenderChannel::WebGl2,
1207 ),
1208 };
1209 HostChannelCapabilities::from_host_declaration(
1210 self.host_vendor_name(),
1211 channels,
1212 preferred,
1213 HostVisualEquivalenceGate::default(),
1214 simulated,
1215 false,
1216 )
1217 }
1218
1219 /// Resolves the MiniApp rendering channel under unified visual-equivalence and single-channel non-probing rules.
1220 ///
1221 /// # Arguments
1222 ///
1223 /// - `Option<HostRenderChannel>` - Optional requested channel.
1224 ///
1225 /// # Returns
1226 ///
1227 /// - `HostChannelSelection` - Resolved channel decision.
1228 #[must_use]
1229 pub fn select_render_channel(
1230 &self,
1231 requested: Option<HostRenderChannel>,
1232 ) -> HostChannelSelection {
1233 self.host_channel_capabilities().select_channel(requested)
1234 }
1235}