|
1 |
| -import { showToast, Toast } from "@raycast/api"; |
2 |
| -import { EXPORT_FILE_PATH } from "./constants/ente"; |
| 1 | +import { getPreferenceValues, showToast, Toast } from "@raycast/api"; |
| 2 | +import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente"; |
| 3 | +import { checkEnteBinary, createEntePath, deleteEnteExport, exportEnteAuthSecrets } from "./helpers/ente"; |
3 | 4 | import { getSecrets, parseSecrets, storeSecrets } from "./helpers/secrets";
|
4 | 5 |
|
5 | 6 | export default async function Command() {
|
6 |
| - const toast = await showToast({ |
7 |
| - style: Toast.Style.Animated, |
8 |
| - title: "Importing secrets", |
9 |
| - }); |
| 7 | + const toast = await showToast({ style: Toast.Style.Animated, title: "Importing secrets" }); |
| 8 | + |
| 9 | + if (!checkEnteBinary()) { |
| 10 | + showToast(Toast.Style.Failure, "Ente binary not found"); |
| 11 | + } |
10 | 12 |
|
11 | 13 | try {
|
| 14 | + createEntePath(DEFAULT_EXPORT_DIR_PATH()); |
| 15 | + exportEnteAuthSecrets(); |
| 16 | + |
12 | 17 | const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
|
13 | 18 | await storeSecrets(secrets);
|
14 | 19 |
|
15 |
| - if (secrets.length > 0) { |
16 |
| - toast.style = Toast.Style.Success; |
17 |
| - toast.title = " "; |
18 |
| - toast.message = `${secrets.length} secrets imported!`; |
19 |
| - } else { |
20 |
| - toast.style = Toast.Style.Failure; |
21 |
| - toast.title = "No secrets found"; |
22 |
| - toast.message = "Please check your export path"; |
23 |
| - } |
| 20 | + toast.style = secrets.length > 0 ? Toast.Style.Success : Toast.Style.Failure; |
| 21 | + toast.title = secrets.length > 0 ? `${secrets.length} secrets imported!` : "No secrets found"; |
| 22 | + toast.message = secrets.length > 0 ? "" : "Please check your export path"; |
24 | 23 | } catch (error) {
|
25 | 24 | toast.style = Toast.Style.Failure;
|
26 | 25 | toast.title = "Error importing secrets";
|
27 |
| - if (error instanceof Error) { |
28 |
| - toast.message = error.message; |
29 |
| - } |
| 26 | + toast.message = error instanceof Error ? error.message : "Unknown error"; |
30 | 27 | }
|
| 28 | + |
| 29 | + if (getPreferenceValues().deleteExport == true) { |
| 30 | + deleteEnteExport(); |
| 31 | + }; |
31 | 32 | }
|
0 commit comments