Skip to content

Commit

Permalink
Fixed Assignement Toast on page.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kendallcorner committed Feb 28, 2020
1 parent 0290eb1 commit 8ef5cbd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
25 changes: 16 additions & 9 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,23 @@ window.assignManager = {
userContextId,
neverAsk: false
}, exemptedTabIds);
actionName = "added";
actionName = "assigned site to always open in this container";
} else {
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) {
Expand Down Expand Up @@ -595,15 +602,15 @@ window.assignManager = {
// 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 (neverAsk) {
browser.tabs.create({url, cookieStoreId, index, active, openerTabId});
return browser.tabs.create({url, cookieStoreId, index, active, openerTabId});
} else {
let confirmUrl = `${loadPage}?url=${this.encodeURLProperty(url)}&cookieStoreId=${cookieStoreId}`;
let currentCookieStoreId;
if (currentUserContextId) {
currentCookieStoreId = backgroundLogic.cookieStoreId(currentUserContextId);
confirmUrl += `&currentCookieStoreId=${currentCookieStoreId}`;
}
browser.tabs.create({
return browser.tabs.create({
url: confirmUrl,
cookieStoreId: currentCookieStoreId,
openerTabId,
Expand Down
22 changes: 18 additions & 4 deletions src/js/background/messageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const messageHandler = {

init() {
// Handles messages from webextension code
browser.runtime.onMessage.addListener((m) => {
browser.runtime.onMessage.addListener(async (m) => {
let response;
let tab;

switch (m.method) {
case "getShortcuts":
Expand Down Expand Up @@ -43,9 +44,7 @@ const messageHandler = {
case "setOrRemoveAssignment":
// 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(m.tabId).then((tab) => {
return assignManager._setOrRemoveAssignment(tab.id, m.url, m.userContextId, m.value);
});
response = assignManager._setOrRemoveAssignment(m.tabId, m.url, m.userContextId, m.value);
break;
case "sortTabs":
backgroundLogic.sortTabs();
Expand Down Expand Up @@ -90,6 +89,21 @@ const messageHandler = {
true
);
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);
return response;
Expand Down
4 changes: 2 additions & 2 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
Utils.addEnterHandler(deleteButton, async () => {
const userContextId = Logic.currentUserContextId();
// Lets show the message to the current tab
const currentTab = await Utils.currentTab();
Utils.setOrRemoveAssignment(currentTab.id, assumedUrl, userContextId, true);
// const currentTab = await Utils.currentTab();
Utils.setOrRemoveAssignment(false, assumedUrl, userContextId, true);
delete assignments[siteKey];
this.showAssignedContainers(assignments);
});
Expand Down
31 changes: 17 additions & 14 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const Utils = {
});
},

reloadInContainer(url, currentUserContextId, newUserContextId, tabIndex, active) {
return browser.runtime.sendMessage({
async reloadInContainer(url, currentUserContextId, newUserContextId, tabIndex, active) {
return await browser.runtime.sendMessage({
method: "reloadInContainer",
url,
currentUserContextId,
Expand All @@ -102,21 +102,24 @@ const Utils = {
},

async alwaysOpenInContainer(identity) {
const currentTab = await this.currentTab();
let currentTab = await this.currentTab();
const assignedUserContextId = this.userContextId(identity.cookieStoreId);
Utils.setOrRemoveAssignment(
currentTab.id,
currentTab.url,
assignedUserContextId,
false
);
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,
false,
assignedUserContextId,
currentTab.index + 1,
currentTab.active
assignedUserContextId,
false
);
}
}
Expand Down

0 comments on commit 8ef5cbd

Please sign in to comment.