Skip to content

adding needed changes #18987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions extensions/ente-auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Ente Auth Changelog

## [Enhancements & Fixes] - 2025-05-08

- Import command now performs all necessary setup actions automatically
- Added a new "overwrite preference" action for finer control over import behavior
- Introduced dynamic icon support for improved visual feedback
- Set unused tasks to be disabled by default
- Improved path resolution using preferences
- Renamed primary action variable for clarity
- Refactored command and function naming for consistency
- Corrected `stripServiceName` logic to handle edge cases
- Restructured imports and added logging when folders already exist

## [Bug fix] - 2024-11-14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: The title should use the {PR_MERGE_DATE} placeholder instead of a hardcoded date. Change to ## [Bug fix] - {PR_MERGE_DATE}

Suggested change
## [Bug fix] - 2024-11-14
## [Bug fix] - {PR_MERGE_DATE}

- Allow path to be resolved during runtime (e.g ~/Desktop/Ente)

Expand Down
114 changes: 114 additions & 0 deletions extensions/ente-auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion extensions/ente-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"name": "export",
"title": "Export Secrets",
"description": "Export Ente Auth secrets to a JSON file",
"disabledByDefault": true,
"mode": "view"
},
{
Expand All @@ -45,6 +46,7 @@
"name": "delete",
"title": "Delete Export",
"description": "Delete Ente Auth Exported file",
"disabledByDefault": true,
"mode": "no-view"
}
],
Expand All @@ -66,7 +68,7 @@
"placeholder": "Export Path"
},
{
"name": "action",
"name": "primaryAction",
"type": "dropdown",
"title": "Primary Action",
"description": "Choose whether the primary action should copy or paste the output.",
Expand All @@ -82,15 +84,32 @@
],
"default": "paste",
"required": false
},
{
"name": "overwriteAction",
"type": "checkbox",
"title": "Options",
"label": "Overwrite Current Export",
"description": "Choose whether the export should overwrite on runs.",
"required": false
},
{
"name": "deleteExport",
"type": "checkbox",
"label": "Delete Export File After Import",
"description": "Choose whether the export should be deleted after import.",
"required": false
}
],
"dependencies": {
"@raycast/api": "^1.81.2",
"@raycast/utils": "^1.16.3",
"axios": "^1.7.8",
"commander": "^9.0.0",
"figlet": "^1.7.0",
"fs-extra": "^11.2.0",
"otpauth": "^9.3.2",
"simple-icons": "^13.18.0",
"ts-node": "^10.0.0",
"typescript": "^4.0.0",
"url-parse": "^1.5.10"
Expand Down
14 changes: 9 additions & 5 deletions extensions/ente-auth/src/constants/ente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { getPreferenceValues } from "@raycast/api";
import os from "os";
import path from "path";

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

if (exportPath.startsWith("~/")) {
return exportPath.replace("~", os.homedir());
export const DEFAULT_EXPORT_DIR_PATH = (): string => {
if (cachedExportDirPath) {
return cachedExportDirPath;
}

return exportPath;
const exportPath = getPreferenceValues().exportPath || path.join(os.homedir(), "Documents", "ente");

cachedExportDirPath = exportPath.startsWith("~/") ? exportPath.replace("~", os.homedir()) : exportPath;

return cachedExportDirPath;
};

export const EXPORT_FILE_PATH = `${DEFAULT_EXPORT_DIR_PATH()}/ente_auth.txt`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: DEFAULT_EXPORT_DIR_PATH() is called on every reference - consider memoizing the result

2 changes: 1 addition & 1 deletion extensions/ente-auth/src/constants/string.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const LINE_BREAK = "\n\n";
export const stripServiceName = (serviceName: string) => serviceName.replace(/-/g, "_").toLowerCase();
export const stripServiceName = (serviceName: string) => serviceName.replace(/-| /g, "").toLowerCase();
9 changes: 5 additions & 4 deletions extensions/ente-auth/src/export.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Detail, showToast, Toast } from "@raycast/api";
import { Detail } from "@raycast/api";
import { showFailureToast } from "@raycast/utils";
import { showError } from "./components/showError";
import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente";
import { checkEnteBinary, createEntePath, exportEnteAuthSecrets } from "./helpers/ente";
Expand All @@ -14,14 +15,14 @@ export default function Command() {
try {
createEntePath(DEFAULT_EXPORT_DIR_PATH());
} catch (error) {
showToast(Toast.Style.Failure, "Folder creation failed");
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH}\``} />;
showFailureToast(error, { title: "Folder creation failed" });
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH()}\``} />;
}

