From e2f5726aec252cb26d41f4f7df7d02e3b52596cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Sk=C3=B6ld?= Date: Sat, 28 Jun 2025 21:41:54 +0200 Subject: [PATCH] Add toast for indexing images --- __init__.py | 11 ++++++----- web/js/settings.js | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index eda082a..a69e2e4 100644 --- a/__init__.py +++ b/__init__.py @@ -31,7 +31,7 @@ def index_images(): # Ensure directory exists if not images_dir.exists(): print(f"Warning: Directory not found: {images_dir}") - return False + return {"success": False} # Get all image files recursively image_files = [] @@ -59,11 +59,12 @@ def index_images(): json.dump(output, f, indent=2) print(f"Created index with {len(images)} images at {json_path}") - return True + return_data = {"success": True, "count": len(images)} + return return_data except Exception as e: print(f"Error creating image index: {str(e)}") - return False + return {"success": False} # Create image index @@ -89,8 +90,8 @@ async def get_enabled(request): @PromptServer.instance.routes.get(f"{API_PREFIX}/index") async def index_images_endpoint(request): - success = index_images() - return web.json_response({"success": success}) + data = index_images() + return web.json_response(data) @PromptServer.instance.routes.get(f"{API_PREFIX}/favorites") diff --git a/web/js/settings.js b/web/js/settings.js index 9baac50..ef57ed4 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -1,4 +1,4 @@ -import { SettingsHelper } from "./settings/ComfyHelper.js"; +import { SettingsHelper, UiHelper } from "./settings/ComfyHelper.js"; export const API_PREFIX = "/SyntaxHighlighting"; export const settingsHelper = new SettingsHelper("SyntaxHighlighting"); @@ -86,7 +86,24 @@ const settingsDefinitions = [ name: "Index Images", category: ["Syntax Highlighting", "Preview Image", "IndexImages"], type: SettingsHelper.ST.BUTTON("Index Images", async () => { - await fetch(`${API_PREFIX}/index`); + const response = await fetch(`${API_PREFIX}/index`); + if (!response.ok) { + settingsHelper.uiHelper.addToast( + UiHelper.Severity.ERROR, + "Indexing Images Failed", + "", + 5000 + ); + return; + } + + const data = await response.json(); + settingsHelper.uiHelper.addToast( + UiHelper.Severity.INFO, + "Indexing Images", + `Indexed ${data.count} images.`, + 5000 + ); SettingsHelper.PresetOnChange.reloadSettings(); }), tooltip: "Update images available for preview.",