Skip to content

Commit

Permalink
Delay saving settings until closing the app
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rdbende committed Jul 6, 2024
1 parent ad9cda8 commit a79cefb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions cozy/application_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ApplicationSettings(EventSender):

def __init__(self):
super().__init__()
self._settings.delay()
self._connect()

def _connect(self):
Expand Down
9 changes: 6 additions & 3 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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.")
Expand All @@ -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
Expand Down

0 comments on commit a79cefb

Please sign in to comment.