-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file validation to pre-window checks
Provides the user with some information about what went wrong and why - and where they can look to fix it. Needs help / support button added.
- Loading branch information
1 parent
f5fed9d
commit d1a1d51
Showing
3 changed files
with
67 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { app, dialog, shell } from 'electron'; | ||
|
||
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: Electron.MessageBoxOptions): Promise<void> { | ||
const defaults: Electron.MessageBoxOptions = { | ||
// Message must be set by caller. | ||
message: `Was unable to read the file shown below. It could be missing, inaccessible, or corrupt.\n\n${file}`, | ||
title: 'Invalid file', | ||
type: 'error', | ||
buttons: ['Locate the &file (then quit)', '&Quit'], | ||
defaultId: 0, | ||
cancelId: 1, | ||
normalizeAccessKeys: true, | ||
}; | ||
const opt = Object.assign(defaults, options); | ||
|
||
const result = await dialog.showMessageBox(opt); | ||
|
||
if (result.response === 0) shell.showItemInFolder(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