Skip to main content

lingxia_platform/
lib.rs

1//! LingXia Platform
2//!
3//! This crate provides the platform-specific implementation for LingXia.
4
5use std::io::Read;
6
7/// Asset file entry with reader for streaming content
8pub struct AssetFileEntry<'a> {
9    pub path: String,
10    pub reader: Box<dyn Read + 'a>,
11}
12
13/// Device information
14#[derive(Debug, Clone)]
15pub struct DeviceInfo {
16    pub brand: String,
17    pub model: String,
18    pub market_name: String,
19    pub os_name: String,
20    pub os_version: String,
21}
22
23/// Screen information reported in logical pixels (dp/pt) and scale factor
24#[derive(Debug, Clone, serde::Serialize)]
25pub struct ScreenInfo {
26    pub width: f64,
27    pub height: f64,
28    pub scale: f64,
29}
30
31pub(crate) mod rt;
32pub mod traits;
33
34/// Independent realtime capture contract. Not an `AppRuntime` supertrait.
35#[cfg(feature = "capture-contract")]
36pub mod capture;
37
38#[cfg(target_os = "android")]
39mod android;
40
41#[cfg(any(target_os = "ios", target_os = "macos"))]
42mod apple;
43
44#[cfg(target_env = "ohos")]
45pub mod harmony;
46
47#[cfg(target_os = "windows")]
48pub mod windows;
49
50#[cfg(not(any(
51    target_os = "android",
52    target_os = "ios",
53    target_os = "macos",
54    target_os = "windows",
55    target_env = "ohos"
56)))]
57mod unsupported;
58
59#[cfg(any(target_os = "macos", target_os = "windows"))]
60pub mod desktop;
61
62/// Canonical platform-family label — the single source of truth for "which
63/// OS is this," shared by the WebView bridge config injection
64/// (`lingxia-lxapp`), `lx.app.getBaseInfo().os`, and `lx.getDeviceInfo().osName`
65/// (`lingxia-logic`) so the three can never drift apart. Matches the values
66/// the View-side bridge already exposes via `usePlatform().os`.
67pub fn os_label() -> &'static str {
68    #[cfg(any(target_os = "ios", target_os = "macos"))]
69    {
70        if cfg!(target_os = "macos") {
71            "macOS"
72        } else {
73            "iOS"
74        }
75    }
76    #[cfg(target_os = "android")]
77    {
78        "Android"
79    }
80    #[cfg(target_os = "windows")]
81    {
82        "Windows"
83    }
84    #[cfg(all(target_os = "linux", target_env = "ohos"))]
85    {
86        "Harmony"
87    }
88    #[cfg(not(any(
89        target_os = "ios",
90        target_os = "macos",
91        target_os = "android",
92        target_os = "windows",
93        all(target_os = "linux", target_env = "ohos"),
94    )))]
95    {
96        "unknown"
97    }
98}
99
100/// Whether launch-at-startup can actually work on this host, probed at
101/// runtime. macOS builds target 12 but SMAppService needs 13+, so the
102/// `lx.app.autostart` member must not be registered from a compile-time
103/// gate alone — presence is the JS support contract.
104#[cfg(any(target_os = "macos", target_os = "windows"))]
105pub fn autostart_supported() -> bool {
106    #[cfg(target_os = "macos")]
107    {
108        apple::autostart_probe_supported()
109    }
110    #[cfg(target_os = "windows")]
111    {
112        true
113    }
114}
115
116#[cfg(target_os = "android")]
117pub use android::{
118    CachedClass, Platform, get_android_id, get_api_level, get_system_property,
119    has_telephony_feature, init_cached_class, initialize_jni, read_external_storage_text,
120    write_external_storage_text,
121};
122
123#[cfg(any(target_os = "ios", target_os = "macos"))]
124pub use apple::Platform;
125#[cfg(any(target_os = "ios", target_os = "macos"))]
126pub use apple::apply_staged_macos_update;
127
128#[cfg(target_env = "ohos")]
129pub use harmony::Platform;
130
131#[cfg(target_os = "windows")]
132pub use windows::{
133    Platform, WindowsMediaPreviewCancel, WindowsMediaPreviewOpen, WindowsUrlSurfaceWebTag,
134    WindowsVideoCommandDispatcher, apply_staged_windows_update, install_windows_aside_panel_bridge,
135    register_windows_media_preview_host, register_windows_video_command_dispatcher,
136    set_windows_activate_browser_tab_handler, set_windows_app_exit_handler,
137    set_windows_builtin_browser_page_handler, set_windows_close_browser_tab_handler,
138    set_windows_home_first_ready_handler, set_windows_layout_plan_handler,
139    set_windows_lxapp_main_activation_handler, set_windows_managed_aside_event_handler,
140    set_windows_managed_native_surface_open_handler, set_windows_managed_surface_close_handler,
141    set_windows_managed_surface_visible_handler, set_windows_open_url_handler,
142    set_windows_page_visibility_handler, set_windows_pull_to_refresh_handler,
143    set_windows_shell_pins_handler, set_windows_sidebar_actions_handler,
144    set_windows_surface_closed_handler, set_windows_surface_dispose_handler,
145    set_windows_tray_click_intercept_handler, set_windows_tray_menu_handler,
146    set_windows_ui_update_async_handler, set_windows_ui_update_handler,
147    set_windows_url_surface_handler, sync_windows_ui,
148};
149
150#[cfg(not(any(
151    target_os = "android",
152    target_os = "ios",
153    target_os = "macos",
154    target_os = "windows",
155    target_env = "ohos"
156)))]
157pub use unsupported::Platform;
158
159pub mod error;
160pub use error::*;
161
162pub mod i18n;