oxios_kernel/kernel_handle/
browser_api.rs1use std::sync::Arc;
7
8#[cfg(feature = "browser")]
13pub struct BrowserApi {
14 browser: Arc<oxibrowser_core::Browser>,
15}
16
17#[cfg(feature = "browser")]
18impl BrowserApi {
19 pub fn from_config(config: &oxibrowser_core::BrowserConfig) -> Self {
21 let rt = tokio::runtime::Handle::current();
22 let engine = config.clone();
23 let browser = rt
24 .block_on(oxibrowser_core::Browser::new(engine))
25 .expect("Failed to initialize browser engine");
26 Self {
27 browser: Arc::new(browser),
28 }
29 }
30
31 pub fn new(browser: Arc<oxibrowser_core::Browser>) -> Self {
33 Self { browser }
34 }
35
36 pub fn browser(&self) -> &Arc<oxibrowser_core::Browser> {
38 &self.browser
39 }
40
41 pub async fn shutdown(&self) -> anyhow::Result<()> {
43 self.browser.close().await?;
44 Ok(())
45 }
46}
47
48#[cfg(feature = "browser")]
50impl Default for BrowserApi {
51 fn default() -> Self {
52 panic!("BrowserApi::default() called with browser feature enabled — use KernelHandle::new() with a real BrowserApi");
53 }
54}
55
56#[cfg(not(feature = "browser"))]
58pub struct BrowserApi;
59
60#[cfg(not(feature = "browser"))]
61impl Default for BrowserApi {
62 fn default() -> Self {
63 BrowserApi
64 }
65}