Skip to content

Commit

Permalink
Merge pull request #419 from ZIMkaRU/feature/show-useful-error-modal-…
Browse files Browse the repository at this point in the history
…if-os-docs-dir-is-misconfigured

Show useful error modal if OS docs dir is misconfigured
  • Loading branch information
ezewer authored Oct 16, 2024
2 parents 5aaa202 + 3418434 commit 94bbc7a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
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

0 comments on commit 94bbc7a

Please sign in to comment.