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