@@ -68,9 +68,11 @@ module.exports.contextMenuCopyAddressAtPublicGw = contextMenuCopyAddressAtPublic
6868module . exports . contextMenuViewOnGateway = contextMenuViewOnGateway
6969module . 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)
7274const apiMenuItems = new Set ( )
73- // menu items enabled only in IPFS context
75+ // menu items enabled only in IPFS context (dynamic)
7476const ipfsContextItems = new Set ( )
7577
7678function 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
0 commit comments