#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use adw::prelude::*;
use gtk::{
    gio::{self, ApplicationFlags},
    glib,
};

mod app;
mod color;
mod config;
mod i18n;
mod search;
mod ui;

// generated by Meson
mod build;

fn main() {
    env_logger::init();

    i18n::setup_gettext();

    gtk::init().expect("Failed to initialize Gtk");
    adw::init().expect("Failed to initialize Adwaita");
    sourceview5::init();

    log::info!(target: "env", "user = {:?}", glib::user_name());
    log::info!(target: "env", "home = {:?}", glib::home_dir());
    log::info!(target: "env", "data = {:?}", glib::user_data_dir());
    log::info!(target: "env", "config = {:?}", glib::user_config_dir());
    log::info!(target: "env", "state = {:?}", glib::user_state_dir());

    gio::resources_register(
        &gio::Resource::from_data(&glib::Bytes::from_static(build::GRESOURCES_BUNDLE)).unwrap(),
    );

    let application = adw::Application::builder()
        .application_id(build::APP_ID)
        .flags(ApplicationFlags::HANDLES_OPEN)
        .build();

    application.connect_open(|a, files, _| app::start(a, files));
    application.connect_activate(|a| app::start(a, &[]));

    application.run();
}
