Merge pull request #1565 from kendallcorner/bookmark-menu-updates
fixed #1564: cleanup updates requested for bookmark context menu
This commit is contained in:
commit
3c2dda5100
5 changed files with 47 additions and 46 deletions
|
@ -240,19 +240,26 @@ const assignManager = {
|
||||||
delete this.canceledRequests[options.tabId];
|
delete this.canceledRequests[options.tabId];
|
||||||
}
|
}
|
||||||
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
||||||
this.getPermissions();
|
this.resetBookmarksMenuItem();
|
||||||
},
|
},
|
||||||
|
|
||||||
async getPermissions() {
|
async resetBookmarksMenuItem() {
|
||||||
const {permissions} = await browser.permissions.getAll();
|
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
|
||||||
permissions.includes("bookmarks") ? this.makeBookmarksMenu() : browser.contextMenus.remove(this.OPEN_IN_CONTAINER);
|
if (this.hadBookmark === hasPermission) {
|
||||||
},
|
return;
|
||||||
|
}
|
||||||
makeBookmarksMenu() {
|
this.hadBookmark = hasPermission;
|
||||||
this.initBookmarksMenu();
|
if (hasPermission) {
|
||||||
browser.contextualIdentities.onCreated.addListener(this.contextualIdentityCreated);
|
this.initBookmarksMenu();
|
||||||
browser.contextualIdentities.onUpdated.addListener(this.contextualIdentityUpdated);
|
browser.contextualIdentities.onCreated.addListener(this.contextualIdentityCreated);
|
||||||
browser.contextualIdentities.onRemoved.addListener(this.contextualIdentityRemoved);
|
browser.contextualIdentities.onUpdated.addListener(this.contextualIdentityUpdated);
|
||||||
|
browser.contextualIdentities.onRemoved.addListener(this.contextualIdentityRemoved);
|
||||||
|
} else {
|
||||||
|
this.removeBookmarksMenu();
|
||||||
|
browser.contextualIdentities.onCreated.removeListener(this.contextualIdentityCreated);
|
||||||
|
browser.contextualIdentities.onUpdated.removeListener(this.contextualIdentityUpdated);
|
||||||
|
browser.contextualIdentities.onRemoved.removeListener(this.contextualIdentityRemoved);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
contextualIdentityCreated(changeInfo) {
|
contextualIdentityCreated(changeInfo) {
|
||||||
|
@ -324,7 +331,7 @@ const assignManager = {
|
||||||
if(openInReaderMode) {
|
if(openInReaderMode) {
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(bookmark.url);
|
const parsed = new URL(bookmark.url);
|
||||||
bookmark.url = parsed.searchParams.get("url") + parsed.hash; // can't believe const lets me do this ...
|
bookmark.url = parsed.searchParams.get("url") + parsed.hash;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return err.message;
|
return err.message;
|
||||||
}
|
}
|
||||||
|
@ -521,6 +528,14 @@ const assignManager = {
|
||||||
icons: { "16": `img/usercontext.svg#${identity.icon}` }
|
icons: { "16": `img/usercontext.svg#${identity.icon}` }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async removeBookmarksMenu() {
|
||||||
|
browser.contextMenus.remove(this.OPEN_IN_CONTAINER);
|
||||||
|
const identities = await browser.contextualIdentities.query({});
|
||||||
|
for (const identity of identities) {
|
||||||
|
browser.contextMenus.remove(identity.cookieStoreId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ const messageHandler = {
|
||||||
|
|
||||||
switch (m.method) {
|
switch (m.method) {
|
||||||
case "resetBookmarksContext":
|
case "resetBookmarksContext":
|
||||||
response = assignManager.getPermissions();
|
response = assignManager.resetBookmarksMenuItem();
|
||||||
break;
|
break;
|
||||||
case "deleteContainer":
|
case "deleteContainer":
|
||||||
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
||||||
|
|
|
@ -1,39 +1,23 @@
|
||||||
|
|
||||||
function requestPermissions() {
|
async function requestPermissions() {
|
||||||
const checkbox = document.querySelector("#bookmarksPermissions");
|
const checkbox = document.querySelector("#bookmarksPermissions");
|
||||||
if (checkbox.checked) {
|
if (checkbox.checked) {
|
||||||
browser.permissions.request({permissions: ["bookmarks"]}).
|
const granted = await browser.permissions.request({permissions: ["bookmarks"]});
|
||||||
then((response) => {
|
if (!granted) {
|
||||||
if (response) {
|
checkbox.checked = false;
|
||||||
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
|
return;
|
||||||
} else {
|
}
|
||||||
checkbox.checked = false;
|
|
||||||
}
|
|
||||||
}).
|
|
||||||
catch((err) => {
|
|
||||||
return err.message;
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
browser.permissions.remove({permissions: ["bookmarks"]}).
|
await browser.permissions.remove({permissions: ["bookmarks"]});
|
||||||
then(() => {
|
|
||||||
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
|
|
||||||
}).
|
|
||||||
catch((err) => {
|
|
||||||
return err.message;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreOptions() {
|
async function restoreOptions() {
|
||||||
browser.permissions.getAll()
|
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
|
||||||
.then((permissions) => {
|
if (hasPermission) {
|
||||||
if (permissions.permissions.includes("bookmarks")) {
|
document.querySelector("#bookmarksPermissions").checked = true;
|
||||||
document.querySelector("#bookmarksPermissions").checked = true;
|
}
|
||||||
}
|
|
||||||
}).
|
|
||||||
catch((err) => {
|
|
||||||
return err.message;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,15 @@
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<form>
|
<form>
|
||||||
<input type="checkbox" id="bookmarksPermissions"/>
|
<label>
|
||||||
<label>Enable Bookmark Menus</label>
|
<input type="checkbox" id="bookmarksPermissions">
|
||||||
|
Enable Bookmark Menus
|
||||||
|
</label>
|
||||||
<p>This setting allows you to open a bookmark or folder of bookmarks in a container.</p>
|
<p>This setting allows you to open a bookmark or folder of bookmarks in a container.</p>
|
||||||
</form>
|
</form>
|
||||||
<script src="js/options.js"></script>
|
<script src="js/options.js"></script>
|
||||||
|
|
|
@ -93,7 +93,7 @@ module.exports = () => {
|
||||||
getURL: sinon.stub().returns("moz-extension://multi-account-containers/confirm-page.html")
|
getURL: sinon.stub().returns("moz-extension://multi-account-containers/confirm-page.html")
|
||||||
},
|
},
|
||||||
permissions: {
|
permissions: {
|
||||||
getAll: sinon.stub().returns({"permissions": ["bookmarks"]})
|
contains: sinon.stub().returns(true)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue