|
1 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public
|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
3 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */
|
4 |
| - |
5 | 4 | const appActions = require('../../js/actions/appActions')
|
6 | 5 | const windowActions = require('../../js/actions/windowActions')
|
7 | 6 | const tabActions = require('../common/actions/tabActions')
|
@@ -430,11 +429,6 @@ const api = {
|
430 | 429 | updateTab(tabId, changeInfo)
|
431 | 430 | })
|
432 | 431 |
|
433 |
| - process.on('chrome-tabs-removed', (tabId, windowId) => { |
434 |
| - appActions.tabClosed(tabId, windowId) |
435 |
| - cleanupWebContents(tabId) |
436 |
| - }) |
437 |
| - |
438 | 432 | app.on('web-contents-created', function (event, tab) {
|
439 | 433 | if (tab.isBackgroundPage() || !tab.isGuest()) {
|
440 | 434 | return
|
@@ -526,6 +520,14 @@ const api = {
|
526 | 520 | windowActions.gotResponseDetails(tabId, {status, newURL, originalURL, httpResponseCode, requestMethod, referrer, headers, resourceType})
|
527 | 521 | }
|
528 | 522 | })
|
| 523 | + |
| 524 | + tab.once('will-destroy', () => { |
| 525 | + const tabValue = getTabValue(tabId) |
| 526 | + if (tabValue) { |
| 527 | + const windowId = tabValue.get('windowId') |
| 528 | + appActions.tabClosed(tabId, windowId) |
| 529 | + } |
| 530 | + }) |
529 | 531 | })
|
530 | 532 |
|
531 | 533 | process.on('on-tab-created', (tab, options) => {
|
@@ -985,6 +987,86 @@ const api = {
|
985 | 987 |
|
986 | 988 | return nextTabId
|
987 | 989 | },
|
| 990 | + |
| 991 | + closeTabPage: (state, windowId, tabPageIndex) => { |
| 992 | + const tabsPerPage = Number(getSetting(settings.TABS_PER_PAGE)) |
| 993 | + const startTabIndex = tabPageIndex * tabsPerPage |
| 994 | + const pinnedTabsCount = tabState.getPinnedTabsByWindowId(state, windowId).size |
| 995 | + tabState.getTabsByWindowId(state, windowId) |
| 996 | + .sort((tab1, tab2) => tab1.get('index') - tab2.get('index')) |
| 997 | + .filter((tabValue) => !tabValue.get('pinned')) |
| 998 | + .slice(startTabIndex + pinnedTabsCount, startTabIndex + tabsPerPage + pinnedTabsCount) |
| 999 | + .forEach((tabValue) => { |
| 1000 | + const tab = getWebContents(tabValue.get('tabId')) |
| 1001 | + if (tab && !tab.isDestroyed()) { |
| 1002 | + tab.forceClose() |
| 1003 | + } |
| 1004 | + }) |
| 1005 | + state = api.updateTabsStateForWindow(state, windowId) |
| 1006 | + return state |
| 1007 | + }, |
| 1008 | + |
| 1009 | + closeTabsToLeft: (state, tabId) => { |
| 1010 | + const tabValue = tabState.getByTabId(state, tabId) |
| 1011 | + if (!tabValue) { |
| 1012 | + return state |
| 1013 | + } |
| 1014 | + const index = tabValue.get('index') |
| 1015 | + const windowId = tabValue.get('windowId') |
| 1016 | + const pinnedTabsCount = tabState.getPinnedTabsByWindowId(state, windowId).size |
| 1017 | + tabState.getTabsByWindowId(state, windowId) |
| 1018 | + .sort((tab1, tab2) => tab1.get('index') - tab2.get('index')) |
| 1019 | + .filter((tabValue) => !tabValue.get('pinned')) |
| 1020 | + .slice(0, index - pinnedTabsCount) |
| 1021 | + .forEach((tabValue) => { |
| 1022 | + const tab = getWebContents(tabValue.get('tabId')) |
| 1023 | + if (tab && !tab.isDestroyed()) { |
| 1024 | + tab.forceClose() |
| 1025 | + } |
| 1026 | + }) |
| 1027 | + state = api.updateTabsStateForWindow(state, windowId) |
| 1028 | + return state |
| 1029 | + }, |
| 1030 | + |
| 1031 | + closeTabsToRight: (state, tabId) => { |
| 1032 | + const tabValue = tabState.getByTabId(state, tabId) |
| 1033 | + if (!tabValue) { |
| 1034 | + return state |
| 1035 | + } |
| 1036 | + const index = tabValue.get('index') |
| 1037 | + const windowId = tabValue.get('windowId') |
| 1038 | + const pinnedTabsCount = tabState.getPinnedTabsByWindowId(state, windowId).size |
| 1039 | + tabState.getTabsByWindowId(state, windowId) |
| 1040 | + .sort((tab1, tab2) => tab1.get('index') - tab2.get('index')) |
| 1041 | + .filter((tabValue) => !tabValue.get('pinned')) |
| 1042 | + .slice(index + 1 - pinnedTabsCount) |
| 1043 | + .forEach((tabValue) => { |
| 1044 | + const tab = getWebContents(tabValue.get('tabId')) |
| 1045 | + if (tab && !tab.isDestroyed()) { |
| 1046 | + tab.forceClose() |
| 1047 | + } |
| 1048 | + }) |
| 1049 | + state = api.updateTabsStateForWindow(state, windowId) |
| 1050 | + return state |
| 1051 | + }, |
| 1052 | + |
| 1053 | + closeOtherTabs: (state, tabId) => { |
| 1054 | + const tabValue = tabState.getByTabId(state, tabId) |
| 1055 | + if (!tabValue) { |
| 1056 | + return state |
| 1057 | + } |
| 1058 | + const windowId = tabValue.get('windowId') |
| 1059 | + tabState.getTabsByWindowId(state, windowId) |
| 1060 | + .forEach((tabValue) => { |
| 1061 | + const tab = getWebContents(tabValue.get('tabId')) |
| 1062 | + if (tab && !tab.isDestroyed() && tabValue.get('tabId') !== tabId && !tabValue.get('pinned')) { |
| 1063 | + tab.forceClose() |
| 1064 | + } |
| 1065 | + }) |
| 1066 | + state = api.updateTabsStateForWindow(state, windowId) |
| 1067 | + return state |
| 1068 | + }, |
| 1069 | + |
988 | 1070 | debugTabs: (state) => {
|
989 | 1071 | console.log(tabState.getTabs(state)
|
990 | 1072 | .toJS()
|
@@ -1042,6 +1124,9 @@ const api = {
|
1042 | 1124 | }
|
1043 | 1125 | })
|
1044 | 1126 | return state
|
| 1127 | + }, |
| 1128 | + forgetTab: (tabId) => { |
| 1129 | + cleanupWebContents(tabId) |
1045 | 1130 | }
|
1046 | 1131 | }
|
1047 | 1132 |
|
|
0 commit comments