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

Commit

Permalink
New debug menu option - 'Allow Manual Tab Discarding' will create 'Di…
Browse files Browse the repository at this point in the history
…scard' tab context menu command
  • Loading branch information
petemill committed Feb 13, 2018
1 parent ef5a356 commit eebe586
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 4 deletions.
18 changes: 15 additions & 3 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const settings = require('../../js/constants/settings')

// State
const {getByTabId} = require('../common/state/tabState')
const tabState = require('../../app/common/state/tabState')
const tabState = require('../common/state/tabState')
const appStore = require('../../js/stores/appStore')

// Actions
Expand Down Expand Up @@ -485,7 +485,7 @@ const createHelpSubmenu = () => {
return submenu
}

const createDebugSubmenu = () => {
const createDebugSubmenu = (state) => {
return [
{
// Makes future renderer processes pause when they are created until a debugger appears.
Expand Down Expand Up @@ -533,6 +533,14 @@ const createDebugSubmenu = () => {
const win = BrowserWindow.getActiveWindow()
appActions.noReportStateModeClicked(win.id)
}
}, {
label: 'Allow manual tab discarding',
type: 'checkbox',
checked: !!getSetting(settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD),
click: function (menuItem, browserWindow, e) {
console.log('clicked', menuItem)
appActions.changeSetting(settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD, menuItem.checked)
}
}
]
}
Expand Down Expand Up @@ -570,7 +578,7 @@ const createMenu = (state) => {
]

if (process.env.NODE_ENV === 'development' || process.env.BRAVE_ENABLE_DEBUG_MENU !== undefined) {
template.push({ label: 'Debug', submenu: createDebugSubmenu() })
template.push({ label: 'Debug', submenu: createDebugSubmenu(state) })
}

if (isDarwin) {
Expand Down Expand Up @@ -661,6 +669,10 @@ const doAction = (state, action) => {
// Update the checkbox next to "Bookmarks Toolbar" (Bookmarks menu)
setMenuItemChecked(state, locale.translation('bookmarksToolbar'), action.value)
}
if (action.key === settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD) {
console.log('change tab disc', action.value)
setMenuItemChecked(state, 'Allow manual tab discarding', action.value)
}
break
case windowConstants.WINDOW_UNDO_CLOSED_FRAME:
{
Expand Down
7 changes: 7 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ const tabsReducer = (state, action, immutableAction) => {
state = tabs.closeOtherTabs(state, tabId)
break
}
case appConstants.APP_DISCARD_TAB_REQUESTED: {
const tabId = action.get('tabId')
setImmediate(() => {
tabs.discard(tabId)
})
break
}
case appConstants.APP_CREATE_TAB_REQUESTED:
if (action.getIn(['createProperties', 'windowId']) == null) {
const senderWindowId = action.getIn(['senderWindowId'])
Expand Down
12 changes: 12 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,18 @@ const api = {
}
},

discard: (tabId) => {
const tab = webContentsCache.getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.discard()
} else {
console.error(
`Asked for tab ${tabId} to be discarded but ` +
(tab ? 'tab was not in cache' : 'tab was discarded')
)
}
},

loadURL: (action) => {
action = makeImmutable(action)
const tabId = action.get('tabId')
Expand Down
7 changes: 7 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ const appActions = {
})
},

discardTabRequested: function (tabId) {
dispatch({
actionType: appConstants.APP_DISCARD_TAB_REQUESTED,
tabId
})
},

/**
* A request for a new tab has been made with the specified createProperties
* @param {Object} createProperties
Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ module.exports = {
'general.is-default-browser': null,
'notification-add-funds-timestamp': null,
'notification-reconcile-soon-timestamp': null,

// debug
'debug.manual-tab-discard.enabled': false,
// DEPRECATED settings
// DO NOT REMOVE OR CHANGE THESE VALUES
// ########################
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const appConstants = {
APP_CLOSE_TABS_TO_LEFT_MENU_ITEM_CLICKED: _,
APP_CLOSE_TABS_TO_RIGHT_MENU_ITEM_CLICKED: _,
APP_CLOSE_OTHER_TABS_MENU_ITEM_CLICKED: _,
APP_DISCARD_TAB_REQUESTED: _,
APP_TAB_ATTACHED: _,
APP_TAB_WILL_ATTACH: _,
APP_TAB_ACTIVATE_REQUESTED: _,
Expand Down
2 changes: 2 additions & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const settings = {
PINTEREST_ENABLED: 'extensions.pinterest.enabled',
METAMASK_ENABLED: 'extensions.metamask.enabled',
METAMASK_PROMPT_DISMISSED: 'extensions.metamask.promptDismissed',
// Debug settings
DEBUG_ALLOW_MANUAL_TAB_DISCARD: 'debug.manual-tab-discard.enabled',

// DEPRECATED settings
// DO NOT REMOVE OR CHANGE THESE VALUES
Expand Down
13 changes: 13 additions & 0 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,19 @@ function tabTemplateInit (frameProps) {
}
}, CommonMenu.separatorMenuItem)

// debug options, only in development
if (getSetting(settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD) === true) {
template.push(
{
label: 'Discard',
click: (item) => {
appActions.discardTabRequested(tabId)
}
},
CommonMenu.separatorMenuItem
)
}

template.push(Object.assign({},
CommonMenu.reopenLastClosedTabItem(),
{ enabled: closedFrames ? closedFrames.size > 0 : false }
Expand Down

0 comments on commit eebe586

Please sign in to comment.