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    /// Whether this platform installs host-app updates itself (download +
7    /// in-place install/relaunch). Store-delivered platforms (iOS App Store,
8    /// HarmonyOS AppGallery) return `false`: they must update through the
9    /// store, so the update flow never downloads or self-installs there.
10    ///
11    /// Defaults to `false` — opt in per platform (macOS, Android).
12    fn self_update_supported(&self) -> bool {
13        false
14    }
15
16    /// Open the platform app-store page for this app so the user can update
17    /// through the store. Used on store-delivered platforms when an update is
18    /// available. Returns `true` if a store page was opened. Defaults to
19    /// `false` (no in-app redirect; rely on the store's own update prompts).
20    fn open_update_store(&self, _update_info_json: &str) -> Result<bool, PlatformError> {
21        Ok(false)
22    }
23
24    /// Requests installation of an application update from a local package file.
25    ///
26    /// This starts the platform-specific apply flow and returns once the request
27    /// is handed off to the updater helper.
28    ///
29    /// # Arguments
30    /// * `package_path` - Local, readable update package path (e.g. .apk on Android)
31    /// * `info_json` - Prompt metadata `{version, releaseNotes, isForceUpdate}`.
32    ///   Release notes are shown in the "ready to update" prompt; when
33    ///   `isForceUpdate` is true the prompt is blocking (no dismiss).
34    ///
35    /// # Platform Support / Notes
36    /// - Android: Shows the post-download "ready to install" prompt (with
37    ///   release notes), then launches the system installer on confirm.
38    ///   Requires `REQUEST_INSTALL_PACKAGES` and a `FileProvider` for APK sharing.
39    /// - macOS: Stages a prepared `.zip` or `.app` update, shows the
40    ///   "ready to update" callout, and relaunches on the user's click.
41    /// - iOS: Not supported (App Store only).
42    /// - HarmonyOS: Not implemented (returns error).
43    fn install_update(&self, package_path: &Path, info_json: &str) -> Result<(), PlatformError> {
44        let _ = (package_path, info_json);
45        Err(PlatformError::NotSupported(
46            "install_update not implemented for this platform".to_string(),
47        ))
48    }
49}