From a79cefbf63119200dc9ca932a155ff133def3530 Mon Sep 17 00:00:00 2001 From: rdbende Date: Sat, 6 Jul 2024 19:21:25 +0200 Subject: [PATCH] Delay saving settings until closing the app This radically improves the performance of resizing the window, as it no longer has to save the three updated values on every resize signal. The volume slider is also smoother now. --- cozy/application_settings.py | 1 + cozy/ui/main_view.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cozy/application_settings.py b/cozy/application_settings.py index fa59a654..a723ba65 100644 --- a/cozy/application_settings.py +++ b/cozy/application_settings.py @@ -9,6 +9,7 @@ class ApplicationSettings(EventSender): def __init__(self): super().__init__() + self._settings.delay() self._connect() def _connect(self): diff --git a/cozy/ui/main_view.py b/cozy/ui/main_view.py index 1710a201..e2b14a1f 100644 --- a/cozy/ui/main_view.py +++ b/cozy/ui/main_view.py @@ -31,6 +31,7 @@ class CozyUI(EventSender, metaclass=Singleton): application_settings = inject.attr(ApplicationSettings) _importer: Importer = inject.attr(Importer) _settings: SettingsModel = inject.attr(SettingsModel) + _gio_settings: Gio.Settings = inject.attr(Gio.Settings) _files: Files = inject.attr(Files) _player: Player = inject.attr(Player) _storages_view_model: StoragesViewModel = inject.attr(StoragesViewModel) @@ -67,8 +68,6 @@ def __init_window(self): self.window.set_application(self.app) self.window.connect("close-request", self.on_close) - self.window.connect("notify::default-width", self._on_window_size_allocate) - self.window.connect("notify::default-height", self._on_window_size_allocate) self._drop_target = Gtk.DropTarget() self._drop_target.set_gtypes([Gdk.FileList]) @@ -228,12 +227,16 @@ def on_close(self, widget, data=None): log.info("Closing.") self.fs_monitor.close() + self._save_window_size() + self._player.destroy() close_db() report.close() + log.info("Saving settings.") + self._gio_settings.apply() log.info("Closing app.") self.app.quit() log.info("App closed.") @@ -254,7 +257,7 @@ def _restore_window_size(self): else: self.window.unmaximize() - def _on_window_size_allocate(self, *_): + def _save_window_size(self, *_): width, height = self.window.get_default_size() self.application_settings.window_width = width self.application_settings.window_height = height