Skip to content

Commit

Permalink
new option to replace current tab when a assigned domain is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Moonloard committed Jul 27, 2020
1 parent 00a1ce9 commit 46d76df
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/js/background/assignManager.js
Expand Up @@ -51,6 +51,11 @@ window.assignManager = {
return !!syncEnabled;
},

async getReplaceTabEnabled() {
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
return !!replaceTabEnabled;
},

getByUrlKey(siteStoreKey) {
return new Promise((resolve, reject) => {
this.area.get([siteStoreKey]).then((storageResponse) => {
Expand Down Expand Up @@ -233,9 +238,11 @@ window.assignManager = {
return {};
}
}
const replaceTabEnabled = await this.storageArea.getReplaceTabEnabled();
const removeTab = backgroundLogic.NEW_TAB_PAGES.has(tab.url)
|| (messageHandler.lastCreatedTab
&& messageHandler.lastCreatedTab.id === tab.id);
&& messageHandler.lastCreatedTab.id === tab.id)
|| replaceTabEnabled;
const openTabId = removeTab ? tab.openerTabId : tab.id;

if (!this.canceledRequests[tab.id]) {
Expand Down
23 changes: 13 additions & 10 deletions src/js/options.js
Expand Up @@ -16,25 +16,26 @@ async function requestPermissions() {

async function enableDisableSync() {
const checkbox = document.querySelector("#syncCheck");
if (checkbox.checked) {
await browser.storage.local.set({syncEnabled: true});
} else {
await browser.storage.local.set({syncEnabled: false});
}
await browser.storage.local.set({syncEnabled: !!checkbox.checked});
browser.runtime.sendMessage({ method: "resetSync" });
}

async function enableDisableReplaceTab() {
const checkbox = document.querySelector("#replaceTabCheck");
await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked});
}

async function setupOptions() {
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
const { replaceTabEnabled } =
await browser.storage.local.get("replaceTabEnabled");
if (hasPermission) {
document.querySelector("#bookmarksPermissions").checked = true;
}
if (syncEnabled) {
document.querySelector("#syncCheck").checked = true;
} else {
document.querySelector("#syncCheck").checked = false;
}
document.querySelector("#syncCheck").checked = !!syncEnabled;
document.querySelector("#replaceTabCheck").checked =
!!replaceTabEnabled;
setupContainerShortcutSelects();
}

Expand Down Expand Up @@ -82,6 +83,8 @@ function resetOnboarding() {
document.addEventListener("DOMContentLoaded", setupOptions);
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
document.querySelector("#replaceTabCheck")
.addEventListener( "change", enableDisableReplaceTab);
document.querySelector("button").addEventListener("click", resetOnboarding);

for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
Expand Down
7 changes: 7 additions & 0 deletions src/options.html
Expand Up @@ -20,6 +20,13 @@ <h3>Firefox Accounts Sync:</h3>
Enable Sync
</label>
<p><em>This setting allows you to sync your containers and site assignments across devices.</em></p>
<h3>Tab behaviour:</h3>
<label>
<input type="checkbox" id="replaceTabCheck">
Enable tab replace for assigned domains
</label>
<p><em>Replace current tab if a page which is assigned to a specific container is opened (instead of keeping the current tab open).
Opening tabs with middle mouse button is not affected.</em></p>
<h3>Keyboard Shortcuts:</h3>
<p><em>Edit which container is opened when using the numbered shortcuts.</em></p>
<p><label>
Expand Down
3 changes: 2 additions & 1 deletion test/common.js
Expand Up @@ -87,7 +87,8 @@ const initializeWithTab = async (details = {
"browserActionBadgesClicked": [],
"onboarding-stage": 7,
"achievements": [],
"syncEnabled": true
"syncEnabled": true,
"replaceTabEnabled": false
});
window.browser.storage.local.set.resetHistory();
window.browser.storage.sync.clear();
Expand Down

0 comments on commit 46d76df

Please sign in to comment.