Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore window if it's just the tab manager in one tab #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 20 additions & 2 deletions lib/TabManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class TabManager extends React.Component {
disabled={true}
className="tabtitle"
ref="topbox"
placeholder={maybePluralize(tabCount, 'tab') + " in " + this.state.windows.length + " windows"}
placeholder={maybePluralize(tabCount, 'tab') + " in " + maybePluralize(this.state.windows.length, 'window')}
value={this.state.topText}
/>
<input type="text" disabled={true} className="taburl" ref="topboxurl" placeholder={this.getTip()} value={this.state.bottomText} />
Expand Down Expand Up @@ -592,6 +592,7 @@ class TabManager extends React.Component {
}
async update() {
var windows = await browser.windows.getAll({ populate: true });
windows = windows.filter(filterExtensionWindow);
windows.sort(function(a, b) {
var windows = [];
if (!!localStorage["windowAge"]) {
Expand Down Expand Up @@ -1771,4 +1772,21 @@ function debounce(func, wait, immediate) {
}

const maybePluralize = (count, noun, suffix = 's') =>
`${count} ${noun}${count !== 1 ? suffix : ''}`;
`${count} ${noun}${count !== 1 ? suffix : ''}`;

/** If a window only contains our extension as a popup in a single tab, we
* don't want it polluting its own tab manager, where it will always be
* the first window, with no other tabs in it, and it really gets in the
* way.
*/
function filterExtensionWindow(window) {
return !isExtensionWindow(window);
}
/** with openInOwnTab, e.g. "moz-extension://df16e922-4c5e-c443-9dba-d480e8c77b06/popup.html" */
let extensionUrl = browser.runtime.getURL('popup.html');
function isExtensionWindow(window) {
if (window.type !== 'normal') return true;
// if we only manage to create a single-tab normal window
if (window.tabs.length !== 1) return false;
return window.tabs[0].url.startsWith(extensionUrl);
}
24 changes: 21 additions & 3 deletions outlib/TabManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ TabManager = function (_React$Component) {_inherits(TabManager, _React$Component
disabled: true,
className: "tabtitle",
ref: "topbox",
placeholder: maybePluralize(tabCount, 'tab') + " in " + this.state.windows.length + " windows",
placeholder: maybePluralize(tabCount, 'tab') + " in " + maybePluralize(this.state.windows.length, 'window'),
value: this.state.topText }),

React.createElement("input", { type: "text", disabled: true, className: "taburl", ref: "topboxurl", placeholder: this.getTip(), value: this.state.bottomText })),
Expand Down Expand Up @@ -592,6 +592,7 @@ TabManager = function (_React$Component) {_inherits(TabManager, _React$Component
} }, { key: "update", value: function () {var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {var windows, tabCount, i, window, j, tab, id;return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:_context2.next = 2;return (

browser.windows.getAll({ populate: true }));case 2:windows = _context2.sent;
windows = windows.filter(filterExtensionWindow);
windows.sort(function (a, b) {
var windows = [];
if (!!localStorage["windowAge"]) {
Expand Down Expand Up @@ -632,7 +633,7 @@ TabManager = function (_React$Component) {_inherits(TabManager, _React$Component

//this.state.searchLen = 0;
// this.forceUpdate();
case 13:case "end":return _context2.stop();}}}, _callee2, this);}));function update() {return _ref2.apply(this, arguments);}return update;}() }, { key: "deleteTabs", value: function () {var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {var _this2, tabs, i, t;return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:
case 14:case "end":return _context2.stop();}}}, _callee2, this);}));function update() {return _ref2.apply(this, arguments);}return update;}() }, { key: "deleteTabs", value: function () {var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {var _this2, tabs, i, t;return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:

_this2 = this;
tabs = Object.keys(this.state.selection).map(function (id) {
Expand Down Expand Up @@ -1771,4 +1772,21 @@ function debounce(func, wait, immediate) {
}

var maybePluralize = function maybePluralize(count, noun) {var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 's';return (
count + " " + noun + (count !== 1 ? suffix : ''));};
count + " " + noun + (count !== 1 ? suffix : ''));};

/** If a window only contains our extension as a popup in a single tab, we
* don't want it polluting its own tab manager, where it will always be

Choose a reason for hiding this comment

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

The spacing here seems to be off. Also, probably no need for the second astrisk when you start the comment block. :)

* the first window, with no other tabs in it, and it really gets in the
* way.
*/
function filterExtensionWindow(window) {
return !isExtensionWindow(window);
}
/** with openInOwnTab, e.g. "moz-extension://df16e922-4c5e-c443-9dba-d480e8c77b06/popup.html" */
var extensionUrl = browser.runtime.getURL('popup.html');
function isExtensionWindow(window) {
if (window.type !== 'normal') return true;
// if we only manage to create a single-tab normal window
if (window.tabs.length !== 1) return false;
return window.tabs[0].url.startsWith(extensionUrl);
}