From 7f30df6c2b578c4798113cc0f90bd1fd51d997fa Mon Sep 17 00:00:00 2001 From: adamhaley Date: Fri, 15 Aug 2025 17:51:22 -0700 Subject: [PATCH] oauth window now opening in a small, discreet window --- setup_dropbox_node.py | 9 +++++---- web/dropbox_oauth.js | 33 ++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/setup_dropbox_node.py b/setup_dropbox_node.py index 8e8f907..47b9e93 100644 --- a/setup_dropbox_node.py +++ b/setup_dropbox_node.py @@ -153,13 +153,14 @@ class DropboxSetupNode: oauth_handler.start_oauth_session(session_id, app_key_clean, app_secret_clean) try: - print(f"[DropboxSetup] Opening browser for automatic OAuth flow...") - webbrowser.open(oauth_url) - message = f"šŸš€ Automatic OAuth Started!\n\n🌐 Browser opened for authorization. After you authorize in Dropbox, ComfyUI will refresh automatically.\n\nā³ Waiting for authorization...\n\nšŸ”— OAuth URL: {oauth_url}" + print(f"[DropboxSetup] Setting up automatic OAuth popup...") + # We'll use JavaScript to open a proper popup window + message = f"šŸš€ Automatic OAuth Ready!\n\nšŸ–±ļø Click the link below to open a small popup window for authorization:\n\nšŸ”— {oauth_url}\n\n✨ After authorization, the popup will close and ComfyUI will refresh automatically!" print(f"[DropboxSetup] Session ID: {session_id}") print(f"[DropboxSetup] Callback URL: {callback_url}") + print(f"[DropboxSetup] OAuth URL ready for popup: {oauth_url}") except Exception as e: - print(f"[DropboxSetup] Could not auto-open browser: {e}") + print(f"[DropboxSetup] Error setting up OAuth: {e}") message = f"šŸ”— Automatic OAuth Setup:\n\nPlease visit this URL to authorize:\n{oauth_url}\n\nAfter authorization, ComfyUI will refresh automatically!" else: # Manual OAuth flow (original behavior) diff --git a/web/dropbox_oauth.js b/web/dropbox_oauth.js index 93bea74..cfadadf 100644 --- a/web/dropbox_oauth.js +++ b/web/dropbox_oauth.js @@ -54,24 +54,39 @@ app.registerExtension({ }, 1500); // Small delay to ensure OAuth processing is complete }, - // Override the webbrowser.open functionality for better popup control + // Override node execution to detect and handle OAuth URLs async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeData.name === "DropboxSetupNode") { console.log("[DropSendNode] Registered DropboxSetupNode enhancement"); // Add custom OAuth popup handling - const originalExecute = nodeType.prototype.onExecuted; + const originalExecuted = nodeType.prototype.onExecuted; nodeType.prototype.onExecuted = function(message) { + console.log("[DropSendNode] Node executed with message:", message); + // Check if this execution includes OAuth URL generation - if (message && typeof message === 'string' && message.includes('šŸš€ Automatic OAuth Started!')) { - console.log("[DropSendNode] Detected automatic OAuth start"); - - // Extract OAuth URL from the message (it should be in the callback setup) - // We'll enhance this to open a proper popup instead of a full tab + if (message && typeof message === 'object' && message.text && message.text[0]) { + const text = message.text[0]; + if (text.includes('šŸš€ Automatic OAuth Ready!')) { + console.log("[DropSendNode] Detected automatic OAuth ready message"); + + // Extract OAuth URL from the message + const urlMatch = text.match(/šŸ”— (https:\/\/www\.dropbox\.com\/oauth2\/authorize[^\s]+)/); + if (urlMatch) { + const oauthUrl = urlMatch[1]; + console.log("[DropSendNode] Extracted OAuth URL:", oauthUrl); + + // Auto-open the popup after a brief delay + setTimeout(() => { + console.log("[DropSendNode] Auto-opening OAuth popup..."); + window.openDropboxOAuth(oauthUrl); + }, 500); + } + } } - if (originalExecute) { - return originalExecute.apply(this, arguments); + if (originalExecuted) { + return originalExecuted.apply(this, arguments); } }; }