ctoolbox/io/webui/
webview.rs1#[cfg(not(target_os = "linux"))]
2#[derive(Default)]
3struct App {
4 url: String,
5 window: Option<Window>,
6 webview: Option<wry::WebView>,
7}
8
9#[cfg(not(target_os = "linux"))]
10impl ApplicationHandler for App {
11 fn resumed(&mut self, event_loop: &ActiveEventLoop) {
12 let window = event_loop
13 .create_window(Window::default_attributes())
14 .unwrap();
15 let webview = WebViewBuilder::new()
16 .with_url(&self.url)
17 .build(&window)
18 .unwrap();
19
20 self.window = Some(window);
21 self.webview = Some(webview);
22 }
23
24 fn window_event(
25 &mut self,
26 _event_loop: &ActiveEventLoop,
27 _window_id: WindowId,
28 event: WindowEvent,
29 ) {
30 }
31}
32
33pub fn start_webview(url: String) {
34 cfg_if::cfg_if! {
35 if #[cfg(target_os = "linux")] {
36 if webbrowser::open(&url).is_err() {
37 eprintln!("Failed to open web browser to URL: {url}");
38 }
39 } else {
40 let event_loop = EventLoop::new().unwrap();
41 let mut app = App::default();
42 app.url = url;
43 event_loop.run_app(&mut app).unwrap();
44 }
45 }
46}