From 16b880d837ddbf8170c69ac32dbd1d28ab826251 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 18 Apr 2020 09:47:24 +0100 Subject: [PATCH 1/3] feat: allow for custom errors License: MIT Signed-off-by: Henrique Dias --- src/dialogs/errors.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/dialogs/errors.js b/src/dialogs/errors.js index d432db68b..bd6851667 100644 --- a/src/dialogs/errors.js +++ b/src/dialogs/errors.js @@ -44,8 +44,11 @@ function criticalErrorDialog (e) { app.exit(1) } -function recoverableErrorDialog (e) { - const option = dialog({ +// Shows a recoverable error dialog with the default title and message. +// Passing an options object alongside the error can be used to override +// the title and message. +function recoverableErrorDialog (e, options = {}) { + const cfg = { title: i18n.t('recoverableErrorDialog.title'), message: i18n.t('recoverableErrorDialog.message'), type: 'error', @@ -54,7 +57,17 @@ function recoverableErrorDialog (e) { i18n.t('reportTheError'), i18n.t('openLogs') ] - }) + } + + if (options.title) { + cfg.title = options.title + } + + if (options.message) { + cfg.message = options.message + } + + const option = dialog(cfg) if (option === 1) { shell.openExternal(`https://github.com/ipfs-shipyard/ipfs-desktop/issues/new?body=${encodeURI(issueTemplate(e))}`) From 233cb2587578b2273f909b1961fb5df5cada2429 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 18 Apr 2020 09:51:03 +0100 Subject: [PATCH 2/3] feat(ux): better error messages Add custom error messages when moving the repository fails, as well as adding IPFS to PATH on Windows. License: MIT Signed-off-by: Henrique Dias --- assets/locales/en.json | 8 ++++++++ src/ipfs-on-path/index.js | 6 +++++- src/move-repository-location.js | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/locales/en.json b/assets/locales/en.json index 9363be17f..a190846f4 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -141,5 +141,13 @@ "runGarbageCollectorDone": { "title": "Garbage collector", "message": "The garbage collector ran successfully." + }, + "moveRepositoryFailed": { + "title": "Move repository", + "message": "Could not move the repository from { currDir } to { newDir }." + }, + "cantAddIpfsToPath": { + "title": "IPFS on PATH", + "message": "Could not add IPFS to the PATH." } } diff --git a/src/ipfs-on-path/index.js b/src/ipfs-on-path/index.js index 04011c1ef..1d1bdab79 100644 --- a/src/ipfs-on-path/index.js +++ b/src/ipfs-on-path/index.js @@ -1,4 +1,5 @@ const { join } = require('path') +const i18n = require('i18next') const which = require('which') const { execFile } = require('child_process') const createToggler = require('../create-toggler') @@ -53,7 +54,10 @@ async function runWindows (script, { failSilently }) { logger.error(`[ipfs on path] ${err.toString()}`) if (!failSilently) { - recoverableErrorDialog(err) + recoverableErrorDialog(err, { + title: i18n.t('cantAddIpfsToPath.title'), + message: i18n.t('cantAddIpfsToPath.message') + }) } return resolve(false) diff --git a/src/move-repository-location.js b/src/move-repository-location.js index ffad28291..7825b1de2 100644 --- a/src/move-repository-location.js +++ b/src/move-repository-location.js @@ -69,7 +69,10 @@ module.exports = function ({ stopIpfs, startIpfs }) { logger.info(`[move repository] moved from ${currDir} to ${newDir}`) } catch (err) { logger.error(`[move repository] ${err.toString()}`) - return recoverableErrorDialog(err) + return recoverableErrorDialog(err, { + title: i18n.t('moveRepositoryFailed.title'), + message: i18n.t('moveRepositoryFailed.message', { currDir, newDir }) + }) } config.path = newDir From f2deaa537ab7669220401778368709eb04e1c9e2 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 18 Apr 2020 15:45:14 +0100 Subject: [PATCH 3/3] add double quotes License: MIT Signed-off-by: Henrique Dias --- assets/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/locales/en.json b/assets/locales/en.json index a190846f4..ba8cb62e7 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -144,7 +144,7 @@ }, "moveRepositoryFailed": { "title": "Move repository", - "message": "Could not move the repository from { currDir } to { newDir }." + "message": "Could not move the repository from \"{ currDir }\" to \"{ newDir }\"." }, "cantAddIpfsToPath": { "title": "IPFS on PATH",