Skip to main content

lingxia_platform/traits/
update.rs

1use std::path::Path;
2
3use crate::error::PlatformError;
4
5pub trait UpdateService: Send + Sync + 'static {
6    /// Show download progress UI
7    fn show_download_progress(&self) -> Result<(), PlatformError> {
8        Ok(())
9    }
10
11    /// Update download progress (0-100)
12    fn update_download_progress(&self, _progress: i32) -> Result<(), PlatformError> {
13        Ok(())
14    }
15
16    /// Dismiss download progress UI
17    fn dismiss_download_progress(&self) -> Result<(), PlatformError> {
18        Ok(())
19    }
20
21    /// Show update confirmation prompt and invoke callback with the result.
22    ///
23    /// # Arguments
24    /// * `callback_id` - Callback ID for result
25    /// * `update_info_json` - Optional JSON string with update details: {"version":"1.2.0","size":15728640,"releaseNotes":["..."]}
26    ///
27    /// # Callback behavior
28    /// - Confirm: callback success with payload (e.g. {"confirm":true})
29    /// - Cancel: callback error code 2000
30    fn show_update_prompt(
31        &self,
32        _callback_id: u64,
33        _update_info_json: Option<&str>,
34    ) -> Result<(), PlatformError> {
35        Err(PlatformError::Platform(
36            "show_update_prompt not implemented for this platform".to_string(),
37        ))
38    }
39
40    /// Requests installation of an application update from a local package file.
41    ///
42    /// This launches the system installer and returns once the request is issued.
43    /// It does not guarantee the update is installed successfully.
44    ///
45    /// # Arguments
46    /// * `package_path` - Local, readable update package path (e.g. .apk on Android)
47    ///
48    /// # Platform Support / Notes
49    /// - Android: Launches the system installer; requires user confirmation.
50    ///   Requires `REQUEST_INSTALL_PACKAGES` and a `FileProvider` for APK sharing.
51    /// - macOS: Planned support for .pkg/.dmg installers.
52    /// - iOS: Not supported (App Store only).
53    /// - HarmonyOS: Not implemented (returns error).
54    fn install_update(&self, package_path: &Path) -> Result<(), PlatformError> {
55        let _ = package_path;
56        Err(PlatformError::Platform(
57            "install_update not implemented for this platform".to_string(),
58        ))
59    }
60}