Skip to content

Commit b13d3fc

Browse files
chkpwdraycastbot
andauthored
adding needed changes (#18987)
* chore: change casing on cmd * chore: update func names * fix: resolve paths from preferences * chore: log if folder exist * chore: organize imports * fix(bug): allow path to be resolved during runtime * fix: adjust stripServiceName expression * add dynamic icon support * refactor: set unused tasks to diasbled by default * feat: add new overwrite preference action * refator: renamed primary action var * feat: import now performs all needed actions * style: memoize the dir path * style: set title uppercase * update changelog * style: switched to showFailureToast * style: add recursive to folder recreation * style: add consistency with cli binary * not part of this pr * style: fix linting * Update CHANGELOG.md and optimise images --------- Co-authored-by: raycastbot <[email protected]>
1 parent c32785a commit b13d3fc

File tree

8 files changed

+182
-31
lines changed

8 files changed

+182
-31
lines changed

extensions/ente-auth/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Ente Auth Changelog
22

3+
## [Enhancements & Fixes] - 2025-05-08
4+
5+
- Import command now performs all necessary setup actions automatically
6+
- Added a new "overwrite preference" action for finer control over import behavior
7+
- Introduced dynamic icon support for improved visual feedback
8+
- Set unused tasks to be disabled by default
9+
- Improved path resolution using preferences
10+
- Renamed primary action variable for clarity
11+
- Refactored command and function naming for consistency
12+
- Corrected `stripServiceName` logic to handle edge cases
13+
- Restructured imports and added logging when folders already exist
14+
315
## [Bug fix] - 2024-11-14
416
- Allow path to be resolved during runtime (e.g ~/Desktop/Ente)
517

extensions/ente-auth/package-lock.json

+114
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ente-auth/package.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"name": "export",
3434
"title": "Export Secrets",
3535
"description": "Export Ente Auth secrets to a JSON file",
36+
"disabledByDefault": true,
3637
"mode": "view"
3738
},
3839
{
@@ -45,6 +46,7 @@
4546
"name": "delete",
4647
"title": "Delete Export",
4748
"description": "Delete Ente Auth Exported file",
49+
"disabledByDefault": true,
4850
"mode": "no-view"
4951
}
5052
],
@@ -66,7 +68,7 @@
6668
"placeholder": "Export Path"
6769
},
6870
{
69-
"name": "action",
71+
"name": "primaryAction",
7072
"type": "dropdown",
7173
"title": "Primary Action",
7274
"description": "Choose whether the primary action should copy or paste the output.",
@@ -82,15 +84,32 @@
8284
],
8385
"default": "paste",
8486
"required": false
87+
},
88+
{
89+
"name": "overwriteAction",
90+
"type": "checkbox",
91+
"title": "Options",
92+
"label": "Overwrite Current Export",
93+
"description": "Choose whether the export should overwrite on runs.",
94+
"required": false
95+
},
96+
{
97+
"name": "deleteExport",
98+
"type": "checkbox",
99+
"label": "Delete Export File After Import",
100+
"description": "Choose whether the export should be deleted after import.",
101+
"required": false
85102
}
86103
],
87104
"dependencies": {
88105
"@raycast/api": "^1.81.2",
89106
"@raycast/utils": "^1.16.3",
107+
"axios": "^1.7.8",
90108
"commander": "^9.0.0",
91109
"figlet": "^1.7.0",
92110
"fs-extra": "^11.2.0",
93111
"otpauth": "^9.3.2",
112+
"simple-icons": "^13.18.0",
94113
"ts-node": "^10.0.0",
95114
"typescript": "^4.0.0",
96115
"url-parse": "^1.5.10"

extensions/ente-auth/src/constants/ente.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import { getPreferenceValues } from "@raycast/api";
22
import os from "os";
33
import path from "path";
44

5-
export const DEFAULT_EXPORT_DIR_PATH = (): string => {
6-
const exportPath = getPreferenceValues().exportPath || path.join(process.env.HOME || "", "Documents", "ente");
5+
let cachedExportDirPath: string;
76

8-
if (exportPath.startsWith("~/")) {
9-
return exportPath.replace("~", os.homedir());
7+
export const DEFAULT_EXPORT_DIR_PATH = (): string => {
8+
if (cachedExportDirPath) {
9+
return cachedExportDirPath;
1010
}
1111

12-
return exportPath;
12+
const exportPath = getPreferenceValues().exportPath || path.join(os.homedir(), "Documents", "ente");
13+
14+
cachedExportDirPath = exportPath.startsWith("~/") ? exportPath.replace("~", os.homedir()) : exportPath;
15+
16+
return cachedExportDirPath;
1317
};
1418

1519
export const EXPORT_FILE_PATH = `${DEFAULT_EXPORT_DIR_PATH()}/ente_auth.txt`;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const LINE_BREAK = "\n\n";
2-
export const stripServiceName = (serviceName: string) => serviceName.replace(/-/g, "_").toLowerCase();
2+
export const stripServiceName = (serviceName: string) => serviceName.replace(/-| /g, "").toLowerCase();

extensions/ente-auth/src/export.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Detail, showToast, Toast } from "@raycast/api";
1+
import { Detail } from "@raycast/api";
2+
import { showFailureToast } from "@raycast/utils";
23
import { showError } from "./components/showError";
34
import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente";
45
import { checkEnteBinary, createEntePath, exportEnteAuthSecrets } from "./helpers/ente";
@@ -14,14 +15,14 @@ export default function Command() {
1415
try {
1516
createEntePath(DEFAULT_EXPORT_DIR_PATH());
1617
} catch (error) {
17-
showToast(Toast.Style.Failure, "Folder creation failed");
18-
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH}\``} />;
18+
showFailureToast(error, { title: "Folder creation failed" });
19+
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH()}\``} />;
1920
}
2021

2122
try {
2223
exportEnteAuthSecrets();
2324
} catch (error) {
24-
showToast(Toast.Style.Failure, "Export failed");
25+
showFailureToast(error, { title: "Export failed" });
2526
}
2627

2728
const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));

extensions/ente-auth/src/helpers/ente.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const DEFAULT_CLI_PATH = getPreferenceValues().cliPath || "/usr/local/bin/ente";
77

88
export const createEntePath = (path: string): string => {
99
if (!fse.existsSync(path)) {
10-
fse.mkdirSync(path);
10+
fse.mkdirSync(path, { recursive: true });
1111
console.log("Ente folder created at", path);
1212
} else {
1313
console.log("Ente folder already exists at", path);
@@ -30,7 +30,7 @@ export const exportEnteAuthSecrets = (): boolean => {
3030
if (!fse.existsSync(EXPORT_FILE_PATH)) {
3131
console.log("ente_auth.txt not found. Exporting...");
3232
try {
33-
execSync("ente export");
33+
execSync(`${DEFAULT_CLI_PATH} export`);
3434
} catch (error) {
3535
throw new Error("Export failed. Please check if the command is correct.");
3636
}

extensions/ente-auth/src/import.tsx

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
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";
34
import { getSecrets, parseSecrets, storeSecrets } from "./helpers/secrets";
45

56
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+
}
1012

1113
try {
14+
createEntePath(DEFAULT_EXPORT_DIR_PATH());
15+
exportEnteAuthSecrets();
16+
1217
const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
1318
await storeSecrets(secrets);
1419

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";
2423
} catch (error) {
2524
toast.style = Toast.Style.Failure;
2625
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";
27+
}
28+
29+
if (getPreferenceValues().deleteExport == true) {
30+
deleteEnteExport();
3031
}
3132
}

0 commit comments

Comments
 (0)