freya_webview/
registry.rs1use std::sync::Arc;
4
5use freya_core::prelude::UseId;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
9pub struct WebViewId(pub usize);
10
11impl WebViewId {
12 pub fn new() -> Self {
14 Self(UseId::<Self>::get_in_hook())
15 }
16}
17
18impl Default for WebViewId {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24pub type WebViewCallback =
26 Arc<Box<dyn Fn(wry::WebViewBuilder) -> wry::WebViewBuilder + Send + 'static>>;
27
28#[derive(Clone, Default)]
30pub struct WebViewConfig {
31 pub url: String,
33 pub transparent: bool,
35 pub user_agent: Option<String>,
37 pub on_created: Option<WebViewCallback>,
39}
40
41impl PartialEq for WebViewConfig {
42 fn eq(&self, other: &Self) -> bool {
43 self.url == other.url
44 && self.transparent == other.transparent
45 && self.user_agent == other.user_agent
46 && match (&self.on_created, &other.on_created) {
47 (None, None) => true,
48 (Some(a), Some(b)) => std::sync::Arc::ptr_eq(a, b),
49 _ => false,
50 }
51 }
52}
53
54impl std::fmt::Debug for WebViewConfig {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 f.debug_struct("WebViewConfig")
57 .field("url", &self.url)
58 .field("transparent", &self.transparent)
59 .field("user_agent", &self.user_agent)
60 .field(
61 "on_created",
62 &self.on_created.as_ref().map(|_| "<callback>"),
63 )
64 .finish()
65 }
66}