tauri_runtime_verso/
webview.rs1#![allow(unused_variables)]
2
3use tauri_runtime::{
4 Error, Result, UserEvent, WebviewDispatch, WebviewEventId,
5 dpi::{PhysicalPosition, PhysicalSize, Position, Size},
6 window::{WebviewEvent, WindowId},
7};
8use url::Url;
9use verso::VersoviewController;
10
11use std::{
12 fmt::{self, Debug},
13 sync::{Arc, Mutex},
14};
15
16use crate::{RuntimeContext, VersoRuntime};
17
18#[derive(Clone)]
20pub struct VersoWebviewDispatcher<T: UserEvent> {
21 pub(crate) id: u32,
22 pub(crate) context: RuntimeContext<T>,
23 pub(crate) webview: Arc<Mutex<VersoviewController>>,
24}
25
26impl<T: UserEvent> Debug for VersoWebviewDispatcher<T> {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 f.debug_struct("VersoWebviewDispatcher")
29 .field("id", &self.id)
30 .field("context", &self.context)
31 .field("webview", &"VersoviewController")
32 .finish()
33 }
34}
35
36impl<T: UserEvent> WebviewDispatch<T> for VersoWebviewDispatcher<T> {
37 type Runtime = VersoRuntime<T>;
38
39 fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> Result<()> {
40 self.context.run_on_main_thread(f)
41 }
42
43 fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) -> WebviewEventId {
45 self.context.next_window_event_id()
46 }
47
48 fn with_webview<F: FnOnce(Box<dyn std::any::Any>) + Send + 'static>(&self, f: F) -> Result<()> {
50 Ok(())
51 }
52
53 fn set_zoom(&self, scale_factor: f64) -> Result<()> {
55 Ok(())
56 }
57
58 fn eval_script<S: Into<String>>(&self, script: S) -> Result<()> {
59 self.webview
60 .lock()
61 .unwrap()
62 .execute_script(script.into())
63 .map_err(|_| Error::FailedToSendMessage)?;
64 Ok(())
65 }
66
67 fn url(&self) -> Result<String> {
68 Ok(self
69 .webview
70 .lock()
71 .unwrap()
72 .get_current_url()
73 .map_err(|_| Error::FailedToSendMessage)?
74 .to_string())
75 }
76
77 fn bounds(&self) -> Result<tauri_runtime::dpi::Rect> {
78 Ok(tauri_runtime::dpi::Rect {
79 position: self.position()?.into(),
80 size: self.size()?.into(),
81 })
82 }
83
84 fn position(&self) -> Result<PhysicalPosition<i32>> {
85 Ok(PhysicalPosition { x: 0, y: 0 })
86 }
87
88 fn size(&self) -> Result<PhysicalSize<u32>> {
89 let size = self
90 .webview
91 .lock()
92 .unwrap()
93 .get_inner_size()
94 .map_err(|_| Error::FailedToSendMessage)?;
95 Ok(size)
96 }
97
98 fn navigate(&self, url: Url) -> Result<()> {
99 self.webview
100 .lock()
101 .unwrap()
102 .navigate(url)
103 .map_err(|_| Error::FailedToSendMessage)?;
104 Ok(())
105 }
106
107 fn print(&self) -> Result<()> {
109 Ok(())
110 }
111
112 fn close(&self) -> Result<()> {
116 Ok(())
117 }
118
119 fn set_bounds(&self, bounds: tauri_runtime::dpi::Rect) -> Result<()> {
123 Ok(())
124 }
125
126 fn set_size(&self, _size: Size) -> Result<()> {
130 Ok(())
131 }
132
133 fn set_position(&self, _position: Position) -> Result<()> {
137 Ok(())
138 }
139
140 fn set_focus(&self) -> Result<()> {
144 Ok(())
145 }
146
147 fn reparent(&self, window_id: WindowId) -> Result<()> {
149 Ok(())
150 }
151
152 fn set_auto_resize(&self, auto_resize: bool) -> Result<()> {
154 Ok(())
155 }
156
157 fn clear_all_browsing_data(&self) -> Result<()> {
159 Ok(())
160 }
161
162 fn hide(&self) -> Result<()> {
166 Ok(())
167 }
168
169 fn show(&self) -> Result<()> {
173 Ok(())
174 }
175
176 fn set_background_color(&self, color: Option<tauri_utils::config::Color>) -> Result<()> {
178 Ok(())
179 }
180
181 #[cfg(debug_assertions)]
183 fn open_devtools(&self) {}
184
185 #[cfg(debug_assertions)]
187 fn close_devtools(&self) {}
188
189 #[cfg(debug_assertions)]
191 fn is_devtools_open(&self) -> Result<bool> {
192 Ok(false)
193 }
194
195 fn reload(&self) -> Result<()> {
196 self.webview
197 .lock()
198 .unwrap()
199 .reload()
200 .map_err(|_| Error::FailedToSendMessage)?;
201 Ok(())
202 }
203
204 fn cookies_for_url(&self, url: Url) -> Result<Vec<tauri_runtime::Cookie<'static>>> {
206 Ok(Vec::new())
207 }
208
209 fn cookies(&self) -> Result<Vec<tauri_runtime::Cookie<'static>>> {
211 Ok(Vec::new())
212 }
213}