-
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.
* Rename window settings: AppWindowSettings * Add settings store, required for startup If present, the config must be valid to proceed with app startup. * Add shell open option to debug * Add initial DesktopSettings type * Use app settings store for install state * Add setting store reset to resetInstall script * 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. * [Refactor] Desktop config store back to class * Add better handling for showing file on exit * Add documentation --------- Co-authored-by: huchenlei <[email protected]>
- Loading branch information
1 parent
bf9a3c0
commit 54f1a96
Showing
7 changed files
with
282 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { app, dialog, shell } from 'electron'; | ||
import fs from 'fs/promises'; | ||
import log from 'electron-log/main'; | ||
import path from 'node:path'; | ||
|
||
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); | ||
|
||
// 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
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.