diff --git a/CHANGELOG.md b/CHANGELOG.md index 4adcd28..1899a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#92](https://github.com/utensils/comfyui-nix/issues/92)) ### Fixed +- The model downloader now subscribes to `model_download_progress` through + ComfyUI's API client (`window.comfyAPI.api.api`). It previously registered + only through the legacy `window.api`, which current frontends don't define, + so progress arrived solely through a WebSocket monkey-patch and frontend + 1.57 logged `Unknown message type model_download_progress`. The socket patch + remains as a fallback when no API client is found. - Apple Silicon comfy-kitchen operators use list annotations supported by PyTorch 2.5.1, preventing an import failure during operator registration. - Apple Silicon PyTorch shared-memory helpers close inherited resource-tracker diff --git a/src/custom_nodes/model_downloader/js/model_downloader.js b/src/custom_nodes/model_downloader/js/model_downloader.js index a97cd9a..c44c063 100644 --- a/src/custom_nodes/model_downloader/js/model_downloader.js +++ b/src/custom_nodes/model_downloader/js/model_downloader.js @@ -4,45 +4,32 @@ if (window.location.hostname === 'localhost' || window.location.hostname === '12 console.log("[MODEL_DOWNLOADER] Loading model downloader extension..."); } +// Forward a progress event to the core module, if it has loaded. +function forwardProgress(event) { + if (window.modelDownloader && typeof window.modelDownloader.handleMessageEvent === 'function') { + window.modelDownloader.handleMessageEvent(event); + } +} + +// Resolve ComfyUI's API client. Current frontends expose it as +// window.comfyAPI.api.api (and app.api); window.api is legacy. +function getComfyApi() { + return window.comfyAPI?.api?.api || window.app?.api || window.api || null; +} + // Register message handler as early as possible function registerMessageHandler() { try { - // Register the model_download_progress message type in all possible ways - // to ensure compatibility with different ComfyUI versions - - // Method 1: Add to the reportedUnknownMessageTypes set if it exists - if (window.api && typeof window.api.reportedUnknownMessageTypes !== 'undefined') { - if (!(window.api.reportedUnknownMessageTypes instanceof Set)) { - window.api.reportedUnknownMessageTypes = new Set(); - } - window.api.reportedUnknownMessageTypes.add('model_download_progress'); + // Preferred: subscribe through the API client. This delivers each + // model_download_progress message as a CustomEvent and registers the + // type, so the frontend no longer logs "Unknown message type". + const comfyApi = getComfyApi(); + if (comfyApi && typeof comfyApi.addEventListener === 'function') { + comfyApi.addEventListener('model_download_progress', forwardProgress); + return; } - - // Method 2: Using API extension system (newer ComfyUI versions) - if (window.api && typeof window.api.registerExtension === 'function') { - window.api.registerExtension({ - name: "model_downloader", - init() { - window.api.addEventListener("model_download_progress", function(data) { - // Forward to our event handler function if available - if (window.modelDownloader && typeof window.modelDownloader.handleMessageEvent === 'function') { - window.modelDownloader.handleMessageEvent(data); - } - }); - } - }); - } - - // Method 3: Using custom API message handler (alternative newer ComfyUI versions) - if (window.app && typeof window.app.registerMessageHandler === 'function') { - window.app.registerMessageHandler('model_download_progress', function(event) { - if (window.modelDownloader && typeof window.modelDownloader.handleMessageEvent === 'function') { - window.modelDownloader.handleMessageEvent(event); - } - }); - } - - // Method 4: Direct WebSocket patching (fallback for older ComfyUI versions) + + // Fallback: patch the WebSocket directly when no API client is found function patchWebSocket() { // Find the WebSocket object to patch let socket = null; @@ -69,10 +56,7 @@ function registerMessageHandler() { try { const message = JSON.parse(event.data); if (message.type === 'model_download_progress') { - // Forward to our handler - if (window.modelDownloader && typeof window.modelDownloader.handleMessageEvent === 'function') { - window.modelDownloader.handleMessageEvent(message); - } + forwardProgress(message); } } catch (e) { // Ignore JSON parse errors