Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to opening options page manually in brave #315

Merged
merged 2 commits into from
Nov 27, 2017
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
68 changes: 38 additions & 30 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,32 @@ const contextMenuUploadToIpfs = 'contextMenu_UploadToIpfs'
const contextMenuCopyIpfsAddress = 'panelCopy_currentIpfsAddress'
const contextMenuCopyPublicGwUrl = 'panel_copyCurrentPublicGwUrl'

browser.contextMenus.create({
id: contextMenuUploadToIpfs,
title: browser.i18n.getMessage(contextMenuUploadToIpfs),
contexts: ['image', 'video', 'audio'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: addFromURL
})
browser.contextMenus.create({
id: contextMenuCopyIpfsAddress,
title: browser.i18n.getMessage(contextMenuCopyIpfsAddress),
contexts: ['page', 'image', 'video', 'audio', 'link'],
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
onclick: copyCanonicalAddress
})
browser.contextMenus.create({
id: contextMenuCopyPublicGwUrl,
title: browser.i18n.getMessage(contextMenuCopyPublicGwUrl),
contexts: ['page', 'image', 'video', 'audio', 'link'],
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
onclick: copyAddressAtPublicGw
})
try {
browser.contextMenus.create({
id: contextMenuUploadToIpfs,
title: browser.i18n.getMessage(contextMenuUploadToIpfs),
contexts: ['image', 'video', 'audio'],
documentUrlPatterns: ['<all_urls>'],
enabled: false,
onclick: addFromURL
})
browser.contextMenus.create({
id: contextMenuCopyIpfsAddress,
title: browser.i18n.getMessage(contextMenuCopyIpfsAddress),
contexts: ['page', 'image', 'video', 'audio', 'link'],
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
onclick: copyCanonicalAddress
})
browser.contextMenus.create({
id: contextMenuCopyPublicGwUrl,
title: browser.i18n.getMessage(contextMenuCopyPublicGwUrl),
contexts: ['page', 'image', 'video', 'audio', 'link'],
documentUrlPatterns: ['*://*/ipfs/*', '*://*/ipns/*'],
onclick: copyAddressAtPublicGw
})
} catch (err) {
console.log('[ipfs-companion] Error creating contextMenus', err)
}

function inFirefox () {
return !!navigator.userAgent.match('Firefox')
Expand Down Expand Up @@ -362,15 +366,19 @@ async function copyTextToClipboard (copyText) {
}

async function updateContextMenus (changedTabId) {
await browser.contextMenus.update(contextMenuUploadToIpfs, {enabled: state.peerCount > 0})
if (changedTabId) {
// recalculate tab-dependant menu items
const currentTab = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
if (currentTab && currentTab.id === changedTabId) {
const ipfsContext = isIpfsPageActionsContext(currentTab.url)
browser.contextMenus.update(contextMenuCopyIpfsAddress, {enabled: ipfsContext})
browser.contextMenus.update(contextMenuCopyPublicGwUrl, {enabled: ipfsContext})
try {
await browser.contextMenus.update(contextMenuUploadToIpfs, {enabled: state.peerCount > 0})
if (changedTabId) {
// recalculate tab-dependant menu items
const currentTab = await browser.tabs.query({active: true, currentWindow: true}).then(tabs => tabs[0])
if (currentTab && currentTab.id === changedTabId) {
const ipfsContext = isIpfsPageActionsContext(currentTab.url)
browser.contextMenus.update(contextMenuCopyIpfsAddress, {enabled: ipfsContext})
browser.contextMenus.update(contextMenuCopyPublicGwUrl, {enabled: ipfsContext})
}
}
} catch (err) {
console.log('[ipfs-companion] Error updating context menus', err)
}
}

Expand Down
8 changes: 7 additions & 1 deletion add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ module.exports = (state, emitter) => {
})

emitter.on('openPrefs', () => {
browser.runtime.openOptionsPage().then(() => window.close())
browser.runtime.openOptionsPage()
.then(() => window.close())
.catch((err) => {
console.error('runtime.openOptionsPage() failed, opening options page in tab instead.', err)
// brave: fallback to opening options page as a tab.
browser.tabs.create({ url: browser.extension.getURL('dist/options/options.html') })
})
})

emitter.on('toggleRedirect', async () => {
Expand Down