From 148c1c3a26c6c94dd67e6889f1257cd439406b62 Mon Sep 17 00:00:00 2001 From: pax Date: Sat, 4 Apr 2026 19:49:09 -0500 Subject: [PATCH] Session cache option, zip conversion fix, page boundary nav - Add "Clear cache on exit" checkbox in Settings > Cache - Fix ugoira zip conversion: don't crash if frames fail, verify gif exists before deleting zip - Arrow key past last/first post loads next/prev page --- booru_viewer/core/cache.py | 6 ++++-- booru_viewer/gui/app.py | 7 +++++++ booru_viewer/gui/settings.py | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/booru_viewer/core/cache.py b/booru_viewer/core/cache.py index e50bb90..40a518a 100644 --- a/booru_viewer/core/cache.py +++ b/booru_viewer/core/cache.py @@ -68,12 +68,14 @@ def _convert_ugoira_to_gif(zip_path: Path) -> Path: except Exception: continue if not frames: - raise ValueError("Zip contains no image frames") + # Can't convert — just return the zip path as-is + return zip_path frames[0].save( gif_path, save_all=True, append_images=frames[1:], duration=80, loop=0, disposal=2, ) - zip_path.unlink() + if gif_path.exists(): + zip_path.unlink() return gif_path diff --git a/booru_viewer/gui/app.py b/booru_viewer/gui/app.py index 93bd6c7..7351519 100644 --- a/booru_viewer/gui/app.py +++ b/booru_viewer/gui/app.py @@ -787,6 +787,10 @@ class BooruApp(QMainWindow): if 0 <= idx < len(self._posts): self._grid._select(idx) self._on_post_activated(idx) + elif idx >= len(self._posts) and direction == 1 and len(self._posts) > 0: + self._next_page() + elif idx < 0 and direction == -1 and self._current_page > 1: + self._prev_page() def _favorite_from_preview(self) -> None: idx = self._grid.selected_index @@ -1335,6 +1339,9 @@ class BooruApp(QMainWindow): thumbs[index].set_saved_locally(True) def closeEvent(self, event) -> None: + if self._db.get_setting_bool("clear_cache_on_exit"): + from ..core.cache import clear_cache + clear_cache(clear_images=True, clear_thumbnails=True) self._db.close() super().closeEvent(event) diff --git a/booru_viewer/gui/settings.py b/booru_viewer/gui/settings.py index 6f0b725..c2cfd90 100644 --- a/booru_viewer/gui/settings.py +++ b/booru_viewer/gui/settings.py @@ -166,6 +166,10 @@ class SettingsDialog(QDialog): self._auto_evict.setChecked(self._db.get_setting_bool("auto_evict")) limits_layout.addRow("", self._auto_evict) + self._clear_on_exit = QCheckBox("Clear cache on exit (session-only cache)") + self._clear_on_exit.setChecked(self._db.get_setting_bool("clear_cache_on_exit")) + limits_layout.addRow("", self._clear_on_exit) + layout.addWidget(limits_group) # Cache actions @@ -614,6 +618,7 @@ class SettingsDialog(QDialog): self._db.set_setting("preload_thumbnails", "1" if self._preload.isChecked() else "0") self._db.set_setting("max_cache_mb", str(self._max_cache.value())) self._db.set_setting("auto_evict", "1" if self._auto_evict.isChecked() else "0") + self._db.set_setting("clear_cache_on_exit", "1" if self._clear_on_exit.isChecked() else "0") if self._file_dialog_combo is not None: self._db.set_setting("file_dialog_platform", self._file_dialog_combo.currentText()) self.settings_changed.emit()