feat: Enhance drag interception with dynamic URL pattern matching configuration injection
This commit is contained in:
parent
f385ee6410
commit
0eba82b8af
2 changed files with 62 additions and 9 deletions
|
|
@ -88,7 +88,7 @@
|
||||||
for (var i = 0; i < angularDragHandlers.length; i++) {
|
for (var i = 0; i < angularDragHandlers.length; i++) {
|
||||||
var h = angularDragHandlers[i];
|
var h = angularDragHandlers[i];
|
||||||
if (h.target === document || h.target === e.target ||
|
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 {
|
try {
|
||||||
h.listener.call(e.target, e);
|
h.listener.call(e.target, e);
|
||||||
handled++;
|
handled++;
|
||||||
|
|
@ -102,10 +102,27 @@
|
||||||
|
|
||||||
// NOW check if we should intercept
|
// NOW check if we should intercept
|
||||||
if (e.altKey && currentDragUrl) {
|
if (e.altKey && currentDragUrl) {
|
||||||
var isAzure = /^https?:\/\/.+\.file\.core\.windows\.net\//i.test(currentDragUrl);
|
var shouldIntercept = false;
|
||||||
var isZDrive = /^z:/i.test(currentDragUrl);
|
|
||||||
|
|
||||||
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',
|
console.log('%c[Intercept] PREVENTING browser drag, using Qt',
|
||||||
'background: #F44336; color: white; font-weight: bold; padding: 4px 8px;');
|
'background: #F44336; color: white; font-weight: bold; padding: 4px 8px;');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -408,6 +408,7 @@ class MainWindow(QMainWindow):
|
||||||
before any page scripts that might interfere with drag events.
|
before any page scripts that might interfere with drag events.
|
||||||
|
|
||||||
Embeds qwebchannel.js inline to avoid CSP issues with qrc:// URLs.
|
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
|
from PySide6.QtCore import QFile, QIODevice
|
||||||
|
|
||||||
|
|
@ -427,6 +428,9 @@ class MainWindow(QMainWindow):
|
||||||
else:
|
else:
|
||||||
logger.warning("Failed to load qwebchannel.js from resources")
|
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
|
# Load bridge script from file
|
||||||
# Using intercept script - prevents browser drag, hands off to Qt
|
# Using intercept script - prevents browser drag, hands off to Qt
|
||||||
script_path = Path(__file__).parent / "bridge_script_intercept.js"
|
script_path = Path(__file__).parent / "bridge_script_intercept.js"
|
||||||
|
|
@ -444,11 +448,8 @@ class MainWindow(QMainWindow):
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
logger.warning(f"Download interceptor not found: {e}")
|
logger.warning(f"Download interceptor not found: {e}")
|
||||||
|
|
||||||
# Combine qwebchannel.js + bridge script + download interceptor (inline to avoid CSP)
|
# Combine: qwebchannel.js + config + bridge script + download interceptor
|
||||||
if qwebchannel_code:
|
combined_code = qwebchannel_code + "\n\n" + config_code + "\n\n" + bridge_code
|
||||||
combined_code = qwebchannel_code + "\n\n" + bridge_code
|
|
||||||
else:
|
|
||||||
combined_code = bridge_code
|
|
||||||
|
|
||||||
if download_interceptor_code:
|
if download_interceptor_code:
|
||||||
combined_code += "\n\n" + download_interceptor_code
|
combined_code += "\n\n" + download_interceptor_code
|
||||||
|
|
@ -459,6 +460,41 @@ class MainWindow(QMainWindow):
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
logger.warning(f"Failed to load bridge script: {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:
|
def _inject_drag_bridge(self, html_content: str) -> str:
|
||||||
"""Return HTML content unmodified.
|
"""Return HTML content unmodified.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue