Skip to main content

lingxia_platform/traits/
app_runtime.rs

1use std::io::Read;
2use std::path::{Path, PathBuf};
3
4use crate::AssetFileEntry;
5use crate::error::PlatformError;
6
7use super::device::{Device, DeviceHardware, DeviceSecureStore};
8use super::document::DocumentInteraction;
9use super::location::Location;
10use super::media_interaction::{MediaInteraction, MediaKind};
11use super::media_runtime::MediaRuntime;
12use super::ui::{PopupPresenter, UIUpdate, UserFeedback};
13use super::update::UpdateService;
14use super::wifi::Wifi;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum AnimationType {
18    None = 0,
19    Forward = 1,
20    Backward = 2,
21}
22
23impl From<i32> for AnimationType {
24    fn from(value: i32) -> Self {
25        match value {
26            1 => AnimationType::Forward,
27            2 => AnimationType::Backward,
28            _ => AnimationType::None,
29        }
30    }
31}
32
33pub trait AppRuntime:
34    Send
35    + Sync
36    + MediaInteraction
37    + MediaRuntime
38    + PopupPresenter
39    + Device
40    + DeviceHardware
41    + DeviceSecureStore
42    + DocumentInteraction
43    + Location
44    + UIUpdate
45    + UpdateService
46    + UserFeedback
47    + Wifi
48    + 'static
49{
50    /// Reads an asset file as a streaming reader.
51    fn read_asset<'a>(&'a self, path: &str) -> Result<Box<dyn Read + 'a>, PlatformError>;
52
53    /// Iterates over files in an asset directory.
54    fn asset_dir_iter<'a>(
55        &'a self,
56        asset_dir: &str,
57    ) -> Box<dyn Iterator<Item = Result<AssetFileEntry<'a>, PlatformError>> + 'a>;
58
59    /// Returns the app's data directory path.
60    fn app_data_dir(&self) -> PathBuf;
61
62    /// Returns the app's cache directory path.
63    fn app_cache_dir(&self) -> PathBuf;
64
65    /// Obtains the application identifier.
66    fn get_app_identifier(&self) -> Result<String, PlatformError>;
67
68    /// Copies media from the system album to a local file.
69    fn copy_album_media_to_file(
70        &self,
71        uri: &str,
72        dest_path: &Path,
73        kind: MediaKind,
74    ) -> Result<(), PlatformError> {
75        MediaRuntime::copy_album_media_to_file(self, uri, dest_path, kind)
76    }
77
78    /// Returns the current system locale.
79    fn get_system_locale(&self) -> &str;
80
81    /// Show the UI container for the given LxApp and route.
82    fn show_lxapp(&self, appid: String, path: String) -> Result<(), PlatformError>;
83
84    /// Hide the UI container for the given LxApp (does not destroy its runtime state).
85    fn hide_lxapp(&self, appid: String) -> Result<(), PlatformError>;
86
87    /// Navigates within the given LxApp using an animation.
88    fn navigate(
89        &self,
90        appid: String,
91        path: String,
92        animation_type: AnimationType,
93    ) -> Result<(), PlatformError>;
94
95    /// Launches the given URL in the host environment.
96    fn launch_with_url(&self, url: String) -> Result<(), PlatformError>;
97
98    /// Gets the capsule button bounding rect in screen coordinates.
99    /// Returns result via callback with JSON string format: {"width": 84.5, "height": 32, "top": 50, "right": 375, "bottom": 82, "left": 290.5}
100    /// All values are in pixels, relative to screen top-left corner (0, 0).
101    /// Note: This only works when the page has showNavigationBar: false (webview is fullscreen).
102    ///
103    /// # Arguments
104    /// * `callback_id` - The callback ID to invoke with the result
105    ///
106    /// # iOS/macOS
107    /// Returns synchronously via callback immediately
108    ///
109    /// # Android/HarmonyOS
110    /// Returns asynchronously via callback after querying native UI layer
111    fn get_capsule_rect(&self, callback_id: u64) -> Result<(), PlatformError>;
112}