Skip to content
Open
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: 15 additions & 1 deletion js/browserUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ options
options.enterEditMode - whether to enter editing mode when the tab is created. Defaults to true.
options.openInBackground - whether to open the tab without switching to it. Defaults to false.
*/
function addTab (tabId = tabs.add(), options = {}) {
function addTab (tabId = undefined, options = {}) {
/*
adding a new tab should destroy the current one if either:
* The current tab is an empty, non-private tab, and the new tab is private
* The current tab is empty, and the new tab has a URL
*/

if (focusMode.enabled()) {
/**
* Introduced with -> https://github.com/minbrowser/min/issues/2643
* If the user has managed to get into this logic, we should just disallow and return
* Last ditch effort to prevent tab from being created in focus mode...
*
* i.e. --> User is using the middle mouse button to click on a link
*/
return
}

// If tabId is undefined, and we're not in focus mode, then do true initialization of new tab and get id now...
tabId = !tabId ? tabs.add() : tabId;

if (!options.openInBackground && !tabs.get(tabs.getSelected()).url && ((!tabs.get(tabs.getSelected()).private && tabs.get(tabId).private) || tabs.get(tabId).url)) {
destroyTab(tabs.getSelected())
}
Expand Down
68 changes: 39 additions & 29 deletions js/navbar/tabContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,53 @@ const browserUI = require('browserUI.js')
const webviews = require('webviews.js')
const readerView = require('readerView.js')
const urlParser = require('util/urlParser.js')
const focusMode = require('../focusMode.js')

const tabContextMenu = {
show: function (tabId) {
const tabMenu = [
[
{
label: l('appMenuDuplicateTab'),
click: function () {
const sourceTab = tabs.get(tabId)
// strip tab id so that a new one is generated
const newTab = tabs.add({ ...sourceTab, id: undefined })
const tabMenu = [[]]

/**
* https://github.com/minbrowser/min/issues/2643
*
* Users should not be able to duplicate tabs or open new windows in focus mode.
* Prior to this, users would be able to duplicate tabs without actually creating the view for them.
* So, as a consequence, when the tabMenuNewWindow context menu option was clicked,
* those duplicated tabs from before would all aggregate through the `viewManager.createView` logic.
* Then, all of the priorly duplicated tabs would suddenly appear.
*/
if (!focusMode.enabled()) {
tabMenu[0].push({
label: l('appMenuDuplicateTab'),
click: function () {
const sourceTab = tabs.get(tabId)
// strip tab id so that a new one is generated
const newTab = tabs.add({ ...sourceTab, id: undefined })

browserUI.addTab(newTab, { enterEditMode: false })
}
},
{
label: l('tabMenuNewWindow'),
click: function () {
// insert after current task
let index
if (tasks.getSelected()) {
index = tasks.getIndex(tasks.getSelected().id) + 1
}
const newTask = tasks.get(tasks.add({}, index))
browserUI.addTab(newTab, { enterEditMode: false })
}
})
tabMenu[0].push({
label: l('tabMenuNewWindow'),
click: function () {
// insert after current task
let index
if (tasks.getSelected()) {
index = tasks.getIndex(tasks.getSelected().id) + 1
}
const newTask = tasks.get(tasks.add({}, index))

const targetTab = tabs.get(tabId)
tabs.destroy(targetTab.id)
const targetTab = tabs.get(tabId)
tabs.destroy(targetTab.id)

newTask.tabs.add(targetTab)
newTask.tabs.add(targetTab)

ipc.send('newWindow', { initialTask: newTask.id })
ipc.send('newWindow', { initialTask: newTask.id })

browserUI.switchToTask(tasks.getSelected().id)
}
}
]
]
browserUI.switchToTask(tasks.getSelected().id)
}
})
}

if (tabs.get(tabId).url && (readerView.isReader(tabId) || !urlParser.isInternalURL(tabs.get(tabId).url))) {
if (!readerView.isReader(tabId)) {
Expand Down
66 changes: 40 additions & 26 deletions js/webviewMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const userscripts = require('userscripts.js')
const settings = require('util/settings/settings.js')
const pageTranslations = require('pageTranslations.js')
const PasswordManagers = require('passwordManager/passwordManager.js')
const focusMode = require('./focusMode')

const remoteMenu = require('remoteMenuRenderer.js')

Expand Down Expand Up @@ -82,22 +83,28 @@ const webviewMenu = {
}
]

if (!currentTab.private) {
if (!focusMode.enabled()) {
/**
* https://github.com/minbrowser/min/issues/2643
* Users should not see open in new tab in any capacity in the context menu while in focus mode
*/
if (!currentTab.private) {
linkActions.push({
label: l('openInNewTab'),
click: function () {
browserUI.addTab(tabs.add({ url: link }), { enterEditMode: false, openInBackground: openInBackground })
}
})
}

linkActions.push({
label: l('openInNewTab'),
label: l('openInNewPrivateTab'),
click: function () {
browserUI.addTab(tabs.add({ url: link }), { enterEditMode: false, openInBackground: openInBackground })
browserUI.addTab(tabs.add({ url: link, private: true }), { enterEditMode: false, openInBackground: openInBackground })
}
})
}

linkActions.push({
label: l('openInNewPrivateTab'),
click: function () {
browserUI.addTab(tabs.add({ url: link, private: true }), { enterEditMode: false, openInBackground: openInBackground })
}
})

linkActions.push({
label: l('saveLinkAs'),
click: function () {
Expand All @@ -121,29 +128,36 @@ const webviewMenu = {
}
]

imageActions.push({
label: l('viewImage'),
click: function () {
webviews.update(tabs.getSelected(), mediaURL)
if (!focusMode.enabled()) {
/**
* https://github.com/minbrowser/min/issues/2643
* Users can get stuck viewing an image while in focus mode because they can't go back or exit the tab
* And users shouldn't be able to open tabs in any capacity while in focus mode
*/
imageActions.push({
label: l('viewImage'),
click: function () {
webviews.update(tabs.getSelected(), mediaURL)
}
})

if (!currentTab.private) {
imageActions.push({
label: l('openImageInNewTab'),
click: function () {
browserUI.addTab(tabs.add({ url: mediaURL }), { enterEditMode: false, openInBackground: openInBackground })
}
})
}
})

if (!currentTab.private) {

imageActions.push({
label: l('openImageInNewTab'),
label: l('openImageInNewPrivateTab'),
click: function () {
browserUI.addTab(tabs.add({ url: mediaURL }), { enterEditMode: false, openInBackground: openInBackground })
browserUI.addTab(tabs.add({ url: mediaURL, private: true }), { enterEditMode: false, openInBackground: openInBackground })
}
})
}

imageActions.push({
label: l('openImageInNewPrivateTab'),
click: function () {
browserUI.addTab(tabs.add({ url: mediaURL, private: true }), { enterEditMode: false, openInBackground: openInBackground })
}
})

imageActions.push({
label: l('saveImageAs'),
click: function () {
Expand Down