web_component/runner/
mod.rs

1use crate::prelude::*;
2
3pub struct Runner {
4
5}
6
7impl Default for Runner {
8    fn default() -> Self {
9        Self {}
10    }
11}
12
13impl Runner {
14    pub fn new() -> Self {
15        Default::default()
16    }
17
18    #[cfg(feature = "desktop")]
19    pub fn run(&self, f: fn() -> Element) {
20        use dioxus::desktop::{LogicalPosition, LogicalSize};
21        // Init logger
22        dioxus_logger::init(dioxus_logger::tracing::Level::INFO).expect("failed to init logger");
23        let monitor = {
24            let event_loop = dioxus::desktop::tao::event_loop::EventLoop::new();
25            let window = dioxus::desktop::tao::window::WindowBuilder::new()
26                .with_visible(false).build(&event_loop).expect("Failed to create window");
27            window.available_monitors().next().expect("No monitor found")
28        };
29        let window_size = LogicalSize::new(800.0, 600.0);
30        let size = monitor.size();
31        let position = LogicalPosition::new((size.width as f64 - window_size.width) / 2.0, (size.height as f64 - window_size.height) / 2.0);
32        let window = dioxus::desktop::WindowBuilder::new()
33            .with_title("File Explorer")
34            .with_inner_size(window_size)
35            .with_position(position)
36            .with_transparent(true)
37            // .with_decorations(false)
38            .with_always_on_top(true);
39        let cfg = dioxus::desktop::Config::new()
40            .with_window(window)
41            .with_menu(None)
42            .with_disable_context_menu(true);
43        LaunchBuilder::desktop()
44            .with_cfg(cfg)
45            .launch(Application);
46    }
47
48    #[cfg(not(feature = "desktop"))]
49    pub fn run(&self, f: fn() -> Element) {
50        LaunchBuilder::web()
51            .launch(f);
52    }
53}