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:
26    ///   {"version":"1.2.0","size":15728640,"releaseNotes":["..."],"isForceUpdate":true}
27    ///
28    /// # Callback behavior
29    /// - Confirm: callback success with payload (e.g. {"confirm":true})
30    /// - Cancel: callback error code 2000
31    fn show_update_prompt(
32        &self,
33        _callback_id: u64,
34        _update_info_json: Option<&str>,
35    ) -> Result<(), PlatformError> {
36        Err(PlatformError::NotSupported(
37            "show_update_prompt not implemented for this platform".to_string(),
38        ))
39    }
40
41    /// Requests installation of an application update from a local package file.
42    ///
43    /// This launches the system installer and returns once the request is issued.
44    /// It does not guarantee the update is installed successfully.
45    ///
46    /// # Arguments
47    /// * `package_path` - Local, readable update package path (e.g. .apk on Android)
48    ///
49    /// # Platform Support / Notes
50    /// - Android: Launches the system installer; requires user confirmation.
51    ///   Requires `REQUEST_INSTALL_PACKAGES` and a `FileProvider` for APK sharing.
52    /// - macOS: Planned support for .pkg/.dmg installers.
53    /// - iOS: Not supported (App Store only).
54    /// - HarmonyOS: Not implemented (returns error).
55    fn install_update(&self, package_path: &Path) -> Result<(), PlatformError> {
56        let _ = package_path;
57        Err(PlatformError::NotSupported(
58            "install_update not implemented for this platform".to_string(),
59        ))
60    }
61}