fix: improve child webviewer window positioning and movement tracking

- Add focus/blur event listeners to trigger bounds updates when window becomes active
- Enhance bounds tracking system to better handle main window movement
- Improve responsiveness of child window positioning during window operations
- Add proper cleanup for new event listeners
- Maintain existing main process move/resize event handlers for comprehensive tracking

This should fix the issue where child webviewer windows drift away when moving the main window.
This commit is contained in:
spencrmartin
2025-11-12 14:18:27 -05:00
parent f614c83d52
commit 96efcb12c7
+6 -2
View File
@@ -316,7 +316,7 @@ export function WebViewer({
};
}, [childWindowCreated, webViewerContext, unifiedSidecarContext]);
// Update child window bounds when container resizes (throttled)
// Update child window bounds when container resizes or window moves (throttled)
useEffect(() => {
if (!childWindowCreated || !containerRef.current) return;
@@ -358,9 +358,11 @@ export function WebViewer({
const resizeObserver = new ResizeObserver(throttledUpdateBounds);
resizeObserver.observe(containerRef.current);
// Listen for window resize and scroll events
// Listen for window resize, scroll, and focus events
window.addEventListener('resize', throttledUpdateBounds);
window.addEventListener('scroll', throttledUpdateBounds);
window.addEventListener('focus', throttledUpdateBounds);
window.addEventListener('blur', throttledUpdateBounds);
// Use MutationObserver with broader scope to catch drag operations
const mutationObserver = new MutationObserver((mutations) => {
@@ -469,6 +471,8 @@ export function WebViewer({
mutationObserver.disconnect();
window.removeEventListener('resize', throttledUpdateBounds);
window.removeEventListener('scroll', throttledUpdateBounds);
window.removeEventListener('focus', throttledUpdateBounds);
window.removeEventListener('blur', throttledUpdateBounds);
};
}, [childWindowCreated]);