Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
[wip] Attempt to fix detaching previously-discarded tabs by undiscard…
Browse files Browse the repository at this point in the history
…ing first.

Does not work - whatever we call on the tab, it will be destroyed once the tab is detached.
  • Loading branch information
petemill committed Feb 14, 2018
1 parent 7d2fc77 commit 26ba05c
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,20 @@ const api = {
// If the current tab is pinned, then don't allow to drag out
return
}

// detach from current window
tab.detach(() => {
const tabWasActive = tabValue.get('active')
const detachedTabId = tabId
const attachToNewWindow = (tabToAttach) => {
const attachedTabId = tabToAttach.getId()
// handle tab has detached from window
// handle tab was the active tab of the window
if (tabValue.get('active')) {
if (tabWasActive) {
// decide and set next-active-tab muon override
const nextActiveTabIdForOldWindow = api.getNextActiveTabId(currentWindowId, tabId)
const nextActiveTabIdForOldWindow = api.getNextActiveTabId(currentWindowId, detachedTabId)
if (nextActiveTabIdForOldWindow !== null) {
api.setActive(nextActiveTabIdForOldWindow)
}
}
frameOpts = frameOpts.set('tabId', attachedTabId)
if (toWindowId == null || toWindowId === -1) {
if (shouldDebugTabEvents) {
console.log('creating new window for moved tab')
Expand All @@ -1077,7 +1079,8 @@ const api = {
appActions.newWebContentsAdded(toWindowId, frameOpts, tabValue)
}
// handle tab has made it to the new window
tab.once('did-attach', () => {
tabToAttach.once('did-attach', () => {
console.log('moved tab attached', getTabValue(attachedTabId))
if (shouldDebugTabEvents) {
console.log(`Tab attached to a new window, so setting the desired index`)
}
Expand All @@ -1087,7 +1090,26 @@ const api = {
api.setTabIndex(tabId, frameOpts.get('index'))
}
})
})
}
if (tabValue.get('discarded')) {
console.log('is discarded')
// we cannot move a discarded tab due to the tab getting disposed if we try
// therefore undiscard it by calling reload(), and then detach
tab.once('load-start', () => {
tab.once('did-detach', () => {
attachToNewWindow(tab)
})
tab.detach()
})
// tab.attach(tabValue.get('windowId'))
console.log('tab is discarded in window, so reloading before detach', tabValue.get('windowId'))
tab.reload()
} else {
tab.once('did-detach', () => {
attachToNewWindow(tab)
})
tab.detach()
}
}
},

Expand Down

0 comments on commit 26ba05c

Please sign in to comment.