mod agent;
mod app;
mod database;
mod engine;
mod metrics;
mod model;
#[cfg(target_os = "macos")]
mod native_edit;
#[cfg(target_os = "macos")]
mod native_menu;
#[cfg(target_os = "macos")]
mod runtime;
mod schema;
#[cfg(target_os = "macos")]
mod server;
mod settings;

use app::{App, Message, app_icon, app_theme};
use iced::{Size, window};

fn main() -> iced::Result {
    #[cfg(target_os = "macos")]
    if let Err(error) = engine::configure_metal_sources() {
        eprintln!("DS4Server: {error}");
    }
    iced::daemon(App::title, App::update, App::view)
        .subscription(App::subscription)
        .theme(|_, _| app_theme())
        .run_with(|| {
            let (main_window, open) = window::open(window::Settings {
                size: Size::new(1120.0, 720.0),
                min_size: Some(Size::new(760.0, 480.0)),
                icon: Some(app_icon()),
                // The title bar is ours: content runs to the top edge and the
                // native traffic lights float over it.
                #[cfg(target_os = "macos")]
                platform_specific: window::settings::PlatformSpecific {
                    title_hidden: true,
                    titlebar_transparent: true,
                    fullsize_content_view: true,
                },
                ..Default::default()
            });
            (App::load(main_window), open.map(Message::WindowOpened))
        })
}
