diff --git a/src/application.rs b/src/application.rs index c686a218..4fb7fdd9 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,7 +1,7 @@ use crate::config; use crate::Window; use gettextrs::gettext; -use gio::ApplicationFlags; +use gio::{ApplicationFlags, Settings}; use glib::clone; use glib::WeakRef; use gtk::prelude::*; @@ -17,6 +17,7 @@ mod imp { #[derive(Debug)] pub struct Application { pub window: OnceCell>, + pub settings: Settings, } #[glib::object_subclass] @@ -28,6 +29,7 @@ mod imp { fn new() -> Self { Self { window: OnceCell::new(), + settings: Settings::new(config::APP_ID), } } } @@ -91,6 +93,10 @@ impl Application { .unwrap() } + pub fn settings(&self) -> Settings { + imp::Application::from_instance(self).settings.clone() + } + fn setup_gactions(&self) { // Quit action!( @@ -173,3 +179,12 @@ impl Application { ApplicationExtManual::run(self); } } + +impl Default for Application { + fn default() -> Self { + gio::Application::default() + .unwrap() + .downcast::() + .unwrap() + } +} diff --git a/src/window.rs b/src/window.rs index 1cd0159f..88615b82 100644 --- a/src/window.rs +++ b/src/window.rs @@ -21,7 +21,6 @@ mod imp { pub main_stack: TemplateChild, #[template_child] pub login: TemplateChild, - pub settings: gio::Settings, } #[glib::object_subclass] @@ -34,7 +33,6 @@ mod imp { Self { main_stack: TemplateChild::default(), login: TemplateChild::default(), - settings: gio::Settings::new(APP_ID), } } @@ -115,7 +113,7 @@ impl Window { } pub fn save_window_size(&self) -> Result<(), glib::BoolError> { - let settings = &imp::Window::from_instance(self).settings; + let settings = Application::default().settings(); let size = self.default_size(); @@ -128,7 +126,7 @@ impl Window { } fn load_window_size(&self) { - let settings = &imp::Window::from_instance(self).settings; + let settings = Application::default().settings(); let width = settings.int("window-width"); let height = settings.int("window-height");