Add option to disable the page action

This commit is contained in:
bep 2021-04-21 17:37:22 -04:00
parent 83b2606e58
commit 4e75945198
6 changed files with 55 additions and 8 deletions

View file

@ -1,7 +1,7 @@
{ {
"extensionDescription": { "extensionDescription": {
"message": "Multi-Account Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.", "message": "Multi-Account Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.",
"description": "Description of the extension. DO NOT TRANSLATE \"Multi-Account Containers\"." "description": "Description of the extension. DO NOT TRANSLATE \"Multi-Account Containers\"."
}, },
"openInNewTabTitle": { "openInNewTabTitle": {
"message": "Open New Tab in…", "message": "Open New Tab in…",
@ -27,10 +27,10 @@
"message": "Always Open Site in Container" "message": "Always Open Site in Container"
}, },
"openANewTabIn": { "openANewTabIn": {
"message" : "Open a New Tab in…" "message": "Open a New Tab in…"
}, },
"openNewTabInThisContainer": { "openNewTabInThisContainer": {
"message" : "Open New Tab in this Container" "message": "Open New Tab in this Container"
}, },
"openTabs": { "openTabs": {
"message": "Open Tabs" "message": "Open Tabs"
@ -48,7 +48,7 @@
"message": "A simple and secure way to manage your online life" "message": "A simple and secure way to manage your online life"
}, },
"onboarding-1-sec-description": { "onboarding-1-sec-description": {
"message" : "Use containers to organize tasks, manage accounts, and store sensitive data." "message": "Use containers to organize tasks, manage accounts, and store sensitive data."
}, },
"onboarding-2-header": { "onboarding-2-header": {
"message": "Put containers to work for you." "message": "Put containers to work for you."
@ -203,6 +203,9 @@
"keyboardShortCuts": { "keyboardShortCuts": {
"message": "Keyboard Shortcuts:" "message": "Keyboard Shortcuts:"
}, },
"pageActionDescription": {
"message": "Show the \"Always open this in a container\" button in the URL bar"
},
"onboarding": { "onboarding": {
"message": "Onboarding" "message": "Onboarding"
}, },
@ -243,7 +246,7 @@
"message": "Container to open with Keyboard Shortcut $keyId$", "message": "Container to open with Keyboard Shortcut $keyId$",
"placeholders": { "placeholders": {
"keyId": { "keyId": {
"content": "$1" "content": "$1"
} }
} }
}, },

View file

@ -51,6 +51,11 @@ window.assignManager = {
return !!syncEnabled; return !!syncEnabled;
}, },
async getPageActionEnabled() {
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
return !!pageActionEnabled;
},
async getReplaceTabEnabled() { async getReplaceTabEnabled() {
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled"); const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
return !!replaceTabEnabled; return !!replaceTabEnabled;
@ -431,6 +436,19 @@ window.assignManager = {
} }
}, },
async resetPageAction() {
const pageActionEnabled = await this.storageArea.getPageActionEnabled();
const tabs = await browser.tabs.query({});
const res = tabs.map((tab) => {
if (pageActionEnabled) {
return browser.pageAction.show(tab.id);
} else {
return browser.pageAction.hide(tab.id);
}
});
await Promise.all(res);
},
contextualIdentityCreated(changeInfo) { contextualIdentityCreated(changeInfo) {
browser.contextMenus.create({ browser.contextMenus.create({
parentId: assignManager.OPEN_IN_CONTAINER, parentId: assignManager.OPEN_IN_CONTAINER,

View file

@ -23,6 +23,9 @@ const messageHandler = {
case "resetBookmarksContext": case "resetBookmarksContext":
response = assignManager.resetBookmarksMenuItem(); response = assignManager.resetBookmarksMenuItem();
break; break;
case "resetPageAction":
response = assignManager.resetPageAction();
break;
case "deleteContainer": case "deleteContainer":
response = backgroundLogic.deleteContainer(m.message.userContextId); response = backgroundLogic.deleteContainer(m.message.userContextId);
break; break;
@ -180,6 +183,17 @@ const messageHandler = {
}); });
}, {urls: ["<all_urls>"], types: ["main_frame"]}); }, {urls: ["<all_urls>"], types: ["main_frame"]});
browser.tabs.onUpdated.addListener((tabId) => {
// check if the page action is enabled right away to avoid flashing
browser.storage.local.get({ pageActionEnabled: true }).then(({ pageActionEnabled }) => {
if (pageActionEnabled) {
browser.pageAction.show(tabId);
}
}).catch(e => {
throw e;
});
}, { properties: ["status"] });
browser.tabs.onCreated.addListener((tab) => { browser.tabs.onCreated.addListener((tab) => {
// lets remember the last tab created so we can close it if it looks like a redirect // lets remember the last tab created so we can close it if it looks like a redirect
this.lastCreatedTab = tab; this.lastCreatedTab = tab;

View file

@ -25,15 +25,23 @@ async function enableDisableReplaceTab() {
await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked}); await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked});
} }
async function enableDisablePageAction() {
const checkbox = document.querySelector("#pageActionCheck");
await browser.storage.local.set({pageActionEnabled: !!checkbox.checked});
await browser.runtime.sendMessage({ method: "resetPageAction" });
}
async function setupOptions() { async function setupOptions() {
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]}); const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
const { syncEnabled } = await browser.storage.local.get("syncEnabled"); const { syncEnabled } = await browser.storage.local.get("syncEnabled");
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled"); const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
if (hasPermission) { if (hasPermission) {
document.querySelector("#bookmarksPermissions").checked = true; document.querySelector("#bookmarksPermissions").checked = true;
} }
document.querySelector("#syncCheck").checked = !!syncEnabled; document.querySelector("#syncCheck").checked = !!syncEnabled;
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled; document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
document.querySelector("#pageActionCheck").checked = !!pageActionEnabled;
setupContainerShortcutSelects(); setupContainerShortcutSelects();
} }
@ -82,6 +90,7 @@ document.addEventListener("DOMContentLoaded", setupOptions);
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions); document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync); document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab); document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
document.querySelector("#pageActionCheck").addEventListener( "change", enableDisablePageAction);
document.querySelector("button").addEventListener("click", resetOnboarding); document.querySelector("button").addEventListener("click", resetOnboarding);
for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) { for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {

View file

@ -121,8 +121,7 @@
"default_icon": "img/container-openin-16.svg", "default_icon": "img/container-openin-16.svg",
"default_title": "Always open this in a Container", "default_title": "Always open this in a Container",
"default_popup": "pageActionPopup.html", "default_popup": "pageActionPopup.html",
"pinned": false, "pinned": false
"show_matches": ["*://*/*"]
}, },
"background": { "background": {
"page": "js/background/index.html" "page": "js/background/index.html"

View file

@ -28,6 +28,10 @@
<span data-i18n-message-id="replaceTab"></span> <span data-i18n-message-id="replaceTab"></span>
</label> </label>
<p><em data-i18n-message-id="replaceTabDescription"></em></p> <p><em data-i18n-message-id="replaceTabDescription"></em></p>
<label>
<input type="checkbox" id="pageActionCheck">
<span data-i18n-message-id="pageActionDescription"></span>
</label>
<h3 data-i18n-message-id="keyboardShortCuts"></h3> <h3 data-i18n-message-id="keyboardShortCuts"></h3>
<p><em data-i18n-message-id="editWhichContainer"></em></p> <p><em data-i18n-message-id="editWhichContainer"></em></p>
<p><label> <p><label>