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

refactor: the async await extravaganza #811

Merged
merged 20 commits into from
Oct 5, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: badge icon
  • Loading branch information
lidel committed Sep 22, 2020
commit cd250c00750f8dee1182e2309a893e5265e85d3e
46 changes: 19 additions & 27 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const debug = require('debug')
const log = debug('ipfs-companion:main')
log.error = debug('ipfs-companion:main:error')

const { Buffer } = require('buffer')
const browser = require('webextension-polyfill')
const toMultiaddr = require('uri-to-multiaddr')
const pMemoize = require('p-memoize')
Expand Down Expand Up @@ -324,21 +323,14 @@ module.exports = async function init () {
// console.log('onAddFromContext.fetchOptions', fetchOptions)
const response = await fetch(dataSrc, fetchOptions)
const blob = await response.blob()
const buffer = await new Promise((resolve, reject) => {
const reader = new FileReader()
// TODO: remove Buffer?
reader.onloadend = () => resolve(Buffer.from(reader.result))
reader.onerror = reject
reader.readAsArrayBuffer(blob)
})
const url = new URL(response.url)
// https://github.com/ipfs-shipyard/ipfs-companion/issues/599
const filename = url.pathname === '/'
? url.hostname
: url.pathname.replace(/[\\/]+$/, '').split('/').pop()
const data = {
path: decodeURIComponent(filename),
content: buffer
content: blob
}
result = await ipfsImportHandler.importFiles(data, options, importDir)
}
Expand Down Expand Up @@ -520,24 +512,6 @@ module.exports = async function init () {
}
}

async function setBrowserActionIcon (iconPath) {
return browser.browserAction.setIcon(rasterIconDefinition(iconPath))
/* Below fallback does not work since Chromium 80
* (it fails in a way that does not produce error we can catch)
const iconDefinition = { path: iconPath }
try {
// Try SVG first -- Firefox supports it natively
await browser.browserAction.setIcon(iconDefinition)
} catch (error) {
// Fallback!
// Chromium does not support SVG [ticket below is 8 years old, I can't even..]
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
// Still, we want icon, so we precompute rasters of popular sizes and use them instead
await browser.browserAction.setIcon(rasterIconDefinition(iconPath))
}
*/
}

// ColorArray [0,0,0,0] → Hex #000000
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/ColorArray
function colorArraytoHex (colorArray) {
Expand Down Expand Up @@ -587,6 +561,24 @@ module.exports = async function init () {
})
*/

async function setBrowserActionIcon (iconPath) {
return browser.browserAction.setIcon(rasterIconDefinition(iconPath))
/* Below fallback does not work since Chromium 80
* (it fails in a way that does not produce error we can catch)
const iconDefinition = { path: iconPath }
try {
// Try SVG first -- Firefox supports it natively
await browser.browserAction.setIcon(iconDefinition)
} catch (error) {
// Fallback!
// Chromium does not support SVG [ticket below is 8 years old, I can't even..]
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
// Still, we want icon, so we precompute rasters of popular sizes and use them instead
await browser.browserAction.setIcon(rasterIconDefinition(iconPath))
}
*/
}

// OPTIONS
// ===================================================================

Expand Down