Skip to content

Commit

Permalink
feat: separate labels for Image, Video and Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Sep 19, 2018
1 parent 6e50669 commit 3dceb95
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 50 deletions.
18 changes: 11 additions & 7 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@
"message": "Add Selected Text to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsSelection)"
},
"contextMenu_AddToIpfsRawCid": {
"message": "Add This Object to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsRawCid)"
"contextMenu_AddToIpfsImage": {
"message": "Add Image to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsImage)"
},
"contextMenu_AddToIpfsKeepFilename": {
"message": "Add This Object to IPFS (Keep Filename)",
"description": "An item in right-click context menu (contextMenu_AddToIpfsKeepFilename)"
"contextMenu_AddToIpfsVideo": {
"message": "Add Video to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsVideo)"
},
"contextMenu_AddToIpfsAudio": {
"message": "Add Audio to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsAudio)"
},
"contextMenu_AddToIpfsLink": {
"message": "Add This Link to IPFS",
"message": "Add Link Destination to IPFS",
"description": "An item in right-click context menu (contextMenu_AddToIpfsLink)"
},
"notify_addonIssueTitle": {
Expand Down
72 changes: 29 additions & 43 deletions add-on/src/lib/context-menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,45 @@ async function findUrlForContext (context, contextField) {
module.exports.findUrlForContext = findUrlForContext

const contextMenuAddToIpfsSelection = 'contextMenu_AddToIpfsSelection'
const contextMenuAddToIpfsRawCid = 'contextMenu_AddToIpfsRawCid'
const contextMenuAddToIpfsKeepFilename = 'contextMenu_AddToIpfsKeepFilename'
// const contextMenuAddToIpfsRawCid = 'contextMenu_AddToIpfsRawCid'
const contextMenuAddToIpfsImage = 'contextMenu_AddToIpfsImage'
const contextMenuAddToIpfsVideo = 'contextMenu_AddToIpfsVideo'
const contextMenuAddToIpfsAudio = 'contextMenu_AddToIpfsAudio'
const contextMenuAddToIpfsLink = 'contextMenu_AddToIpfsLink'
const contextMenuCopyCanonicalAddress = 'panelCopy_currentIpfsAddress'
const contextMenuCopyAddressAtPublicGw = 'panel_copyCurrentPublicGwUrl'

// menu items that are enabled only when API is online
const apiMenuItems = [
contextMenuAddToIpfsSelection,
contextMenuAddToIpfsImage,
contextMenuAddToIpfsVideo,
contextMenuAddToIpfsAudio,
contextMenuAddToIpfsLink
]

function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromContext, onCopyCanonicalAddress, onCopyAddressAtPublicGw }) {
let copyAddressContexts = ['page', 'image', 'video', 'audio', 'link']
if (runtime.isFirefox) {
// https://github.com/ipfs-shipyard/ipfs-companion/issues/398
copyAddressContexts.push('page_action')
}
try {
browser.contextMenus.create({
id: contextMenuAddToIpfsSelection,
title: browser.i18n.getMessage(contextMenuAddToIpfsSelection),
contexts: ['selection'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: (context) => onAddFromContext(context, 'selectionText')
})

browser.contextMenus.create({
id: contextMenuAddToIpfsRawCid,
title: browser.i18n.getMessage(contextMenuAddToIpfsRawCid),
contexts: ['image', 'video', 'audio'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: (context) => onAddFromContext(context, 'srcUrl')
})

browser.contextMenus.create({
id: contextMenuAddToIpfsKeepFilename,
title: browser.i18n.getMessage(contextMenuAddToIpfsKeepFilename),
contexts: ['image', 'video', 'audio'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: (context) => onAddFromContext(context, 'srcUrl', { wrapWithDirectory: true })
})

browser.contextMenus.create({
id: contextMenuAddToIpfsLink,
title: browser.i18n.getMessage(contextMenuAddToIpfsLink),
contexts: ['link'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: (context) => onAddFromContext(context, 'linkUrl', { wrapWithDirectory: true })
})
const createAddToIpfsMenuItem = (menuItemId, contextName, contextField, ipfsAddOptions) => {
browser.contextMenus.create({
id: menuItemId,
title: browser.i18n.getMessage(menuItemId),
contexts: [contextName],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: (context) => onAddFromContext(context, 'srcUrl', ipfsAddOptions)
})
}
createAddToIpfsMenuItem(contextMenuAddToIpfsSelection, 'selection', 'selectionText')
createAddToIpfsMenuItem(contextMenuAddToIpfsImage, 'image', 'srcUrl', { wrapWithDirectory: true })
createAddToIpfsMenuItem(contextMenuAddToIpfsVideo, 'video', 'srcUrl', { wrapWithDirectory: true })
createAddToIpfsMenuItem(contextMenuAddToIpfsAudio, 'audio', 'srcUrl', { wrapWithDirectory: true })
createAddToIpfsMenuItem(contextMenuAddToIpfsLink, 'link', 'linkUrl', { wrapWithDirectory: true })

browser.contextMenus.create({
id: contextMenuCopyCanonicalAddress,
Expand Down Expand Up @@ -110,12 +101,7 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
async update (changedTabId) {
try {
const canUpload = getState().peerCount > 0
const items = [ contextMenuAddToIpfsSelection,
contextMenuAddToIpfsRawCid,
contextMenuAddToIpfsKeepFilename,
contextMenuAddToIpfsLink
]
for (let item of items) {
for (let item of apiMenuItems) {
await browser.contextMenus.update(item, { enabled: canUpload })
}
if (changedTabId) {
Expand Down

0 comments on commit 3dceb95

Please sign in to comment.