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 6a198bc
Show file tree
Hide file tree
Showing 3 changed files with 52 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
5 changes: 5 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const winston = require('winston')
const path = require('path')
const DailyRotateFile = require('winston-daily-rotate-file')
const util = require('util')
const { format } = require('date-fns')

const store = require('./store')
const appVersion = require('../package.json').version
Expand Down Expand Up @@ -72,6 +73,10 @@ class Logger {
if (this._messageQueue.length > 0) this._drainQueue()
}

get errorFilename () {
return path.join(this.dirname, format(Date.now(), 'yyyy-MM') + '.error.log')
}

debugging (debug) {
this._level(debug ? 'debug' : 'info')
store.set('debugging', debug)
Expand Down
42 changes: 31 additions & 11 deletions src/renderer/components/dialogs/Error.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
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'

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 => {
shell.openPath(logger.errorFilename)
}

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 6a198bc

Please sign in to comment.