Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Prune remaining desktop comments

Manav Rathi6eac73467135
diff --git a/desktop/src/main/utils/common.ts b/desktop/src/main/utils/common.ts
index 7086e63407..caf8dcae89 100644
--- a/desktop/src/main/utils/common.ts
+++ b/desktop/src/main/utils/common.ts
@@ -1,25 +1,5 @@
-/**
- * @file grab bag of utility functions.
- *
- * These are verbatim copies of functions from web code since there isn't
- * currently a common package that both of them share.
- */
-
-/**
- * Wait for {@link ms} milliseconds
- *
- * This function is a promisified `setTimeout`. It returns a promise that
- * resolves after {@link ms} milliseconds.
- *
- * Duplicated from `web/packages/utils/promise.ts`.
- */
export const wait = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
-/**
- * Convert `null` to `undefined`, passthrough everything else unchanged.
- *
- * Duplicated from `web/packages/utils/transform.ts`.
- */
export const nullToUndefined = <T>(v: T | null | undefined): T | undefined =>
v === null ? undefined : v;
diff --git a/desktop/src/main/utils/electron.ts b/desktop/src/main/utils/electron.ts
index c11391dd65..9d31f1a914 100644
--- a/desktop/src/main/utils/electron.ts
+++ b/desktop/src/main/utils/electron.ts
@@ -5,50 +5,14 @@ import path from "node:path";
import { promisify } from "node:util";
import log from "../log";
-/** `true` if the app is running in development mode. */
export const isDev = !app.isPackaged;
-/**
- * Convert a file system {@link platformPath} that uses the local system
- * specific path separators into a path that uses POSIX file separators.
- *
- * For all paths that we persist or pass over the IPC boundary, we always use
- * POSIX paths, even on Windows.
- *
- * Windows recognizes both forward and backslashes. This also works with drive
- * names. c:\foo\bar and c:/foo/bar are both valid.
- *
- * > Almost all paths passed to Windows APIs are normalized. During
- * > normalization, Windows performs the following steps: ... All forward
- * > slashes (/) are converted into the standard Windows separator, the back
- * > slash (\).
- * >
- * > https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
- */
+// Persisted and IPC paths use POSIX separators on every platform.
export const posixPath = (platformPath: string) =>
path.sep == path.posix.sep
? platformPath
: platformPath.split(path.sep).join(path.posix.sep);
-/**
- * Run a shell command asynchronously.
- *
- * This is a convenience promisified version of child_process.exec. It runs the
- * command asynchronously and returns its stdout and stderr if there were no
- * errors.
- *
- * If the command is passed as a string, then it will be executed verbatim.
- *
- * If the command is passed as an array, then the first argument will be treated
- * as the executable and the remaining (optional) items as the command line
- * parameters. This function will shellescape and join the array to form the
- * command that finally gets executed.
- *
- * > Note: This is not a 1-1 replacement of child_process.exec - if you're
- * > trying to run a trivial shell command, say something that produces a lot of
- * > output, this might not be the best option and it might be better to use the
- * > underlying functions.
- */
export const execAsync = async (command: string | string[]) => {
const escapedCommand = Array.isArray(command)
? shellescape(command)
diff --git a/desktop/src/main/utils/exec-worker.ts b/desktop/src/main/utils/exec-worker.ts
index 02ac116a6d..c034da43e3 100644
--- a/desktop/src/main/utils/exec-worker.ts
+++ b/desktop/src/main/utils/exec-worker.ts
@@ -3,13 +3,6 @@ import { exec } from "node:child_process";
import { promisify } from "node:util";
import log from "../log-worker";
-/**
- * Run a shell command asynchronously (utility process edition).
- *
- * This is an almost verbatim copy of {@link execAsync} from `electron.ts`,
- * except it is meant to be usable from a utility process where only a subset of
- * imports are available. See [Note: Using Electron APIs in UtilityProcess].
- */
export const execAsyncWorker = async (command: string | string[]) => {
const escapedCommand = Array.isArray(command)
? shellescape(command)
diff --git a/desktop/src/main/utils/http.ts b/desktop/src/main/utils/http.ts
index 91a476fed9..298ed0e2be 100644
--- a/desktop/src/main/utils/http.ts
+++ b/desktop/src/main/utils/http.ts
@@ -1,27 +1,11 @@
export const clientPackageName = "io.ente.photos.desktop";
-/**
- * Reimplementation of {@link publicRequestHeaders} from the web source.
- *
- * @param desktopAppVersion The desktop app's version. This will get passed on
- * as the "X-Client-Version" header.
- *
- * We cannot directly use `app.getVersion()` to obtain this value since the
- * {@link app} module is not accessible to Electron utility processes which also
- * calls this function.
- */
+// Utility processes cannot import Electron's app module, so callers supply the version.
export const publicRequestHeaders = (desktopAppVersion: string) => ({
"X-Client-Package": clientPackageName,
"X-Client-Version": desktopAppVersion,
});
-/**
- * Reimplementation of {@link authenticatedRequestHeaders} from the web source.
- *
- * This builds on top of {@link publicRequestHeaders} and takes the same
- * parameters, and additionally also requires the {@link authToken} that will be
- * passed as the "X-Auth-Token" header.
- */
export const authenticatedRequestHeaders = (
desktopAppVersion: string,
authToken: string,
diff --git a/desktop/src/main/utils/stream.ts b/desktop/src/main/utils/stream.ts
index cfa3327ffc..59943e6d64 100644
--- a/desktop/src/main/utils/stream.ts
+++ b/desktop/src/main/utils/stream.ts
@@ -2,27 +2,16 @@ import { createWriteStream, existsSync } from "node:fs";
import fs from "node:fs/promises";
import { Readable } from "node:stream";
-/**
- * Write a (web) ReadableStream to a file at the given {@link filePath}.
- *
- * The returned promise resolves when the write completes.
- *
- * @param filePath The local file system path where the file should be written.
- *
- * @param readableStream A web
- * [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
- *
- */
export const writeStream = (
filePath: string,
- readableStream: unknown /*ReadableStream*/, // @ts-expect-error [Note: Node and web stream type mismatch]
+ readableStream: unknown, // @ts-expect-error Node and web ReadableStream types disagree.
) => writeNodeStream(filePath, Readable.fromWeb(readableStream));
const writeNodeStream = async (filePath: string, fileStream: Readable) => {
const writeable = createWriteStream(filePath);
fileStream.on("error", (err) => {
- writeable.destroy(err); // Close the writable stream with an error
+ writeable.destroy(err);
});
fileStream.pipe(writeable);
diff --git a/desktop/src/main/utils/temp.ts b/desktop/src/main/utils/temp.ts
index ad874dd216..cd245542ef 100644
--- a/desktop/src/main/utils/temp.ts
+++ b/desktop/src/main/utils/temp.ts
@@ -7,17 +7,12 @@ import log from "../log";
import { markClosableZip, openZip } from "../services/zip";
import { writeStream } from "./stream";
-/**
- * Our very own directory within the system temp directory. Go crazy, but
- * remember to clean up, especially in exception handlers.
- */
const enteTempDirPath = async () => {
const result = path.join(app.getPath("temp"), "ente");
await fs.mkdir(result, { recursive: true });
return result;
};
-/** Generate a random string suitable for being used as a file name prefix */
const randomPrefix = () => {
const ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const randomChar = () => ch[Math.floor(Math.random() * ch.length)]!;
@@ -25,21 +20,6 @@ const randomPrefix = () => {
return Array(10).fill("").map(randomChar).join("");
};
-/**
- * Return the path to a temporary file with an optional {@link extension}.
- *
- * The function returns the path to a file in the system temp directory (in an
- * Ente specific folder therin) with a random prefix and an (optional)
- * {@link extension}. The parent directory is guaranteed to exist.
- *
- * @param extension A string, if provided, is used as the extension for the
- * generated path. It will be automatically prefixed by a dot, so don't include
- * the dot in the provided string.
- *
- * It ensures that there is no existing item with the same name already.
- *
- * Use {@link deleteTempFile} to remove this file when you're done.
- */
export const makeTempFilePath = async (extension?: string) => {
const tempDir = await enteTempDirPath();
const suffix = extension ? "." + extension : "";
@@ -50,16 +30,6 @@ export const makeTempFilePath = async (extension?: string) => {
return result;
};
-/**
- * Delete a temporary file at the given path if it exists.
- *
- * This is the same as a vanilla {@link fs.rm}, except it first checks that the
- * given path is within the Ente specific directory in the system temp
- * directory. This acts as an additional safety check.
- *
- * @param tempFilePath The path to the temporary file to delete. This path
- * should've been previously created using {@link makeTempFilePath}.
- */
export const deleteTempFile = async (tempFilePath: string) => {
const tempDir = await enteTempDirPath();
if (!tempFilePath.startsWith(tempDir))
@@ -67,11 +37,6 @@ export const deleteTempFile = async (tempFilePath: string) => {
await fs.rm(tempFilePath, { force: true });
};
-/**
- * A variant of {@link deleteTempFile} that suppresses any errors, making it
- * safe to call them in a sequence without needing to handle the scenario where
- * one of them failing causes the rest to be skipped.
- */
export const deleteTempFileIgnoringErrors = async (tempFilePath: string) => {
try {
await deleteTempFile(tempFilePath);
@@ -80,37 +45,12 @@ export const deleteTempFileIgnoringErrors = async (tempFilePath: string) => {
}
};
-/** The result of {@link makeFileForStreamOrPathOrZipItem}. */
interface FileForStreamOrPathOrZipItem {
- /**
- * The path to the file (possibly temporary).
- */
path: string;
- /**
- * `true` if {@link path} points to a temporary file which should be deleted
- * once we are done processing.
- */
isFileTemporary: boolean;
- /**
- * A function that can be called to actually write the contents of the
- * source `Uint8Array | string | ZipItem` into the file at {@link path}.
- *
- * It will do nothing in the case when the source is already a path. In the
- * other two cases this function will write the data or zip item into the
- * file at {@link path}.
- */
writeToTemporaryFile: () => Promise<void>;
}
-/**
- * Return the path to a file, a boolean indicating if this is a temporary path
- * that needs to be deleted after processing, and a function to write the given
- * {@link item} into that temporary file if needed.
- *
- * @param item A {@link ReadableStream} with the contents of the file, or the
- * path to an existing file, or a (path to a zip file, name of an entry within
- * that zip file) tuple.
- */
export const makeFileForStreamOrPathOrZipItem = async (
item: ReadableStream | string | ZipItem,
): Promise<FileForStreamOrPathOrZipItem> => {
diff --git a/desktop/src/types/ipc.ts b/desktop/src/types/ipc.ts
index 08ab5f2b15..9ee53e4fae 100644
--- a/desktop/src/types/ipc.ts
+++ b/desktop/src/types/ipc.ts
@@ -1,10 +1,4 @@
-/**
- * @file types that are shared across the IPC boundary with the renderer process
- *
- * This file is manually kept in sync with the renderer code.
- * See [Note: types.ts <-> preload.ts <-> ipc.ts]
- */
-
+// Keep these definitions in sync with web/packages/base/types/ipc.ts.
export type UtilityProcessType = "ml";
export interface AppUpdate {
@@ -12,41 +6,21 @@ export interface AppUpdate {
version: string;
}
-/**
- * Native provider used for desktop app lock authentication.
- *
- * `touchid` means we can use the platform-native auth prompt.
- * `none` means no supported native provider is currently available.
- */
export type NativeDeviceLockProvider = "touchid" | "none";
-/**
- * Why native device lock is unavailable on this machine/session.
- */
export type NativeDeviceLockUnavailableReason =
| "unsupported-platform"
| "touchid-not-enrolled"
| "touchid-temporarily-unavailable"
| "touchid-api-error";
-/**
- * Capability metadata returned by main-process device-lock checks.
- */
export interface NativeDeviceLockCapability {
- /** True when native auth can be prompted right now. */
available: boolean;
- /** Which native provider backs authentication (if available). */
provider: NativeDeviceLockProvider;
- /** Present when unavailable, with a machine-readable reason. */
reason?: NativeDeviceLockUnavailableReason;
}
-/**
- * Persisted desktop app-lock configuration.
- *
- * This excludes the passphrase hash material, which continues to live in the
- * renderer KV DB.
- */
+// Passphrase hashes remain in renderer KV storage.
export interface PersistedAppLockConfig {
enabled: boolean;
lockType: "pin" | "password" | "device" | "none";
@@ -58,13 +32,7 @@ export interface FolderWatch {
folderPath: string;
syncedFiles: FolderWatchSyncedFile[];
ignoredFiles: string[];
- /**
- * Whether the folder is currently accessible on disk.
- *
- * Folders on ejected external drives will have this set to false. This
- * property is not persisted and is computed each time the watch list is
- * fetched.
- */
+ // Computed on read; false for ejected external drives.
isAccessible?: boolean;
}