use std::sync::Arc;
use freya_core::prelude::UseId;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct WebViewId(pub usize);
impl WebViewId {
pub fn new() -> Self {
Self(UseId::<Self>::get_in_hook())
}
}
impl Default for WebViewId {
fn default() -> Self {
Self::new()
}
}
pub type WebViewCallback =
Arc<Box<dyn Fn(wry::WebViewBuilder) -> wry::WebViewBuilder + Send + 'static>>;
#[derive(Clone, Default)]
pub struct WebViewConfig {
pub url: String,
pub transparent: bool,
pub user_agent: Option<String>,
pub on_created: Option<WebViewCallback>,
}
impl PartialEq for WebViewConfig {
fn eq(&self, other: &Self) -> bool {
self.url == other.url
&& self.transparent == other.transparent
&& self.user_agent == other.user_agent
&& match (&self.on_created, &other.on_created) {
(None, None) => true,
(Some(a), Some(b)) => std::sync::Arc::ptr_eq(a, b),
_ => false,
}
}
}
impl std::fmt::Debug for WebViewConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WebViewConfig")
.field("url", &self.url)
.field("transparent", &self.transparent)
.field("user_agent", &self.user_agent)
.field(
"on_created",
&self.on_created.as_ref().map(|_| "<callback>"),
)
.finish()
}
}