From 75801bfaf4a0123fc5c12ae020d6a0f0800b0d56 Mon Sep 17 00:00:00 2001 From: Frank Kopp Date: Fri, 2 Feb 2024 22:39:05 +0100 Subject: [PATCH] Added error message to clipboard --- src/renderer/components/Modal/ErrorDialog.tsx | 69 ++++++++++++++++--- src/renderer/components/SentrySessionCard.tsx | 7 +- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/renderer/components/Modal/ErrorDialog.tsx b/src/renderer/components/Modal/ErrorDialog.tsx index 58386037..782f1a7f 100644 --- a/src/renderer/components/Modal/ErrorDialog.tsx +++ b/src/renderer/components/Modal/ErrorDialog.tsx @@ -1,7 +1,7 @@ -import React, { FC } from 'react'; +import React, { FC, useState } from 'react'; import { AlertModal } from "renderer/components/Modal/index"; -import { ExclamationTriangle, Hdd, Shield } from "react-bootstrap-icons"; -import { shell } from "electron"; +import { Clipboard, ClipboardCheck, ExclamationTriangle, Hdd, Shield } from "react-bootstrap-icons"; +import { clipboard, shell } from "electron"; import { FragmenterError, FragmenterErrorCode } from "@flybywiresim/fragmenter"; import { SentrySessionCard } from "renderer/components/SentrySessionCard"; @@ -27,30 +27,67 @@ export const ErrorDialog: FC = ({ error, onAcknowledge }) => { let errorVisualisation = null; if (fragmenterError) { switch (fragmenterError.code) { + case FragmenterErrorCode.Null: + break; case FragmenterErrorCode.PermissionsError: errorVisualisation = ( }> Windows permissions error - Make sure the install folder has appropriate permissions. ); break; + case FragmenterErrorCode.ResourcesBusy: + break; case FragmenterErrorCode.NoSpaceOnDevice: errorVisualisation = ( }> No space left on device - Try to free up space in order to install this addon. ); break; + case FragmenterErrorCode.NetworkError: // fallthrough + errorVisualisation = ( + }> + Network error + Try again or use a VPN when connection problems persist. + + ); + break; + case FragmenterErrorCode.MaxModuleRetries: // fallthrough + errorVisualisation = ( + }> + Maximum number of download retries reached + Try again or check your network settings. Use a VPN when connection problems persist. + + ); + break; + case FragmenterErrorCode.FileNotFound: // fallthrough + case FragmenterErrorCode.DirectoryNotEmpty: // fallthrough + case FragmenterErrorCode.NotADirectory: // fallthrough + case FragmenterErrorCode.ModuleJsonInvalid: // fallthrough + case FragmenterErrorCode.ModuleCrcMismatch: // fallthrough + case FragmenterErrorCode.UserAborted: // fallthrough + case FragmenterErrorCode.CorruptedZipFile: // fallthrough + case FragmenterErrorCode.Unknown: // fallthrough default: errorVisualisation = null; break; } } + // Error stack to clipboard handling + const [showCopied, setShowCopied] = useState(false); + const handleCopy = () => { + clipboard.writeText(error.stack, 'clipboard'); + setShowCopied(true); + setTimeout(() => { + setShowCopied(false); + }, 1_500); + }; + return ( = ({ error, onAcknowledge }) => {

An error occurred while installing this addon.

- {errorVisualisation} -
{error.stack}
-

Obtain support with a screenshot of this dialog on Discord:

- +

Obtain support on Discord and provide the error message and on request + the sentry code:

+
+ Copy error message to clipboard: +
+ {showCopied ? ( + + Copied + + + ) : ( + + )} +
+
diff --git a/src/renderer/components/SentrySessionCard.tsx b/src/renderer/components/SentrySessionCard.tsx index 11baa952..ab095c74 100644 --- a/src/renderer/components/SentrySessionCard.tsx +++ b/src/renderer/components/SentrySessionCard.tsx @@ -19,8 +19,8 @@ export const SentrySessionCard: FC = () => { }; return ( -
- {sessionID} +
+ Copy Sentry Code to clipboard: {sessionID}
{showCopied ? ( @@ -30,7 +30,8 @@ export const SentrySessionCard: FC = () => { ) : ( - + )}