Skip to content

Commit

Permalink
fix: tabs: check if tabs are locked by sidebery before retrieving them
Browse files Browse the repository at this point in the history
it should prevent retrieving an incomplete list of tabs on init
also properly handle deferred events

ref: #1368 (comment)
  • Loading branch information
mbnuqw committed Jan 31, 2025
1 parent 96467cf commit d477d51
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/services/tabs.fg.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,37 @@ async function restoreTabsState(ignoreLockedTabs?: boolean): Promise<void> {
const ts = performance.now()
Logs.info('Tabs.restoreTabsState')

let isWindowTabsLocked
if (!ignoreLockedTabs) {
try {
isWindowTabsLocked = await IPC.bg('isWindowTabsLocked', Windows.id)
} catch {
isWindowTabsLocked = true
}
}

// Check if tabs are locked (sidebery is opening this window)
if (isWindowTabsLocked === true) {
Logs.info('Tabs.restoreTabsState: window tabs are locked (still opening?)')
throw Err.TabsLocked
}

// Clear deferredEventHandling
Tabs.deferredEventHandling = []

const results = await Promise.allSettled([
browser.tabs.query({ windowId: browser.windows.WINDOW_ID_CURRENT }),
browser.storage.local.get<Stored>('tabsDataCache'),
IPC.bg('isWindowTabsLocked', Windows.id),
])
const nativeTabs = Utils.settledOr(results[0], [])
const storage = Utils.settledOr(results[1], {})
const isWindowTabsLocked = Utils.settledOr(results[2], true)
let tabsWasMoved = false

// Check if tabs are locked right now
if (isWindowTabsLocked && !ignoreLockedTabs) {
if (isWindowTabsLocked === true) {
Logs.info('Tabs.restoreTabsState: window tabs are locked (still opening?)')
throw Err.TabsLocked
}
// Check if tabs were locked (sidebery opened this window)
if (isWindowTabsLocked) {
Logs.info('Tabs.restoreTabsState: window tabs were locked')
storage.tabsDataCache = [isWindowTabsLocked.cache]
tabsWasMoved = isWindowTabsLocked.move

// Clear deferredEventHandling
Tabs.deferredEventHandling = []
}

let tabs: Tab[] | undefined
Expand Down

0 comments on commit d477d51

Please sign in to comment.