diff --git a/src/webdrop_bridge/ui/bridge_script_intercept.js b/src/webdrop_bridge/ui/bridge_script_intercept.js index 6f627aa..83fa803 100644 --- a/src/webdrop_bridge/ui/bridge_script_intercept.js +++ b/src/webdrop_bridge/ui/bridge_script_intercept.js @@ -88,7 +88,7 @@ for (var i = 0; i < angularDragHandlers.length; i++) { var h = angularDragHandlers[i]; if (h.target === document || h.target === e.target || - (h.target.contains && h.target.contains(e.target))) {https://devagravitystg.file.core.windows.net/devagravitysync/anPGZszKzgKaSz1SIx2HFgduy/weiss_ORIGINAL.jpg + (h.target.contains && h.target.contains(e.target))) { try { h.listener.call(e.target, e); handled++; @@ -102,10 +102,27 @@ // NOW check if we should intercept if (e.altKey && currentDragUrl) { - var isAzure = /^https?:\/\/.+\.file\.core\.windows\.net\//i.test(currentDragUrl); - var isZDrive = /^z:/i.test(currentDragUrl); + var shouldIntercept = false; - if (isAzure || isZDrive) { + // Check against configured URL mappings + if (window.webdropConfig && window.webdropConfig.urlMappings) { + for (var j = 0; j < window.webdropConfig.urlMappings.length; j++) { + var mapping = window.webdropConfig.urlMappings[j]; + if (currentDragUrl.toLowerCase().startsWith(mapping.url_prefix.toLowerCase())) { + shouldIntercept = true; + console.log('[Intercept] URL matches mapping for:', mapping.local_path); + break; + } + } + } else { + // Fallback: Check for legacy Z: drive pattern if no config available + shouldIntercept = /^z:/i.test(currentDragUrl); + if (shouldIntercept) { + console.warn('[Intercept] Using fallback Z: drive pattern (no URL mappings configured)'); + } + } + + if (shouldIntercept) { console.log('%c[Intercept] PREVENTING browser drag, using Qt', 'background: #F44336; color: white; font-weight: bold; padding: 4px 8px;'); diff --git a/src/webdrop_bridge/ui/main_window.py b/src/webdrop_bridge/ui/main_window.py index cfaeb54..be7f17e 100644 --- a/src/webdrop_bridge/ui/main_window.py +++ b/src/webdrop_bridge/ui/main_window.py @@ -408,6 +408,7 @@ class MainWindow(QMainWindow): before any page scripts that might interfere with drag events. Embeds qwebchannel.js inline to avoid CSP issues with qrc:// URLs. + Injects configuration that bridge script uses for dynamic URL pattern matching. """ from PySide6.QtCore import QFile, QIODevice @@ -427,6 +428,9 @@ class MainWindow(QMainWindow): else: logger.warning("Failed to load qwebchannel.js from resources") + # Generate configuration injection script + config_code = self._generate_config_injection_script() + # Load bridge script from file # Using intercept script - prevents browser drag, hands off to Qt script_path = Path(__file__).parent / "bridge_script_intercept.js" @@ -444,11 +448,8 @@ class MainWindow(QMainWindow): except (OSError, IOError) as e: logger.warning(f"Download interceptor not found: {e}") - # Combine qwebchannel.js + bridge script + download interceptor (inline to avoid CSP) - if qwebchannel_code: - combined_code = qwebchannel_code + "\n\n" + bridge_code - else: - combined_code = bridge_code + # Combine: qwebchannel.js + config + bridge script + download interceptor + combined_code = qwebchannel_code + "\n\n" + config_code + "\n\n" + bridge_code if download_interceptor_code: combined_code += "\n\n" + download_interceptor_code @@ -459,6 +460,41 @@ class MainWindow(QMainWindow): except (OSError, IOError) as e: logger.warning(f"Failed to load bridge script: {e}") + def _generate_config_injection_script(self) -> str: + """Generate JavaScript code that injects configuration. + + Creates a script that sets window.webdropConfig with the current + URL mappings, allowing the bridge script to dynamically check + against configured patterns instead of hardcoded values. + + Returns: + JavaScript code as string + """ + # Convert URL mappings to format expected by bridge script + mappings = [] + for mapping in self.config.url_mappings: + mappings.append({ + "url_prefix": mapping.url_prefix, + "local_path": mapping.local_path + }) + + # Generate JavaScript code + config_js = """ +(function() { + // WebDrop Bridge - Configuration Injection + window.webdropConfig = """ + json.dumps({ + "urlMappings": mappings + }) + """; + console.log('[WebDrop Config] Injected configuration with', + window.webdropConfig.urlMappings.length, 'URL mappings'); + for (var i = 0; i < window.webdropConfig.urlMappings.length; i++) { + var m = window.webdropConfig.urlMappings[i]; + console.log('[WebDrop Config] Mapping', (i+1) + ':', m.url_prefix, '→', m.local_path); + } +})(); +""" + return config_js + def _inject_drag_bridge(self, html_content: str) -> str: """Return HTML content unmodified.