From cc1ea76d9de4c807514c6afee8913cedd176483e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 3 Jun 2014 16:48:21 +0200 Subject: [PATCH] Clean up shutdown --- TODO | 2 -- qutebrowser/app.py | 40 ++++++++++++++-------------------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/TODO b/TODO index cd5354b66..96dc0a4b6 100644 --- a/TODO +++ b/TODO @@ -20,8 +20,6 @@ Before 0.1 Style ===== -- somehow clean up init() and save() calls - New big features ================ diff --git a/qutebrowser/app.py b/qutebrowser/app.py index f293be7e8..c4950df36 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -583,38 +583,26 @@ class QuteBrowser(QApplication): For some reason lastWindowClosing sometimes seem to get emitted twice, so we make sure we only run once here. """ - # pylint: disable=too-many-branches if self._shutting_down: return self._shutting_down = True log.destroy.debug("Shutting down...") - # Save config + to_save = [] + # Save everything if self.config.get('general', 'auto-save-config'): + to_save.append(("config", self.config.save)) + to_save += [("command history", self.cmd_history.save), + ("window geometry", self._save_geometry), + ("window geometry", self.stateconfig.save), + ("cookies", self.cookiejar.save), + ("quickmarks", quickmarks.save)] + for what, handler in to_save: + log.destroy.debug("Saving {} (handler: {})".format( + what, handler.__qualname__)) try: - self.config.save() + handler() except AttributeError: - log.destroy.warning("Could not save config.") - # Save command history - try: - self.cmd_history.save() - except AttributeError: - log.destroy.warning("Could not save command history.") - # Save window state - try: - self._save_geometry() - self.stateconfig.save() - except AttributeError: - log.destroy.warning("Could not save window geometry.") - # Save cookies - try: - self.cookiejar.save() - except AttributeError: - log.destroy.warning("Could not save cookies.") - # Save quickmarks - try: - quickmarks.save() - except AttributeError: - log.destroy.warning("Could not save quickmarks.") + log.destroy.warning("Could not save {}.".format(what)) # Shut down tabs try: self.mainwindow.tabs.shutdown_complete.connect(partial( @@ -632,8 +620,8 @@ class QuteBrowser(QApplication): except AttributeError: log.destroy.warning("No networkmanager to shut down.") self._maybe_quit('networkmanager') + # Re-enable faulthandler to stdout, then remove crash log if self._crashlogfile is not None: - # Re-enable faulthandler to stdout, then remove crash log if sys.stderr is not None: faulthandler.enable() else: