Skip to content

Commit

Permalink
feat: handle errors better (#697)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Nov 24, 2018
1 parent 123738d commit b71cc73
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, dialog } from 'electron'
import { app, dialog, shell } from 'electron'
import { join } from 'path'
import { store, createDaemon } from './utils'
import startupMenubar from './menubar'
Expand All @@ -12,7 +12,45 @@ if (!app.requestSingleInstanceLock()) {
)

// No windows were opened at this time so we don't need to do app.quit()
process.exit(0)
process.exit(1)
}

const issueTemplate = (e) => `Please describe what you were doing when this error happened.
**Specifications**
- **OS**: ${process.platform}
- **IPFS Desktop Version**: ${app.getVersion()}
- **Electron Version**: ${process.versions.electron}
- **Chrome Version**: ${process.versions.chrome}
**Error**
\`\`\`
${e.stack}
\`\`\`
`

function handleError (e) {
const option = dialog.showMessageBox({
type: 'error',
title: 'IPFS Desktop has shutdown',
message: 'IPFS Desktop has shutdown because of an error. You can restart the app or report the error to the developers, which requires a GitHub account.',
buttons: [
'Close',
'Report the error to the developers',
'Restart the app'
],
cancelId: 0
})

if (option === 1) {
shell.openExternal(`https://github.com/ipfs-shipyard/ipfs-desktop/issues/new?body=${encodeURI(issueTemplate(e))}`)
} else if (option === 2) {
app.relaunch()
}

app.exit(1)
}

async function setupConnection () {
Expand All @@ -31,21 +69,30 @@ async function setupConnection () {
}

async function run () {
await app.whenReady()

// Initial context object
let ctx = {
ipfsd: await setupConnection()
try {
await app.whenReady()
} catch (e) {
dialog.showErrorBox('Electron could not start', e.stack)
app.exit(1)
}

// Initialize windows. These can add properties to context
await startupMenubar(ctx)
try {
// Initial context object
let ctx = {
ipfsd: await setupConnection()
}

// Initialize windows. These can add properties to context
await startupMenubar(ctx)

// Register hooks
await registerHooks(ctx)
// Register hooks
await registerHooks(ctx)

if (!store.get('seenWelcome')) {
// TODO: open WebUI on Welcome screen
if (!store.get('seenWelcome')) {
// TODO: open WebUI on Welcome screen
}
} catch (e) {
handleError(e)
}
}

Expand Down

0 comments on commit b71cc73

Please sign in to comment.