Skip to content

Commit b9c6703

Browse files
authored
fix: copy actions in context menu on subdomains (#986)
This fixes sneaky regression on subdomain gws.
1 parent d83d30d commit b9c6703

File tree

3 files changed

+521
-1263
lines changed

3 files changed

+521
-1263
lines changed

add-on/src/lib/context-menus.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ module.exports.contextMenuCopyAddressAtPublicGw = contextMenuCopyAddressAtPublic
6868
module.exports.contextMenuViewOnGateway = contextMenuViewOnGateway
6969
module.exports.contextMenuCopyPermalink = contextMenuCopyPermalink
7070

71-
// menu items that are enabled only when API is online
71+
// menu item ids for things that are enabled only when API is online (static)
72+
const apiMenuItemIds = new Set([contextMenuCopyRawCid, contextMenuCopyCanonicalAddress, contextMenuImportToIpfs])
73+
// menu items that are enabled only when API is online (dynamic)
7274
const apiMenuItems = new Set()
73-
// menu items enabled only in IPFS context
75+
// menu items enabled only in IPFS context (dynamic)
7476
const ipfsContextItems = new Set()
7577

7678
function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromContext, onCopyCanonicalAddress, onCopyRawCid, onCopyAddressAtPublicGw }) {
@@ -104,15 +106,19 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
104106
const itemId = `${parentId}_${id}`
105107
ipfsContextItems.add(itemId)
106108
// some items also require API access
107-
if (id === contextMenuCopyRawCid) {
109+
if (apiMenuItemIds.has(id)) {
108110
apiMenuItems.add(itemId)
109111
}
110112
return browser.contextMenus.create({
111113
id: itemId,
112114
parentId,
113115
title: browser.i18n.getMessage(id),
114116
contexts: [contextType],
115-
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
117+
documentUrlPatterns: [
118+
'*://*/ipfs/*', '*://*/ipns/*',
119+
'*://*.ipfs.dweb.link/*', '*://*.ipns.dweb.link/*', // TODO: add any custom public gateway from Preferences
120+
'*://*.ipfs.localhost/*', '*://*.ipns.localhost/*'
121+
],
116122
/* no support for 'icons' in Chrome
117123
icons: {
118124
'48': '/ui-kit/icons/stroke_copy.svg'
@@ -124,7 +130,8 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
124130
createSubmenu(parentId, contextType)
125131
createImportToIpfsMenuItem(parentId, contextMenuImportToIpfs, contextType, { wrapWithDirectory: true, pin: false })
126132
createCopierMenuItem(parentId, contextMenuCopyAddressAtPublicGw, contextType, onCopyAddressAtPublicGw)
127-
createCopierMenuItem(parentId, contextMenuCopyCanonicalAddress, contextType, onCopyCanonicalAddress)
133+
// 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
134+
// createCopierMenuItem(parentId, contextMenuCopyCanonicalAddress, contextType, onCopyCanonicalAddress)
128135
createCopierMenuItem(parentId, contextMenuCopyRawCid, contextType, onCopyRawCid)
129136
}
130137

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"babel-plugin-syntax-async-generators": "6.13.0",
8181
"chai": "4.3.3",
8282
"cross-env": "7.0.3",
83-
"css-loader": "5.1.1",
83+
"css-loader": "5.1.2",
8484
"download-cli": "1.1.1",
8585
"file-loader": "6.2.0",
8686
"firefox-addons-add-update-version": "1.0.1",
@@ -106,7 +106,7 @@
106106
"terser": "5.6.0",
107107
"terser-webpack-plugin": "5.1.1",
108108
"transform-loader": "0.2.4",
109-
"web-ext": "5.5.0",
109+
"web-ext": "6.0.0",
110110
"webpack": "5.24.4",
111111
"webpack-bundle-analyzer": "4.4.0",
112112
"webpack-cli": "4.5.0",

0 commit comments

Comments
 (0)