Skip to content

Commit

Permalink
fix: dnd: incorrect checking of consumed drop event in other sidebars
Browse files Browse the repository at this point in the history
(resolves #1554)
  • Loading branch information
mbnuqw committed Apr 10, 2024
1 parent eef3964 commit 64fcd86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/services/drag-and-drop.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,17 @@ export async function onDragEnd(e: DragEvent): Promise<void> {
// Check if the drop event was consumed by another sidebar
const requestingDropStatus: Promise<boolean>[] = []
for (const win of Windows.otherWindows) {
if (win.id) requestingDropStatus.push(IPC.sidebar(win.id, 'isDropEventConsumed'))
if (win.id) {
const gettingStatus = browser.sidebarAction.isOpen({ windowId: win.id }).then(isOpen => {
if (isOpen && win.id) return IPC.sidebar(win.id, 'isDropEventConsumed')
else return false
})
requestingDropStatus.push(gettingStatus)
}
}
let consumed
try {
consumed = await Promise.all(requestingDropStatus)
consumed = await Utils.deadline(1500, [], Promise.all(requestingDropStatus))
} catch (err) {
Logs.err('DnD.onDragEnd: Cannot get drop status from other windows', err)
return
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export async function sleep(ms = 1000): Promise<void> {
})
}

/**
* Deadline
*/
export function deadline<T>(deadline: number, fallback: T, promise: Promise<T>): Promise<T> {
return new Promise((ok, meh) => {
setTimeout(() => ok(fallback), deadline)
promise.then(ok).catch(meh)
})
}

/**
* Bytes to readable string
*/
Expand Down

0 comments on commit 64fcd86

Please sign in to comment.