-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Reapply "Settings store (#362)" (#440) This reverts commit 81320e2. * Allow user to see result of YAML config read - Nature of the failure is returned - Invalid values read are included if available - Retains inferred types * Fix cannot start app if invalid install state Current requirement is that a missing YAML file triggers the install screen. * Detect YAML parse exceptions * Update test expectations
- Loading branch information
1 parent
901c69a
commit f5e108d
Showing
9 changed files
with
359 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { app, dialog, shell } from 'electron'; | ||
import fs from 'fs/promises'; | ||
import log from 'electron-log/main'; | ||
import path from 'node:path'; | ||
|
||
type RequireProperties<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>; | ||
|
||
type MessageBoxOptions = RequireProperties<Electron.MessageBoxOptions, 'buttons' | 'defaultId' | 'cancelId'>; | ||
|
||
export class InstallationValidator { | ||
/** | ||
* Shows a dialog box with an option to open the problematic file in the native shell file viewer. | ||
* @param options The options paramter of {@link dialog.showMessageBox}, filled with defaults for invalid config | ||
* @returns | ||
*/ | ||
static async showInvalidFileAndQuit(file: string, options: MessageBoxOptions): Promise<void> { | ||
const defaults: Partial<Electron.MessageBoxOptions> = { | ||
title: 'Invalid file', | ||
type: 'error', | ||
buttons: ['Open the &directory and quit', '&Quit'], | ||
defaultId: 0, | ||
cancelId: 1, | ||
normalizeAccessKeys: true, | ||
}; | ||
const opt = Object.assign(defaults, options); | ||
|
||
const result = await dialog.showMessageBox(opt); | ||
|
||
// Try show the file in file manager | ||
if (result.response === 0) { | ||
try { | ||
const parsed = path.parse(file); | ||
log.debug(`Attempting to open containing directory: ${parsed.dir}`); | ||
await fs.access(file); | ||
shell.showItemInFolder(file); | ||
} catch (error) { | ||
log.warn(`Could not access file whilst attempting to exit gracefully after a critical error.`, file); | ||
try { | ||
// Failed - try the parent dir | ||
const parsed = path.parse(file); | ||
await fs.access(parsed.dir); | ||
shell.openPath(parsed.dir); | ||
} catch (error) { | ||
// Nothing works. Log, notify, quit. | ||
log.error( | ||
`Could not read directory containing file, whilst attempting to exit gracefully after a critical error.` | ||
); | ||
dialog.showErrorBox( | ||
'Unable to fine file', | ||
`Unable to find the file. Please navigate to it manually:\n\n${file}` | ||
); | ||
} | ||
} | ||
} | ||
|
||
app.quit(); | ||
// Wait patiently for graceful termination. | ||
await new Promise(() => {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.