Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show useful error modal if OS docs dir is misconfigured #419

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/error-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,29 @@ const initLogger = () => {
if (message.level === 'error') {
const error = message.data.join(os.EOL)

if (/Failed to get 'documents' path/gi.test(error)) {
const title = 'The OS Documents directory has been misconfigured'
const msg = `\
This indicates that your OS \`Documents\` directory has been misconfigured.
Please, set it to a valid location or reset it to the default`

showModalDialog({
errBoxTitle: title,
errBoxDescription: msg,
mdIssue: msg,
alertOpts: {
icon: 'error',
title,
showConfirmButton: false,
hasNoParentWin: true
}
})
.then(() => { app.exit() })
.catch((err) => { console.error(err) })

return
}

/*
* Don't open a new issue when:
* - It can't download differentially it would fallback to full download
Expand Down
37 changes: 24 additions & 13 deletions src/error-manager/show-modal-dialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { app, dialog, screen, remote } = require('electron')
const { app, dialog, screen } = require('electron')
const fs = require('fs')
const path = require('path')
const { Converter } = require('showdown')
Expand Down Expand Up @@ -53,19 +53,23 @@ const converter = new Converter({
const _fireAlert = (params) => {
const {
title = 'Should a bug report be submitted?',
html
} = params
const win = wins.mainWindow
html = '',
parentWin,
hasNoParentWin
} = params ?? {}
const win = parentWin ?? wins.mainWindow

if (!isMainWinAvailable()) {
if (
!hasNoParentWin &&
!isMainWinAvailable(win)
) {
return { value: false }
}

const _screen = screen || remote.screen
const {
getCursorScreenPoint,
getDisplayNearestPoint
} = _screen
} = screen
const {
workArea
} = getDisplayNearestPoint(getCursorScreenPoint())
Expand All @@ -76,7 +80,8 @@ const _fireAlert = (params) => {

const eventHandlerCtx = addOnceProcEventHandler(
WINDOW_EVENT_NAMES.CLOSED,
() => closeAlert(alert)
() => closeAlert(alert),
win
)

const bwOptions = {
Expand All @@ -103,15 +108,17 @@ const _fireAlert = (params) => {
}),

icon: 'question',
title,
html,
focusConfirm: true,
showConfirmButton: true,
confirmButtonText: 'Report',
showCancelButton: true,
cancelButtonText: 'Cancel',
timerProgressBar: false,

...params,
title,
html,

willOpen: () => {
if (
!alert ||
Expand Down Expand Up @@ -164,18 +171,22 @@ module.exports = async (params) => {
const {
errBoxTitle = 'Bug report',
errBoxDescription = 'A new Github issue will be opened',
mdIssue
mdIssue,
alertOpts = {}
} = params

if (
app.isReady() &&
isMainWinAvailable()
(
alertOpts?.hasNoParentWin ||
isMainWinAvailable(alertOpts?.parentWin ?? wins.mainWindow)
)
) {
const html = converter.makeHtml(mdIssue)

const {
value
} = await _fireAlert({ html })
} = await _fireAlert({ html, ...alertOpts })

return {
isExit: false,
Expand Down