Skip to content

Commit

Permalink
Added error message to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkopp committed Feb 2, 2024
1 parent 641a165 commit 75801bf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
69 changes: 60 additions & 9 deletions src/renderer/components/Modal/ErrorDialog.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -27,30 +27,67 @@ export const ErrorDialog: FC<ErrorDialogProps> = ({ error, onAcknowledge }) => {
let errorVisualisation = null;
if (fragmenterError) {
switch (fragmenterError.code) {
case FragmenterErrorCode.Null:
break;
case FragmenterErrorCode.PermissionsError:
errorVisualisation = (
<ErrorVisualisationBox icon={<Shield className="text-utility-red" size={36} />}>
<span className="text-4xl font-bold font-manrope">Windows permissions error</span>

<span className="text-2xl">Make sure the install folder has appropriate permissions.</span>
</ErrorVisualisationBox>
);
break;
case FragmenterErrorCode.ResourcesBusy:
break;
case FragmenterErrorCode.NoSpaceOnDevice:
errorVisualisation = (
<ErrorVisualisationBox icon={<Hdd className="text-utility-red" size={36} />}>
<span className="text-4xl font-bold font-manrope">No space left on device</span>

<span className="text-2xl">Try to free up space in order to install this addon.</span>
</ErrorVisualisationBox>
);
break;
case FragmenterErrorCode.NetworkError: // fallthrough
errorVisualisation = (
<ErrorVisualisationBox icon={<Shield className="text-utility-red" size={36} />}>
<span className="text-4xl font-bold font-manrope">Network error</span>
<span className="text-2xl">Try again or use a VPN when connection problems persist.</span>
</ErrorVisualisationBox>
);
break;
case FragmenterErrorCode.MaxModuleRetries: // fallthrough
errorVisualisation = (
<ErrorVisualisationBox icon={<Shield className="text-utility-red" size={36} />}>
<span className="text-4xl font-bold font-manrope">Maximum number of download retries reached</span>
<span
className="text-2xl">Try again or check your network settings. Use a VPN when connection problems persist.</span>
</ErrorVisualisationBox>
);
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 (
<AlertModal
title={(
Expand All @@ -63,15 +100,29 @@ export const ErrorDialog: FC<ErrorDialogProps> = ({ error, onAcknowledge }) => {
<div className="flex flex-col gap-y-5">
<div className="flex flex-col">
<p>An error occurred while installing this addon.</p>

{errorVisualisation}

<pre className="h-96 bg-gray-800 p-2.5 rounded-md">{error.stack}</pre>
</div>

<div className="flex flex-col">
<p>Obtain support with a screenshot of this dialog on <a onClick={handleOpenDiscordSupport}>Discord</a>:</p>

<p>Obtain support on <a onClick={handleOpenDiscordSupport}>Discord</a> and provide the error message and on request
the sentry code:</p>
<div
className="relative w-full flex justify-center items-center border-2 border-gray-800 text-3xl text-center p-3.5 rounded-md">
<span className="font-mono">Copy error message to clipboard:</span>
<div className="absolute right-3">
{showCopied ? (
<span className="flex items-center gap-x-2.5 text-utility-green">
<span className="text-3xl font-medium">Copied</span>
<ClipboardCheck className="transition-colors duration-200 cursor-pointer" size={24}
onClick={handleCopy} />
</span>
) : (
<Clipboard className="text-gray-500 hover:text-gray-300 transition-colors duration-200 cursor-pointer"
size={24} onClick={handleCopy} />
)}
</div>
</div>
<SentrySessionCard />
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/components/SentrySessionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const SentrySessionCard: FC = () => {
};

return (
<div className="relative w-full flex justify-center items-center border-2 border-gray-800 text-5xl text-center p-3.5 rounded-md">
<span className="font-mono">{sessionID}</span>
<div className="relative w-full flex justify-center items-center border-2 border-gray-800 text-2xl text-center p-3.5 rounded-md">
<span className="font-mono">Copy Sentry Code to clipboard: {sessionID}</span>

<div className="absolute right-3">
{showCopied ? (
Expand All @@ -30,7 +30,8 @@ export const SentrySessionCard: FC = () => {
<ClipboardCheck className="transition-colors duration-200 cursor-pointer" size={24} onClick={handleCopy} />
</span>
) : (
<Clipboard className="text-gray-500 hover:text-gray-300 transition-colors duration-200 cursor-pointer" size={24} onClick={handleCopy} />
<Clipboard className="text-gray-500 hover:text-gray-300 transition-colors duration-200 cursor-pointer" size={24}
onClick={handleCopy} />
)}
</div>
</div>
Expand Down

0 comments on commit 75801bf

Please sign in to comment.