Fixed Assignement Toast on page.

Now opens in the newly opened tab (after it has been reopened
in the correct container). It also does not provide a toast
when removing sites from the edit assignments panel, becuase
user will most likely not be on that site when editing the
panel, so it has been throwing an error. Error should go away.
This commit is contained in:
Kendall Werts 2020-02-27 08:42:27 -06:00
parent 0290eb1d56
commit 8ef5cbd81b
4 changed files with 53 additions and 29 deletions

View file

@ -500,16 +500,23 @@ window.assignManager = {
userContextId, userContextId,
neverAsk: false neverAsk: false
}, exemptedTabIds); }, exemptedTabIds);
actionName = "added"; actionName = "assigned site to always open in this container";
} else { } else {
await this.storageArea.remove(pageUrl); await this.storageArea.remove(pageUrl);
actionName = "removed"; actionName = "removed from assigned sites list";
}
if (tabId) {
const tab = await browser.tabs.get(tabId);
setTimeout(function(){
browser.tabs.sendMessage(tabId, {
text: `Successfully ${actionName}`
});
}, 1000);
this.calculateContextMenu(tab);
} }
browser.tabs.sendMessage(tabId, {
text: `Successfully ${actionName} site to always open in this container`
});
const tab = await browser.tabs.get(tabId);
this.calculateContextMenu(tab);
}, },
async _getAssignment(tab) { async _getAssignment(tab) {
@ -595,7 +602,7 @@ window.assignManager = {
// False represents assignment is not permitted // False represents assignment is not permitted
// If the user has explicitly checked "Never Ask Again" on the warning page we will send them straight there // If the user has explicitly checked "Never Ask Again" on the warning page we will send them straight there
if (neverAsk) { if (neverAsk) {
browser.tabs.create({url, cookieStoreId, index, active, openerTabId}); return browser.tabs.create({url, cookieStoreId, index, active, openerTabId});
} else { } else {
let confirmUrl = `${loadPage}?url=${this.encodeURLProperty(url)}&cookieStoreId=${cookieStoreId}`; let confirmUrl = `${loadPage}?url=${this.encodeURLProperty(url)}&cookieStoreId=${cookieStoreId}`;
let currentCookieStoreId; let currentCookieStoreId;
@ -603,7 +610,7 @@ window.assignManager = {
currentCookieStoreId = backgroundLogic.cookieStoreId(currentUserContextId); currentCookieStoreId = backgroundLogic.cookieStoreId(currentUserContextId);
confirmUrl += `&currentCookieStoreId=${currentCookieStoreId}`; confirmUrl += `&currentCookieStoreId=${currentCookieStoreId}`;
} }
browser.tabs.create({ return browser.tabs.create({
url: confirmUrl, url: confirmUrl,
cookieStoreId: currentCookieStoreId, cookieStoreId: currentCookieStoreId,
openerTabId, openerTabId,

View file

@ -6,8 +6,9 @@ const messageHandler = {
init() { init() {
// Handles messages from webextension code // Handles messages from webextension code
browser.runtime.onMessage.addListener((m) => { browser.runtime.onMessage.addListener(async (m) => {
let response; let response;
let tab;
switch (m.method) { switch (m.method) {
case "getShortcuts": case "getShortcuts":
@ -43,9 +44,7 @@ const messageHandler = {
case "setOrRemoveAssignment": case "setOrRemoveAssignment":
// m.tabId is used for where to place the in content message // m.tabId is used for where to place the in content message
// m.url is the assignment to be removed/added // m.url is the assignment to be removed/added
response = browser.tabs.get(m.tabId).then((tab) => { response = assignManager._setOrRemoveAssignment(m.tabId, m.url, m.userContextId, m.value);
return assignManager._setOrRemoveAssignment(tab.id, m.url, m.userContextId, m.value);
});
break; break;
case "sortTabs": case "sortTabs":
backgroundLogic.sortTabs(); backgroundLogic.sortTabs();
@ -90,6 +89,21 @@ const messageHandler = {
true true
); );
break; break;
case "assignAndReloadInContainer":
tab = await assignManager.reloadPageInContainer(
m.url,
m.currentUserContextId,
m.newUserContextId,
m.tabIndex,
m.active,
true
);
// m.tabId is used for where to place the in content message
// m.url is the assignment to be removed/added
response = browser.tabs.get(tab.id).then((tab) => {
return assignManager._setOrRemoveAssignment(tab.id, m.url, m.newUserContextId, m.value);
});
break;
} }
console.log(m.method, "response", response); console.log(m.method, "response", response);
return response; return response;

View file

@ -1180,8 +1180,8 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
Utils.addEnterHandler(deleteButton, async () => { Utils.addEnterHandler(deleteButton, async () => {
const userContextId = Logic.currentUserContextId(); const userContextId = Logic.currentUserContextId();
// Lets show the message to the current tab // Lets show the message to the current tab
const currentTab = await Utils.currentTab(); // const currentTab = await Utils.currentTab();
Utils.setOrRemoveAssignment(currentTab.id, assumedUrl, userContextId, true); Utils.setOrRemoveAssignment(false, assumedUrl, userContextId, true);
delete assignments[siteKey]; delete assignments[siteKey];
this.showAssignedContainers(assignments); this.showAssignedContainers(assignments);
}); });

View file

@ -90,8 +90,8 @@ const Utils = {
}); });
}, },
reloadInContainer(url, currentUserContextId, newUserContextId, tabIndex, active) { async reloadInContainer(url, currentUserContextId, newUserContextId, tabIndex, active) {
return browser.runtime.sendMessage({ return await browser.runtime.sendMessage({
method: "reloadInContainer", method: "reloadInContainer",
url, url,
currentUserContextId, currentUserContextId,
@ -102,21 +102,24 @@ const Utils = {
}, },
async alwaysOpenInContainer(identity) { async alwaysOpenInContainer(identity) {
const currentTab = await this.currentTab(); let currentTab = await this.currentTab();
const assignedUserContextId = this.userContextId(identity.cookieStoreId); const assignedUserContextId = this.userContextId(identity.cookieStoreId);
Utils.setOrRemoveAssignment(
currentTab.id,
currentTab.url,
assignedUserContextId,
false
);
if (currentTab.cookieStoreId !== identity.cookieStoreId) { if (currentTab.cookieStoreId !== identity.cookieStoreId) {
Utils.reloadInContainer( return await browser.runtime.sendMessage({
method: "assignAndReloadInContainer",
url: currentTab.url,
currentUserContextId: false,
newUserContextId: assignedUserContextId,
tabIndex: currentTab.index +1,
active:currentTab.active
});
} else {
currentTab = await this.currentTab();
Utils.setOrRemoveAssignment(
currentTab.id,
currentTab.url, currentTab.url,
false,
assignedUserContextId, assignedUserContextId,
currentTab.index + 1, false
currentTab.active
); );
} }
} }