Skip to content

Commit

Permalink
fix: windows: lock tabs init on early steps of createWithTabs
Browse files Browse the repository at this point in the history
This should prevent some cases of losing tabs structure on opening
window by sidebery e.g. opening snapshot window or moving tabs to new
window. (#1910)
  • Loading branch information
mbnuqw committed Jan 27, 2025
1 parent 7cbc197 commit 8422d5c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/services/windows.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,24 @@ export function closeWindowsPopup(): void {

const lockedWindowsTabs: Record<ID, boolean | { move: boolean; cache: TabCache[] }> = {}
export function isWindowTabsLocked(id: ID): boolean | { move: boolean; cache: TabCache[] } {
Logs.info('Windows.isWindowTabsLocked', id, typeof lockedWindowsTabs[id])
const locked = lockedWindowsTabs[id]
Logs.info('Windows.isWindowTabsLocked', id, typeof locked, globalTabsLockCounter)
if (locked && locked !== true) {
delete lockedWindowsTabs[id]
}
return locked ?? false
return locked ?? globalTabsLockCounter > 0
}

let globalTabsLockCounter = 0

export async function createWithTabs(
tabsInfo: ItemInfo[],
conf?: browser.windows.CreateData
): Promise<boolean> {
Logs.info('Windows.createWithTabs', tabsInfo.length)

globalTabsLockCounter++

if (!conf) conf = {}

const moveTabs = conf.tabId === MOVEID
Expand Down Expand Up @@ -172,8 +176,10 @@ export async function createWithTabs(
}
}
Logs.err('Windows: Cannot create window with tabs', err)
globalTabsLockCounter--
return false
}
globalTabsLockCounter--
if (!window.id || !window.tabs?.length) return true
lockedWindowsTabs[window.id] = true

Expand Down

0 comments on commit 8422d5c

Please sign in to comment.