capacitor_bindings/
browser.rs

1use crate::error::Error;
2use crate::helpers::*;
3use crate::{extern_functions::*, prelude::*};
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7pub struct Browser;
8
9impl Browser {
10    /// Open a page with the specified options.
11    pub async fn open(options: impl Into<OpenOptions>) -> Result<(), Error> {
12        run_value_unit(options, browser_open).await
13    }
14    #[cfg(any(feature = "ios", feature = "web"))]
15    /// Web & iOS only: Close an open browser window.
16    pub async fn close() -> Result<(), Error> {
17        run_unit_unit(browser_close).await
18    }
19
20    /// Remove all native listeners for this plugin.
21    pub async fn remove_all_listeners() -> Result<(), Error> {
22        run_unit_unit(browser_remove_all_listeners).await
23    }
24
25    #[cfg(any(feature = "ios", feature = "android"))]
26    pub async fn add_browser_finished_listener<F: Fn(()) + 'static>(
27        func: F,
28    ) -> Result<PluginListenerHandle, Error> {
29        listen_async(func, "browserFinished", browser_add_listener).await
30    }
31
32    #[cfg(any(feature = "ios", feature = "android"))]
33    pub async fn add_browser_page_loaded_listener<F: Fn(()) + 'static>(
34        func: F,
35    ) -> Result<PluginListenerHandle, Error> {
36        listen_async(func, "browserPageLoaded", browser_add_listener).await
37    }
38}
39
40#[skip_serializing_none]
41#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase", default)]
43pub struct OpenOptions {
44    /// The URL to which the browser is opened.
45    pub url: String,
46    /// Web only: Optional target for browser open. Follows the target property for window.open. Defaults to _blank. Ignored on other platforms.
47    pub window_name: Option<String>,
48    /// A hex color to which the toolbar color is set.
49    pub toolbar_color: Option<String>,
50    /// iOS only: The presentation style of the browser. Defaults to fullscreen. Ignored on other platforms.
51    pub presentation_style: Option<PresentationStyle>,
52    /// iOS only: The width the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms.
53    pub width: Option<u32>,
54    /// iOS only: The height the browser when using presentationStyle 'popover' on iPads. Ignored on other platforms.
55    pub height: Option<u32>,
56}
57
58#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
59#[serde(rename_all = "kebab-case")]
60pub enum PresentationStyle {
61    Fullscreen,
62    Popover,
63}