use std::sync::Arc;
#[cfg(feature = "browser")]
pub struct BrowserApi {
browser: Arc<oxibrowser_core::Browser>,
}
#[cfg(feature = "browser")]
impl BrowserApi {
pub fn from_config(config: &oxibrowser_core::BrowserConfig) -> Self {
let rt = tokio::runtime::Handle::current();
let engine = config.clone();
let browser = rt
.block_on(oxibrowser_core::Browser::new(engine))
.expect("Failed to initialize browser engine");
Self {
browser: Arc::new(browser),
}
}
pub fn new(browser: Arc<oxibrowser_core::Browser>) -> Self {
Self { browser }
}
pub fn browser(&self) -> &Arc<oxibrowser_core::Browser> {
&self.browser
}
pub async fn shutdown(&self) -> anyhow::Result<()> {
self.browser.close().await?;
Ok(())
}
}
#[cfg(feature = "browser")]
impl Default for BrowserApi {
fn default() -> Self {
panic!("BrowserApi::default() called with browser feature enabled — use KernelHandle::new() with a real BrowserApi");
}
}
#[cfg(not(feature = "browser"))]
pub struct BrowserApi;
#[cfg(not(feature = "browser"))]
impl Default for BrowserApi {
fn default() -> Self {
BrowserApi
}
}