Skip to content

Commit

Permalink
fix: Improve styling of Error handling & add open log button
Browse files Browse the repository at this point in the history
  • Loading branch information
okdistribute committed Oct 12, 2020
1 parent b8243d0 commit 0920af4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,22 @@ const main = new Main({
isDev
})

function ipcSend (...args) {
try {
if (win && win.webContents) {
win.webContents.send.apply(win.webContents, args)
return true
} else return false
} catch (e) {
logger.error('exception win.webContents.send', args, e.stack)
return false
}
}

function onError (err) {
logger.info('SHOWING ERROR BOX')
electron.dialog.showErrorBox('Error', err.toString())
if (!ipcSend('error', err.toString())) {
electron.dialog.showErrorBox('Error', err.toString())
}
}

main.on('error', onError)
Expand Down Expand Up @@ -218,7 +231,7 @@ function initDirectories (done) {
chmod(path.join(userDataPath, 'presets'), '0700', (err) => {
if (err) logger.error('Failed to execute chmod on presets', err)
chmod(path.join(userDataPath, 'styles'), '0700', (err) => {
if (err) logger.error('Failed to execute chmod on styles', err)
if (err && !err.message.includes('asar')) logger.error('Failed to execute chmod on styles', err)
done()
})
})
Expand All @@ -227,13 +240,6 @@ function initDirectories (done) {

function createServers (done) {
// Set up Electron IPC bridge with frontend in electron-renderer process
function ipcSend (...args) {
try {
if (win && win.webContents) win.webContents.send.apply(win.webContents, args)
} catch (e) {
logger.error('exception win.webContents.send', args, e.stack)
}
}
electronIpc(ipcSend)

// Start Mapeo HTTP Servers
Expand Down
45 changes: 34 additions & 11 deletions src/renderer/components/dialogs/Error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
import React from 'react'
import TextareaAutosize from '@material-ui/core/TextareaAutosize'
import Dialog from '@material-ui/core/Dialog'
import DialogContent from '@material-ui/core/DialogContent'
import DialogActions from '@material-ui/core/DialogActions'
import DialogTitle from '@material-ui/core/DialogTitle'
import Button from '@material-ui/core/Button'
import path from 'path'
import { format } from 'date-fns'

export default class ErrorDialog extends React.Component {
render () {
// TODO: escape this html for displaying newlines
return (
<Dialog open={this.props.open} onClose={this.props.onClose}>
<DialogTitle>Error</DialogTitle>
<DialogContent>
<textarea cols='20' rows='40' value={this.props.message} disabled />
</DialogContent>
</Dialog>
)
import { shell } from 'electron'
import logger from '../../../logger'

import { defineMessages, useIntl } from 'react-intl'

const m = defineMessages({
openLog: 'Open log...',
close: 'Close'
})

export default ({ onClose, open, message }) => {
const { formatMessage: t } = useIntl()

const handleDownload = event => {
var logfile = path.join(logger.dirname, format(Date.now(), 'yyyy-MM') + '.error.log')
shell.openPath(logfile)
}

return (
<Dialog open={open} onClose={onClose}>
<DialogTitle>Error</DialogTitle>
<DialogContent>
<TextareaAutosize rowsMin='5' rowsMax='30' cols='40' value={message} disabled />
<DialogActions>
<Button onClick={handleDownload}>{t(m.openLog)}</Button>
<Button variant='contained' color='primary' onClick={onClose}>{t(m.close)}</Button>
</DialogActions>
</DialogContent>
</Dialog>
)
}

0 comments on commit 0920af4

Please sign in to comment.