use crate::login_window::LoginWindow; use gtk4 as gtk; use gtk::{glib, gdk, gio, prelude::*, subclass::prelude::*}; mod imp { use super::*; use std::cell::RefCell; #[derive(Debug, glib::Properties)] #[properties(wrapper_type = super::Application)] pub struct Application { #[property(name = "api-key", type = Option, get = Self::api_key, set = Self::set_api_key, nullable)] pub settings: RefCell, } impl Application { fn api_key(&self) -> Option { self.settings.borrow().value("api-key").get() } fn set_api_key(&self, value: Option) { _ = self.settings.borrow().set("api-key", value).unwrap(); } } impl Default for Application { fn default() -> Self { Self { settings: RefCell::new(gio::Settings::new(crate::APP_ID)), } } } #[glib::object_subclass] impl ObjectSubclass for Application { const NAME: &'static str = "Application"; type Type = super::Application; type ParentType = gtk::Application; } impl ApplicationImpl for Application { fn activate(&self) { let css = gtk::CssProvider::new(); gtk::style_context_add_provider_for_display( &gdk::Display::default().unwrap(), &css, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION ); css.load_from_string(include_str!("../data/global.css")); if self.api_key().is_none() { let login_window = LoginWindow::new(&self.obj()); login_window.present(); } else { todo!(); } } } #[glib::derived_properties] impl ObjectImpl for Application {} impl GtkApplicationImpl for Application {} } glib::wrapper! { pub struct Application(ObjectSubclass) @extends gtk::Application, gio::Application, @implements gio::ActionMap, gio::ActionGroup; } impl Application { pub fn new(app_id: &str) -> Self { glib::Object::builder().property("application-id", app_id).build() } }