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

New debug menu option - 'Allow Manual Tab Discarding': creates 'Discard' tab context menu command #13118

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird; the path before was invalid, right? did references before to tabState work (before this PR)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was not invalid, we just went one more step up and then back into the app folder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where now we just go one folder up and then into common

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah- I totally see it now 😄 Was up past bedtime and didn't catch that LOL

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, just some tiny clean up whilst there

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,13 @@ 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) {
appActions.changeSetting(settings.DEBUG_ALLOW_MANUAL_TAB_DISCARD, menuItem.checked)
}
}
]
}
Expand Down Expand Up @@ -570,7 +577,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 +668,9 @@ 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) {
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