From 64fab8d63780bff18f0c093a7c84eacfcc18e0af Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 30 Nov 2024 04:10:42 +1100 Subject: [PATCH] Add better handling for showing file on exit --- src/install/installationValidator.ts | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/install/installationValidator.ts b/src/install/installationValidator.ts index 45abfe52..b92ebabb 100644 --- a/src/install/installationValidator.ts +++ b/src/install/installationValidator.ts @@ -1,4 +1,7 @@ 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 { /** @@ -21,7 +24,33 @@ export class InstallationValidator { const result = await dialog.showMessageBox(opt); - if (result.response === 0) shell.showItemInFolder(file); + // 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(() => {});