freya_components/
app.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::sync::Arc;

use dioxus::prelude::*;
use freya_elements as dioxus_elements;

use crate::NativeContainer;

#[derive(Props, Clone)]
pub struct FreyaAppProps {
    pub app: Arc<dyn Fn() -> Element>,
}

impl PartialEq for FreyaAppProps {
    fn eq(&self, _other: &Self) -> bool {
        true
    }
}

#[allow(non_snake_case)]
pub fn FreyaApp(props: FreyaAppProps) -> Element {
    #[allow(non_snake_case)]
    let App = props.app;

    let handle_error = |e: ErrorContext| {
        for error in e.errors().iter() {
            println!("{:?}", error);
        }

        #[cfg(not(debug_assertions))]
        std::process::exit(1);

        #[cfg(debug_assertions)]
        rsx!(
            rect {
                width: "fill",
                height: "fill",
                background: "rgb(138, 0, 0)",
                color: "white",
                main_align: "center",
                cross_align: "center",
                label {
                    "An unhandled error was thrown, check your logs."
                }
            }
        )
    };

    rsx!(
        NativeContainer {
            ErrorBoundary {
                handle_error,
                {App()}
            }
        }
    )
}