diff --git a/assets/locales/en.json b/assets/locales/en.json index 242d488f8..550c4c70b 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -234,5 +234,14 @@ "clearCustomIpfsBinarySuccess": { "title": "Clear custom IPFS binary", "message": "The custom IPFS binary was cleared. To start using the bundled IPFS version, IPFS needs to be restarted first." + }, + "protocolHandlerDialog": { + "title": "Opening IPFS URIs", + "message": "How would you like IPFS Desktop to open IPFS URIs?", + "browserPublicGateway": "In my default browser using a public gateway", + "browserLocalGateway": "In my default browser using a local gateway", + "filesScreen": "In the Files screen", + "exploreScreen": "In the Explore screen", + "rememberThisChoice": "Remember this choice for all IPFS URIs" } } diff --git a/src/protocol-handlers.js b/src/protocol-handlers.js index 817648407..fefdf3272 100644 --- a/src/protocol-handlers.js +++ b/src/protocol-handlers.js @@ -1,6 +1,7 @@ -const { app, shell } = require('electron') +const { app, shell, ipcMain } = require('electron') const toUri = require('multiaddr-to-uri') const i18n = require('i18next') +const createToggler = require('./utils/create-toggler') const store = require('./common/store') const { showPrompt } = require('./dialogs') @@ -23,25 +24,25 @@ async function getAction () { } const { button, input } = await showPrompt({ - title: 'Opening IPFS URIs', - message: 'How would you like IPFS Desktop to open IPFS URIs?', + title: i18n.t('protocolHandlerDialog.title'), + message: i18n.t('protocolHandlerDialog.message'), inputs: [ { type: 'radio', name: 'action', defaultValue: DEFAULT_ACTION, labels: { - [ACTION_OPTIONS.BROWSER_PUBLIC_GATEWAY]: 'In my default browser using a public gateway', - [ACTION_OPTIONS.BROWSER_LOCAL_GATEWAY]: 'In my default browser using a local gateway', - [ACTION_OPTIONS.FILES_SCREEN]: 'In the Files screen', - [ACTION_OPTIONS.EXPLORE_SCREEN]: 'In the Explore screen' + [ACTION_OPTIONS.BROWSER_PUBLIC_GATEWAY]: i18n.t('protocolHandlerDialog.browserPublicGateway'), + [ACTION_OPTIONS.BROWSER_LOCAL_GATEWAY]: i18n.t('protocolHandlerDialog.browserLocalGateway'), + [ACTION_OPTIONS.FILES_SCREEN]: i18n.t('protocolHandlerDialog.filesScreen'), + [ACTION_OPTIONS.EXPLORE_SCREEN]: i18n.t('protocolHandlerDialog.exploreScreen') } }, { type: 'checkbox', name: 'remember', defaultValue: 'checked', - label: 'Remember this choice for all IPFS URIs' + label: i18n.t('protocolHandlerDialog.rememberThisChoice') } ], buttons: [ @@ -63,6 +64,7 @@ async function getAction () { if (input.remember === 'on') { store.set(CONFIG_KEY, false) store.set(CONFIG_KEY_ACTION, action) + ipcMain.emit('configUpdated') } return action @@ -96,15 +98,16 @@ async function parseUrl (url, ctx) { return false } - const action = store.get(CONFIG_KEY_ACTION, DEFAULT_ACTION) + const action = await getAction() let base = 'https://dweb.link' + let ipfsd switch (action) { case ACTION_OPTIONS.BROWSER_PUBLIC_GATEWAY: openLink(protocol, part, base) break case ACTION_OPTIONS.BROWSER_LOCAL_GATEWAY: - const ipfsd = ctx.getIpfsd ? await ctx.getIpfsd(true) : null + ipfsd = ctx.getIpfsd ? await ctx.getIpfsd(true) : null // Best effort. Defaults to public gateway if not available. if (ipfsd && ipfsd.gatewayAddr) { @@ -117,7 +120,12 @@ async function parseUrl (url, ctx) { ctx.launchWebUI(`/${protocol}/${part}`, { focus: true }) break case ACTION_OPTIONS.EXPLORE_SCREEN: - ctx.launchWebUI(`/explore/${protocol}/${part}`, { focus: true }) + if (protocol === 'ipns') { + // IPNS is not supported on the explore page yet. + ctx.launchWebUI(`/${protocol}/${part}`, { focus: true }) + } else { + ctx.launchWebUI(`/explore/${protocol}/${part}`, { focus: true }) + } break default: return false @@ -144,12 +152,10 @@ module.exports = function (ctx) { // tray option shows a 'tick'. if (store.get(CONFIG_KEY, null) === null) { store.set(CONFIG_KEY, true) + ipcMain.emit('configUpdated') } - setTimeout(async () => { - const action = await getAction() - console.log(action) - }, 5000) + createToggler(CONFIG_KEY, () => true) // Handle if the app started running now, and a link // was sent to be handled.