Skip to main content

beeper_desktop_api/client/
app.rs

1//! App control and asset operations
2
3use crate::models::{DownloadAssetInput, DownloadAssetOutput, FocusAppInput, FocusAppOutput};
4use crate::error::Result;
5use super::{BeeperClient, handle_response};
6
7impl BeeperClient {
8    /// Focuses Beeper Desktop and optionally navigates to a specific location
9    pub async fn focus_app(&self, input: Option<FocusAppInput>) -> Result<FocusAppOutput> {
10        let url = format!("{}/v1/focus", self.get_base_url());
11
12        let response = if let Some(inp) = input {
13            self.get_http_client()
14                .post(&url)
15                .header("Authorization", self.get_auth_header())
16                .json(&inp)
17                .send()
18                .await?
19        } else {
20            self.get_http_client()
21                .post(&url)
22                .header("Authorization", self.get_auth_header())
23                .json(&serde_json::json!({}))
24                .send()
25                .await?
26        };
27
28        handle_response(response).await
29    }
30
31    /// Downloads an asset from a URL
32    ///
33    /// Downloads a Matrix asset using its mxc:// or localmxc:// URL to the device
34    /// running Beeper Desktop and returns the local file URL.
35    pub async fn download_asset(&self, url: &str) -> Result<DownloadAssetOutput> {
36        let endpoint_url = format!("{}/v1/assets/download", self.get_base_url());
37        let input = DownloadAssetInput {
38            url: url.to_string(),
39        };
40
41        let response = self
42            .get_http_client()
43            .post(&endpoint_url)
44            .header("Authorization", self.get_auth_header())
45            .json(&input)
46            .send()
47            .await?;
48
49        handle_response(response).await
50    }
51}