bookmarks: await save_post_file (now async) via run_on_app_loop
Two bookmark save sites updated for save_post_file's sync→async
signature change:
_save_bookmark_to_library: wraps the save in an async closure
and schedules via run_on_app_loop (already imported for the
thumbnail download path). Fire-and-forget; the source file is
already cached so the save is near-instant.
Save As action: same async wrapper pattern. The dialog runs
synchronously (user picks destination), then the actual file
copy is scheduled on the async loop.
Neither site passes a category_fetcher — bookmarks don't have a
direct reference to the active BooruClient. The save flow's
ensure_categories check in library_save.py short-circuits (the
fetcher is None), so template rendering uses whatever categories
are already on the post object. For bookmark→library saves, the
user typically hasn't clicked the post in the browse grid, so
categories may be empty — the template falls back to %id% for
category tokens, same as before. Full categorization on the
bookmark save path is a future enhancement (would require passing
the client through from main_window).
This commit is contained in:
parent
e2a666885f
commit
af9b68273c
@ -286,10 +286,14 @@ class BookmarksView(QWidget):
|
|||||||
return
|
return
|
||||||
src = Path(fav.cached_path)
|
src = Path(fav.cached_path)
|
||||||
post = self._bookmark_to_post(fav)
|
post = self._bookmark_to_post(fav)
|
||||||
try:
|
|
||||||
save_post_file(src, post, dest_dir, self._db)
|
async def _do():
|
||||||
except Exception as e:
|
try:
|
||||||
log.warning(f"Bookmark→library save #{fav.post_id} failed: {e}")
|
await save_post_file(src, post, dest_dir, self._db)
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"Bookmark→library save #{fav.post_id} failed: {e}")
|
||||||
|
|
||||||
|
run_on_app_loop(_do())
|
||||||
|
|
||||||
def _copy_to_library_unsorted(self, fav: Bookmark) -> None:
|
def _copy_to_library_unsorted(self, fav: Bookmark) -> None:
|
||||||
"""Copy a bookmarked image to the unsorted library folder."""
|
"""Copy a bookmarked image to the unsorted library folder."""
|
||||||
@ -404,13 +408,17 @@ class BookmarksView(QWidget):
|
|||||||
dest = save_file(self, "Save Image", default_name, f"Images (*{src.suffix})")
|
dest = save_file(self, "Save Image", default_name, f"Images (*{src.suffix})")
|
||||||
if dest:
|
if dest:
|
||||||
dest_path = Path(dest)
|
dest_path = Path(dest)
|
||||||
try:
|
|
||||||
save_post_file(
|
async def _do_save_as():
|
||||||
src, post, dest_path.parent, self._db,
|
try:
|
||||||
explicit_name=dest_path.name,
|
await save_post_file(
|
||||||
)
|
src, post, dest_path.parent, self._db,
|
||||||
except Exception as e:
|
explicit_name=dest_path.name,
|
||||||
log.warning(f"Bookmark Save As #{fav.post_id} failed: {e}")
|
)
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"Bookmark Save As #{fav.post_id} failed: {e}")
|
||||||
|
|
||||||
|
run_on_app_loop(_do_save_as())
|
||||||
elif action == unsave_lib:
|
elif action == unsave_lib:
|
||||||
from ..core.cache import delete_from_library
|
from ..core.cache import delete_from_library
|
||||||
# Pass db so templated filenames are matched and the meta
|
# Pass db so templated filenames are matched and the meta
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user