try {
exportEnteAuthSecrets();
} catch (error) {
showToast(Toast.Style.Failure, "Export failed");
showFailureToast(error, { title: "Export failed" });
}

const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: getSecrets and parseSecrets calls should be wrapped in try-catch as they could throw errors

Suggested change
const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
let secrets = [];
try {
secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
} catch (error) {
showFailureToast(error, { title: "Failed to read secrets" });
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/ente-auth/src/helpers/ente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_CLI_PATH = getPreferenceValues().cliPath || "/usr/local/bin/ente";

export const createEntePath = (path: string): string => {
if (!fse.existsSync(path)) {
fse.mkdirSync(path);
fse.mkdirSync(path, { recursive: true });
console.log("Ente folder created at", path);
} else {
console.log("Ente folder already exists at", path);
Expand All @@ -30,7 +30,7 @@ export const exportEnteAuthSecrets = (): boolean => {
if (!fse.existsSync(EXPORT_FILE_PATH)) {
console.log("ente_auth.txt not found. Exporting...");
try {
execSync("ente export");
execSync(`${DEFAULT_CLI_PATH} export`);
} catch (error) {
throw new Error("Export failed. Please check if the command is correct.");
}
Expand Down
37 changes: 19 additions & 18 deletions extensions/ente-auth/src/import.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { showToast, Toast } from "@raycast/api";
import { EXPORT_FILE_PATH } from "./constants/ente";
import { getPreferenceValues, showToast, Toast } from "@raycast/api";
import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente";
import { checkEnteBinary, createEntePath, deleteEnteExport, exportEnteAuthSecrets } from "./helpers/ente";
import { getSecrets, parseSecrets, storeSecrets } from "./helpers/secrets";

export default async function Command() {
const toast = await showToast({
style: Toast.Style.Animated,
title: "Importing secrets",
});
const toast = await showToast({ style: Toast.Style.Animated, title: "Importing secrets" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Multiple toast notifications could cause race conditions. Consider using showFailureToast from @raycast/utils for error cases.


if (!checkEnteBinary()) {
showToast(Toast.Style.Failure, "Ente binary not found");
}
Comment on lines +9 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The function continues execution after showing the binary not found error. This should return early to prevent further operations.

Suggested change
if (!checkEnteBinary()) {
showToast(Toast.Style.Failure, "Ente binary not found");
}
if (!checkEnteBinary()) {
showToast(Toast.Style.Failure, "Ente binary not found");
return;
}


try {
createEntePath(DEFAULT_EXPORT_DIR_PATH());
exportEnteAuthSecrets();
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: These operations could fail but their errors aren't being caught. They should be inside the try block or have their own error handling.


const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH));
await storeSecrets(secrets);

if (secrets.length > 0) {
toast.style = Toast.Style.Success;
toast.title = " ";
toast.message = `${secrets.length} secrets imported!`;
} else {
toast.style = Toast.Style.Failure;
toast.title = "No secrets found";
toast.message = "Please check your export path";
}
toast.style = secrets.length > 0 ? Toast.Style.Success : Toast.Style.Failure;
toast.title = secrets.length > 0 ? `${secrets.length} secrets imported!` : "No secrets found";
toast.message = secrets.length > 0 ? "" : "Please check your export path";
} catch (error) {
toast.style = Toast.Style.Failure;
toast.title = "Error importing secrets";
if (error instanceof Error) {
toast.message = error.message;
}
toast.message = error instanceof Error ? error.message : "Unknown error";
}

if (getPreferenceValues().deleteExport == true) {
deleteEnteExport();
}
}