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
mod backend;
mod config;

pub use backend::*;
pub use config::*;

pub use nuit_core::*;
pub use nuit_derive::*;

impl Default for Backend {
    fn default() -> Self {
        #[cfg(target_vendor = "apple")]
        return Backend::SwiftUI;
        #[cfg(not(target_vendor = "apple"))]
        return Backend::Relm;
    }
}

/// Blocks and presents the given view to the user.
pub fn run_app<T>(config: impl Into<Config<T>>) where T: View {
    let config: Config<T> = config.into();
    let backend = config.preferred_backend().unwrap_or_default();
    let view = config.into_view();
    let root = Root::new(view);

    match backend {
        Backend::SwiftUI => {
            let c_root = CRoot::from(Box::new(root));
            #[cfg(target_vendor = "apple")]
            unsafe { nuit_bridge_swiftui::run_app(&c_root); }
            #[cfg(not(target_vendor = "apple"))]
            panic!("SwiftUI is not supported outside of Apple platforms!")
        }
        Backend::Relm => {
            panic!("Relm is not supported (yet)")
        }
    }
}