added javascript extensions dir and auto-reload after oauth flow

This commit is contained in:
adamhaley
2025-08-15 17:44:38 -07:00
parent 71c9369b59
commit 212578b42e
4 changed files with 156 additions and 4 deletions
+3
View File
@@ -12,6 +12,9 @@ NODE_DISPLAY_NAME_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS.update(RUN_DISPLAY)
NODE_DISPLAY_NAME_MAPPINGS.update(SETUP_DISPLAY)
# Define web directory for JavaScript extensions
WEB_DIRECTORY = "./web"
# Register OAuth callback route with ComfyUI server
def register_oauth_routes():
"""Register OAuth callback routes with ComfyUI's PromptServer"""
+34 -2
View File
@@ -46,6 +46,20 @@ class OAuthCallbackHandler:
print(f"[OAuthHandler] Auth code exchange successful")
# Send WebSocket message to trigger ComfyUI refresh
try:
from server import PromptServer
message_data = {
"type": "dropbox_oauth_complete",
"session_id": self.session_id,
"success": True,
"message": "✅ Dropbox connected successfully!"
}
PromptServer.instance.send_sync("dropbox_oauth_complete", message_data)
print(f"[OAuthHandler] Sent WebSocket notification for OAuth completion")
except Exception as e:
print(f"[OAuthHandler] Warning: Could not send WebSocket notification: {e}")
# Call completion callback if provided
if self.completion_callback:
await self.completion_callback(True, "✅ Dropbox connected successfully!")
@@ -110,9 +124,27 @@ async def handle_oauth_callback(request):
<html><body>
<h2>✅ Authorization Successful!</h2>
<p>{message}</p>
<p>You can now close this window and return to ComfyUI.</p>
<p>This window will close automatically and ComfyUI will refresh...</p>
<script>
setTimeout(() => window.close(), 3000);
// Notify parent window (ComfyUI) about successful OAuth
if (window.opener) {{
try {{
window.opener.postMessage({{
type: 'dropbox_oauth_complete',
success: true,
message: '{message}',
session_id: '{session_id}'
}}, '*');
console.log('Sent OAuth completion message to parent window');
}} catch (e) {{
console.error('Could not notify parent window:', e);
}}
}}
// Close this popup after a brief delay
setTimeout(() => {{
window.close();
}}, 2000);
</script>
</body></html>
""", content_type='text/html')
+2 -2
View File
@@ -155,12 +155,12 @@ class DropboxSetupNode:
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, this will complete automatically.\n\n⏳ Waiting for authorization..."
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] Session ID: {session_id}")
print(f"[DropboxSetup] Callback URL: {callback_url}")
except Exception as e:
print(f"[DropboxSetup] Could not auto-open browser: {e}")
message = f"🔗 Automatic OAuth Setup:\n\nPlease visit this URL to authorize:\n{oauth_url}\n\nAfter authorization, setup will complete automatically!"
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)
oauth_url = auth_temp.get_oauth_url()
+117
View File
@@ -0,0 +1,117 @@
// dropbox_oauth.js - ComfyUI extension for seamless Dropbox OAuth flow
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
// Track OAuth popup windows
let oauthPopup = null;
app.registerExtension({
name: "DropSendNode.OAuthHandler",
async setup() {
console.log("[DropSendNode] OAuth extension loaded");
// Listen for WebSocket messages about OAuth completion
api.addEventListener("dropbox_oauth_complete", (event) => {
console.log("[DropSendNode] Received OAuth completion notification via WebSocket", event.detail);
const data = event.detail;
if (data.success) {
console.log("[DropSendNode] OAuth successful - refreshing interface");
this.handleOAuthSuccess();
} else {
console.error("[DropSendNode] OAuth failed:", data.message);
}
});
// Listen for postMessage from OAuth popup window
window.addEventListener("message", (event) => {
if (event.data && event.data.type === 'dropbox_oauth_complete') {
console.log("[DropSendNode] Received OAuth completion notification via postMessage", event.data);
if (event.data.success) {
console.log("[DropSendNode] OAuth successful - refreshing interface");
this.handleOAuthSuccess();
} else {
console.error("[DropSendNode] OAuth failed:", event.data.message);
}
}
});
},
handleOAuthSuccess() {
// Close OAuth popup if it's open
if (oauthPopup && !oauthPopup.closed) {
oauthPopup.close();
console.log("[DropSendNode] Closed OAuth popup window");
}
// Refresh ComfyUI interface to update node UI
setTimeout(() => {
console.log("[DropSendNode] Refreshing ComfyUI interface");
window.location.reload();
}, 1500); // Small delay to ensure OAuth processing is complete
},
// Override the webbrowser.open functionality for better popup control
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;
nodeType.prototype.onExecuted = function(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 (originalExecute) {
return originalExecute.apply(this, arguments);
}
};
}
}
});
// Utility function to open OAuth in a small popup window
window.openDropboxOAuth = function(url) {
console.log("[DropSendNode] Opening OAuth popup:", url);
// Close existing popup if open
if (oauthPopup && !oauthPopup.closed) {
oauthPopup.close();
}
// Open small popup window
const popup = window.open(
url,
'dropbox_oauth',
'width=500,height=600,scrollbars=yes,resizable=yes,status=no,location=no,toolbar=no,menubar=no'
);
if (popup) {
oauthPopup = popup;
// Focus the popup
popup.focus();
// Monitor popup closure (optional - for fallback UI updates)
const checkClosed = setInterval(() => {
if (popup.closed) {
console.log("[DropSendNode] OAuth popup closed by user");
clearInterval(checkClosed);
oauthPopup = null;
}
}, 1000);
return popup;
} else {
console.error("[DropSendNode] Could not open OAuth popup - popup blocked?");
return null;
}
};