Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions add-on/src/lib/context-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ module.exports.contextMenuCopyAddressAtPublicGw = contextMenuCopyAddressAtPublic
module.exports.contextMenuViewOnGateway = contextMenuViewOnGateway
module.exports.contextMenuCopyPermalink = contextMenuCopyPermalink

// menu items that are enabled only when API is online
// menu item ids for things that are enabled only when API is online (static)
const apiMenuItemIds = new Set([contextMenuCopyRawCid, contextMenuCopyCanonicalAddress, contextMenuImportToIpfs])
// menu items that are enabled only when API is online (dynamic)
const apiMenuItems = new Set()
// menu items enabled only in IPFS context
// menu items enabled only in IPFS context (dynamic)
const ipfsContextItems = new Set()

function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromContext, onCopyCanonicalAddress, onCopyRawCid, onCopyAddressAtPublicGw }) {
Expand Down Expand Up @@ -104,15 +106,19 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
const itemId = `${parentId}_${id}`
ipfsContextItems.add(itemId)
// some items also require API access
if (id === contextMenuCopyRawCid) {
if (apiMenuItemIds.has(id)) {
apiMenuItems.add(itemId)
}
return browser.contextMenus.create({
id: itemId,
parentId,
title: browser.i18n.getMessage(id),
contexts: [contextType],
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
documentUrlPatterns: [
'*://*/ipfs/*', '*://*/ipns/*',
'*://*.ipfs.dweb.link/*', '*://*.ipns.dweb.link/*', // TODO: add any custom public gateway from Preferences
'*://*.ipfs.localhost/*', '*://*.ipns.localhost/*'
],
/* no support for 'icons' in Chrome
icons: {
'48': '/ui-kit/icons/stroke_copy.svg'
Expand All @@ -124,7 +130,8 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
createSubmenu(parentId, contextType)
createImportToIpfsMenuItem(parentId, contextMenuImportToIpfs, contextType, { wrapWithDirectory: true, pin: false })
createCopierMenuItem(parentId, contextMenuCopyAddressAtPublicGw, contextType, onCopyAddressAtPublicGw)
createCopierMenuItem(parentId, contextMenuCopyCanonicalAddress, contextType, onCopyCanonicalAddress)
// TODO: below needs refactor to support for both IPFS and IPNS, like one added to browser action in https://github.com/ipfs-shipyard/ipfs-companion/pull/937
// createCopierMenuItem(parentId, contextMenuCopyCanonicalAddress, contextType, onCopyCanonicalAddress)
createCopierMenuItem(parentId, contextMenuCopyRawCid, contextType, onCopyRawCid)
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"babel-plugin-syntax-async-generators": "6.13.0",
"chai": "4.3.3",
"cross-env": "7.0.3",
"css-loader": "5.1.1",
"css-loader": "5.1.2",
"download-cli": "1.1.1",
"file-loader": "6.2.0",
"firefox-addons-add-update-version": "1.0.1",
Expand All @@ -106,7 +106,7 @@
"terser": "5.6.0",
"terser-webpack-plugin": "5.1.1",
"transform-loader": "0.2.4",
"web-ext": "5.5.0",
"web-ext": "6.0.0",
"webpack": "5.24.4",
"webpack-bundle-analyzer": "4.4.0",
"webpack-cli": "4.5.0",
Expand Down
Loading