Skip to content

Commit

Permalink
Option to allow opening of the popup in new tab as default
Browse files Browse the repository at this point in the history
  • Loading branch information
mastef committed Oct 28, 2019
1 parent 186e62f commit 055f5f2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
19 changes: 19 additions & 0 deletions lib/TabManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ var TabManager = React.createFactory(React.createClass({
var hideWindows = false;
var filterTabs = false;
var tabLimit = 0;
var openInOwnTab = false;
var tabWidth = 530;
var tabHeight = 450;

if (this.localStorageAvailable()) {
if (!localStorage["layout"]) localStorage["layout"] = "horizontal";
if (typeof localStorage["tabLimit"] === "undefined") localStorage["tabLimit"] = "0";
if (typeof localStorage["openInOwnTab"] === "undefined") localStorage["openInOwnTab"] = "0";
if (typeof localStorage["tabWidth"] === "undefined") localStorage["tabWidth"] = "530";
if (typeof localStorage["tabHeight"] === "undefined") localStorage["tabHeight"] = "450";
if (typeof localStorage["animations"] === "undefined") localStorage["animations"] = "1";
Expand All @@ -53,6 +55,7 @@ var TabManager = React.createFactory(React.createClass({
tabLimit = JSON.parse(localStorage["tabLimit"]);
tabWidth = JSON.parse(localStorage["tabWidth"]);
tabHeight = JSON.parse(localStorage["tabHeight"]);
openInOwnTab = this.toBoolean(localStorage["openInOwnTab"]);
animations = this.toBoolean(localStorage["animations"]);
windowTitles = this.toBoolean(localStorage["windowTitles"]);
compact = this.toBoolean(localStorage["compact"]);
Expand Down Expand Up @@ -81,6 +84,7 @@ var TabManager = React.createFactory(React.createClass({
animations: animations,
windowTitles: windowTitles,
tabLimit: tabLimit,
openInOwnTab: openInOwnTab,
tabWidth: tabWidth,
tabHeight: tabHeight,
compact: compact,
Expand Down Expand Up @@ -253,6 +257,7 @@ var TabManager = React.createFactory(React.createClass({
animations: this.state.animations,
windowTitles: this.state.windowTitles,
tabLimit: this.state.tabLimit,
openInOwnTab: this.state.openInOwnTab,
tabWidth: this.state.tabWidth,
tabHeight: this.state.tabHeight,
tabactions: this.state.tabactions,
Expand All @@ -261,6 +266,7 @@ var TabManager = React.createFactory(React.createClass({
sessionsFeature: this.state.sessionsFeature,
exportSessions: this.exportSessions,
importSessions: this.importSessions,
toggleOpenInOwnTab: this.toggleOpenInOwnTab,
toggleBadge: this.toggleBadge,
toggleHide: this.toggleHide,
toggleSessions: this.toggleSessions,
Expand All @@ -272,6 +278,7 @@ var TabManager = React.createFactory(React.createClass({
changeTabLimit: this.changeTabLimit,
changeTabWidth: this.changeTabWidth,
changeTabHeight: this.changeTabHeight,
openInOwnTabText: this.openInOwnTabText,
badgeText: this.badgeText,
hideText: this.hideText,
sessionsText: this.sessionsText,
Expand Down Expand Up @@ -824,6 +831,18 @@ var TabManager = React.createFactory(React.createClass({
this.setState({
bottomText: "Shows the number of open tabs on the Tab Manager icon. Default : on" });

},
toggleOpenInOwnTab: function toggleOpenInOwnTab() {
this.state.openInOwnTab = !this.state.openInOwnTab;
localStorage["openInOwnTab"] = this.state.openInOwnTab ? "1" : "0";
this.openInOwnTabText();
browser.runtime.sendMessage({command: "reload_popup_controls"});
this.forceUpdate();
},
openInOwnTabText: function tabLimitText() {
this.setState({
bottomText: "Open the Tab Manager by default in own tab, or as a popup?" });

},
toggleSessions: function toggleSessions() {
this.state.sessionsFeature = !this.state.sessionsFeature;
Expand Down
12 changes: 11 additions & 1 deletion lib/TabOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@
React.DOM.label({ className: "textlabel", htmlFor: "badge_mode", style: { "white-space": "pre", "line-height": "2rem" } }, "Count Tabs"),
React.DOM.div({ className: "option-description" }, "Shows you the number of open tabs over the Tab Manager icon in the top right of your browser.",
React.DOM.br({}),
React.DOM.i({}, "By default: enabled")))),
React.DOM.i({}, "By default: enabled"))),

React.DOM.div({ className: "toggle-box" },
React.DOM.div({ className: "toggle" },
React.DOM.input({ type: "checkbox", onMouseEnter: this.props.openInOwnTabText, onChange: this.props.toggleOpenInOwnTab, checked: this.props.openInOwnTab, id: "openinowntab_mode", name: "openinowntab_mode" }),
React.DOM.label({ onMouseEnter: this.props.openInOwnTabText, htmlFor: "openinowntab_mode", style: { "white-space": "pre", "line-height": "2rem" } })),

React.DOM.label({ className: "textlabel", htmlFor: "openinowntab_mode", style: { "white-space": "pre", "line-height": "2rem" } }, "Open in own Tab by default"),
React.DOM.div({ className: "option-description" }, "Opens the Tab Manager in own tab by default, instead of the popup.",
React.DOM.br({}),
React.DOM.i({}, "By default: disabled")))),



Expand Down
55 changes: 39 additions & 16 deletions lib/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,44 @@ function tabActiveChanged(tab) {
updateTabCountDebounce();
}

async function openAsOwnTab() {
var tabs = await browser.tabs.query({});
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
if (tab.url.indexOf("popup.html") > -1) {
await browser.windows.update(tab.windowId, { focused: true });
await browser.tabs.highlight({ windowId: tab.windowId, tabs: tab.index });
return;
}
}
await browser.tabs.create({ url: "popup.html" });
}

async function setupPopup() {
if (typeof localStorage["openInOwnTab"] === "undefined") localStorage["openInOwnTab"] = "0";
var openInOwnTab = false
try {
openInOwnTab = !!JSON.parse(localStorage["openInOwnTab"]);
} catch (e) {
openInOwnTab = false;
}
console.log(openInOwnTab);
if(openInOwnTab) {
await browser.browserAction.setPopup({ popup: "" });
await browser.browserAction.onClicked.addListener(openAsOwnTab);
}else{
await browser.browserAction.setPopup({ popup: "popup.html?popup=true" });
await browser.browserAction.onClicked.removeListener(openAsOwnTab);
}
}

async function setupListeners() {

await browser.browserAction.setPopup({ popup: "popup.html?popup=true" });
await browser.contextMenus.removeAll();
await browser.contextMenus.create({
title: "Open in own tab",
contexts: ["browser_action"],
onclick: async function onclick() {
var tabs = await browser.tabs.query({});
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
if (tab.url.indexOf("popup.html") > -1) {
await browser.windows.update(tab.windowId, { focused: true });
await browser.tabs.highlight({ windowId: tab.windowId, tabs: tab.index });
return;
}
}
await browser.tabs.create({ url: "popup.html" });
} });
onclick: openAsOwnTab });
await browser.contextMenus.create({
title: "Donate to keep Extensions Alive",
"contexts": ["browser_action"],
Expand Down Expand Up @@ -166,7 +185,7 @@ async function setupListeners() {
chrome.tabs.create({ url: 'mailto:[email protected]' });
} });

// browser.browserAction.onClicked.addListener();
setupPopup();

browser.tabs.onCreated.removeListener(tabAdded);
browser.tabs.onUpdated.removeListener(tabRemoved);
Expand Down Expand Up @@ -194,8 +213,6 @@ async function setupListeners() {
updateTabCountDebounce();
}



// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
Expand Down Expand Up @@ -374,6 +391,12 @@ browser.commands.onCommand.addListener(function (command) {
}
});

browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.command == "reload_popup_controls") {
setupPopup();
}
});

(async function () {
var windows = await browser.windows.getAll({ populate: true });
localStorage["windowAge"] = JSON.stringify([]);
Expand Down

0 comments on commit 055f5f2

Please sign in to comment.