Skip to content

Commit 4b5e846

Browse files
committed
Add option to copy encrypted file path
1 parent d1048f1 commit 4b5e846

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

src/renderer/App.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-alert */
12
/* eslint-disable no-else-return */
23
/* eslint-disable no-console */
34
import { useState } from 'react';
@@ -184,7 +185,19 @@ export default function App() {
184185
return (
185186
<SucessOrErrorModal
186187
onGoHome={() => {
187-
resetToFileUpload();
188+
if (!pathToEncryptedOrDecryptedFile) {
189+
resetToFileUpload();
190+
} else {
191+
navigator.clipboard
192+
.writeText(pathToEncryptedOrDecryptedFile)
193+
.then(() => {
194+
return alert('File path copied to clipboard!');
195+
})
196+
.catch((err) => {
197+
console.error('Failed to copy: ', err);
198+
});
199+
resetToFileUpload();
200+
}
188201
}}
189202
onRevealInFinder={revealInFinder}
190203
errorMessage={undefined}

src/renderer/SuccessOrErrorModal.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,43 @@ export default function SuccessOrErrorModal({
3030

3131
const mainText = isSuccess ? 'Success!' : 'Something went wrong!';
3232

33+
const revealInFinderButton = isSuccess && (
34+
<Button
35+
buttonType="primary"
36+
onClick={() => {
37+
onRevealInFinder();
38+
}}
39+
>
40+
<span className="openFinderText">Reveal in file browser</span>
41+
</Button>
42+
);
43+
const goHomeWithOptionalCopyToClipboard = isSuccess ? (
44+
<Button buttonType="goHome" onClick={onGoHome}>
45+
<span className="backToHomeText">
46+
Copy encrypted file path to clipboard and go home
47+
</span>
48+
</Button>
49+
) : (
50+
<Button buttonType="goHome" onClick={onGoHome}>
51+
<span className="backToHomeText">Return home</span>
52+
</Button>
53+
);
54+
3355
return (
3456
<div className="successOrErrorBody">
3557
<Lottie options={animationOptions} height={100} width={200} />
3658
<span className="successOrErrorHeaderText">{mainText}</span>
3759
{!isSuccess && errorMessage && (
3860
<p className="errorText">
39-
{errorMessage
40-
.split('`')
41-
.map((part, index) =>
42-
index % 2 === 0 ? part : <code className="filePath">{part}</code>,
43-
)}
61+
{errorMessage.split('`').map(
62+
(part, index) =>
63+
index % 2 === 0 ? part : <code className="filePath">{part}</code>, // Split on backticks and render the text as code
64+
)}
4465
</p>
4566
)}
4667
<div className="buttonsWrapper">
47-
{isSuccess && (
48-
<Button
49-
buttonType="primary"
50-
onClick={() => {
51-
onRevealInFinder();
52-
}}
53-
>
54-
<span className="openFinderText">Reveal in file browser</span>
55-
</Button>
56-
)}
57-
<Button buttonType="goHome" onClick={onGoHome}>
58-
<span className="backToHomeText">Return home</span>
59-
</Button>
68+
{revealInFinderButton}
69+
{goHomeWithOptionalCopyToClipboard}
6070
</div>
6171
</div>
6272
);

0 commit comments

Comments
 (0)