fix(electrobun): resize race condition — use cached frame, not async getFrame
This commit is contained in:
parent
31338ad949
commit
31e7c422e4
1 changed files with 23 additions and 10 deletions
|
|
@ -105,9 +105,8 @@
|
|||
isDragging = true;
|
||||
dragStartX = e.screenX;
|
||||
dragStartY = e.screenY;
|
||||
appRpc.request['window.getFrame']({}).then(f => {
|
||||
winStartX = f.x; winStartY = f.y;
|
||||
}).catch(() => {});
|
||||
winStartX = cachedFrame.x;
|
||||
winStartY = cachedFrame.y;
|
||||
e.preventDefault();
|
||||
}
|
||||
function onDragMove(e: MouseEvent) {
|
||||
|
|
@ -116,30 +115,37 @@
|
|||
const dy = e.screenY - dragStartY;
|
||||
appRpc.request['window.setPosition']({ x: winStartX + dx, y: winStartY + dy }).catch(() => {});
|
||||
}
|
||||
function onDragEnd() { isDragging = false; saveWindowFrame(); }
|
||||
function onDragEnd() { if (isDragging) { updateCachedFrame(); saveWindowFrame(); } isDragging = false; }
|
||||
|
||||
// ── Window resize (edge handles) ───────────────────────────
|
||||
let isResizing = false;
|
||||
let resizeReady = false;
|
||||
let resizeEdge = '';
|
||||
let resizeStartX = 0;
|
||||
let resizeStartY = 0;
|
||||
let resizeFrame = { x: 0, y: 0, width: 0, height: 0 };
|
||||
// Cache last known frame to avoid async race
|
||||
let cachedFrame = { x: 100, y: 100, width: 1400, height: 900 };
|
||||
const MIN_W = 600;
|
||||
const MIN_H = 400;
|
||||
|
||||
// Keep cached frame updated on drag/resize end
|
||||
function updateCachedFrame() {
|
||||
appRpc.request['window.getFrame']({}).then(f => { cachedFrame = { ...f }; }).catch(() => {});
|
||||
}
|
||||
|
||||
function onResizeStart(e: MouseEvent, edge: string) {
|
||||
isResizing = true;
|
||||
resizeEdge = edge;
|
||||
resizeStartX = e.screenX;
|
||||
resizeStartY = e.screenY;
|
||||
appRpc.request['window.getFrame']({}).then(f => {
|
||||
resizeFrame = { ...f };
|
||||
}).catch(() => {});
|
||||
resizeFrame = { ...cachedFrame };
|
||||
isResizing = true;
|
||||
resizeReady = true;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
function onResizeMove(e: MouseEvent) {
|
||||
if (!isResizing) return;
|
||||
if (!isResizing || !resizeReady) return;
|
||||
const dx = e.screenX - resizeStartX;
|
||||
const dy = e.screenY - resizeStartY;
|
||||
let { x, y, width, height } = resizeFrame;
|
||||
|
|
@ -149,7 +155,11 @@
|
|||
if (resizeEdge.includes('n')) { const nh = Math.max(MIN_H, height - dy); y = y + (height - nh); height = nh; }
|
||||
appRpc.request['window.setFrame']({ x, y, width, height }).catch(() => {});
|
||||
}
|
||||
function onResizeEnd() { isResizing = false; saveWindowFrame(); }
|
||||
function onResizeEnd() {
|
||||
if (isResizing) { updateCachedFrame(); saveWindowFrame(); }
|
||||
isResizing = false;
|
||||
resizeReady = false;
|
||||
}
|
||||
|
||||
// ── Window frame persistence (debounced 500ms) ──────────────
|
||||
let frameSaveTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
|
@ -249,6 +259,9 @@
|
|||
setAgentToastFn(showToast);
|
||||
setupErrorBoundary();
|
||||
|
||||
// Seed cached frame from actual window position
|
||||
updateCachedFrame();
|
||||
|
||||
// Window drag + resize global listeners
|
||||
const handleGlobalMove = (e: MouseEvent) => { onDragMove(e); onResizeMove(e); };
|
||||
const handleGlobalUp = () => { onDragEnd(); onResizeEnd(); };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue