Skip to content

Commit

Permalink
refactor: cleanup protocol handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jun 13, 2024
1 parent 534711e commit b354b32
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/protocol-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function parseAddr (addr) {
return toUri(addr.toString().includes('/http') ? addr : addr.encapsulate('/http'))
}

async function parseUrl (url) {
async function handleOpenLink (url) {
const getIpfsd = await getCtx().getProp('getIpfsd')
const ipfsd = getIpfsd ? await getIpfsd(true) : null
let base = 'https://dweb.link'
Expand All @@ -24,10 +24,6 @@ async function parseUrl (url) {
return openLink('ipfs', url.slice(7), base)
} else if (url.startsWith('ipns://')) {
return openLink('ipns', url.slice(7), base)
} else if (url.startsWith('dweb:/ipfs/')) {
return openLink('ipfs', url.slice(11), base)
} else if (url.startsWith('dweb:/ipns/')) {
return openLink('ipns', url.slice(11), base)
}

return false
Expand All @@ -37,7 +33,7 @@ async function argvHandler (argv) {
let handled = false

for (const arg of argv) {
if (await parseUrl(arg)) {
if (await handleOpenLink(arg)) {
handled = true
}
}
Expand All @@ -53,7 +49,7 @@ module.exports = function () {
// Handle URLs in macOS
app.on('open-url', async (event, url) => {
event.preventDefault()
parseUrl(url)
handleOpenLink(url)
})
}

Expand Down

0 comments on commit b354b32

Please sign in to comment.