This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After tab close, set next active tab immediately, and only if differe…
…nt from the tab muon will set. Avoids race condition that can occur after will-destory, before appState has been fully updated with any tab details that change from muon as a result of a tab closing. Fix #11981
- Loading branch information
Showing
7 changed files
with
358 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// static | ||
const activeTabsByWindow = new Map() | ||
|
||
const api = { | ||
/** | ||
* Inform this store that a tab is active for a window. | ||
* This information will be added to index 0 in the | ||
* active-tab history for the window. | ||
*/ | ||
setActiveTabForWindow: function (windowId, tabId) { | ||
const existing = activeTabsByWindow.get(windowId) | ||
if (existing) { | ||
existing.unshift(tabId) | ||
} else { | ||
activeTabsByWindow.set(windowId, [ tabId ]) | ||
} | ||
}, | ||
|
||
/** | ||
* Retrieve the tabId that was active at the specified history index, | ||
* 0 for most recent (default) | ||
*/ | ||
getActiveTabForWindow: function (windowId, historyIndex = 0) { | ||
// get history of active tabs for specified window | ||
const windowActiveTabs = activeTabsByWindow.get(windowId) | ||
// handle no history for specified window | ||
if (!windowActiveTabs || !windowActiveTabs.length) { | ||
return null | ||
} | ||
// verify specified index in active-tab history exists | ||
const lastIndex = windowActiveTabs.length - 1 | ||
if (lastIndex < historyIndex) { | ||
return null | ||
} | ||
// get tabId at specified index in active-tab history | ||
return windowActiveTabs[historyIndex] | ||
}, | ||
|
||
/** | ||
* Removes specified tab from active-tab history in specified window | ||
*/ | ||
clearTabFromWindow: function (windowId, tabId) { | ||
const windowActiveTabs = activeTabsByWindow.get(windowId) | ||
if (windowActiveTabs && windowActiveTabs.length) { | ||
activeTabsByWindow.set(windowId, windowActiveTabs.filter(previousTabId => previousTabId !== tabId)) | ||
} | ||
}, | ||
|
||
/** | ||
* Forget history of active tabs for specified window | ||
*/ | ||
clearTabbedWindow: function (windowId) { | ||
activeTabsByWindow.delete(windowId) | ||
} | ||
} | ||
|
||
module.exports = api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.