π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rearrange
Manav Rathid6aeef85d689
diff --git a/desktop/src/main.ts b/desktop/src/main.tsindex 2774ec730c..4b6db7eac9 100644--- a/desktop/src/main.ts+++ b/desktop/src/main.ts@@ -26,7 +26,7 @@ import { createWatcher } from "./main/services/watch";import { userPreferences } from "./main/stores/user-preferences";import { migrateLegacyWatchStoreIfNeeded } from "./main/stores/watch";import { registerStreamProtocol } from "./main/stream";-import { isDev } from "./main/utils-electron";+import { isDev } from "./main/utils/electron";/*** The URL where the renderer HTML is being served from.diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.tsindex bb5daeabac..eb8b6cdda8 100644--- a/desktop/src/main/ipc.ts+++ b/desktop/src/main/ipc.ts@@ -16,6 +16,19 @@ import type {PendingUploads,ZipItem,} from "../types/ipc";+import { logToDisk } from "./log";+import {+ appVersion,+ skipAppUpdate,+ updateAndRestart,+ updateOnNextRestart,+} from "./services/app-update";+import {+ openDirectory,+ openLogDirectory,+ selectDirectory,+} from "./services/dir";+import { ffmpegExec } from "./services/ffmpeg";import {fsExists,fsIsDir,@@ -25,16 +38,7 @@ import {fsRm,fsRmdir,fsWriteFile,-} from "./fs";-import { logToDisk } from "./log";-import {- appVersion,- skipAppUpdate,- updateAndRestart,- updateOnNextRestart,-} from "./services/app-update";-import { selectDirectory } from "./services/dialog";-import { ffmpegExec } from "./services/ffmpeg";+} from "./services/fs";import { convertToJPEG, generateImageThumbnail } from "./services/image";import {clipImageEmbedding,@@ -63,7 +67,6 @@ import {watchUpdateIgnoredFiles,watchUpdateSyncedFiles,} from "./services/watch";-import { openDirectory, openLogDirectory } from "./utils-electron";/*** Listen for IPC events sent/invoked by the renderer process, and route them todiff --git a/desktop/src/main/log.ts b/desktop/src/main/log.tsindex 22ebb5300a..7fc25a94b0 100644--- a/desktop/src/main/log.ts+++ b/desktop/src/main/log.ts@@ -1,6 +1,6 @@import log from "electron-log";import util from "node:util";-import { isDev } from "./utils-electron";+import { isDev } from "./utils/electron";/*** Initialize logging in the main process.diff --git a/desktop/src/main/menu.ts b/desktop/src/main/menu.tsindex 12b1ee17d3..990dd40e5d 100644--- a/desktop/src/main/menu.ts+++ b/desktop/src/main/menu.ts@@ -9,7 +9,7 @@ import { allowWindowClose } from "../main";import { forceCheckForAppUpdates } from "./services/app-update";import autoLauncher from "./services/auto-launcher";import { userPreferences } from "./stores/user-preferences";-import { isDev, openLogDirectory } from "./utils-electron";+import { isDev, openLogDirectory } from "./utils/electron";/** Create and return the entries in the app's main menu bar */export const createApplicationMenu = async (mainWindow: BrowserWindow) => {diff --git a/desktop/src/main/services/dialog.ts b/desktop/src/main/services/dialog.tsdeleted file mode 100644index e98a6a9dd6..0000000000--- a/desktop/src/main/services/dialog.ts+++ /dev/null@@ -1,10 +0,0 @@-import { dialog } from "electron/main";-import { posixPath } from "../utils-path";--export const selectDirectory = async () => {- const result = await dialog.showOpenDialog({- properties: ["openDirectory"],- });- const dirPath = result.filePaths[0];- return dirPath ? posixPath(dirPath) : undefined;-};diff --git a/desktop/src/main/services/dir.ts b/desktop/src/main/services/dir.tsnew file mode 100644index 0000000000..a6917fe27c--- /dev/null+++ b/desktop/src/main/services/dir.ts@@ -0,0 +1,48 @@+import { shell } from "electron/common";+import { app, dialog } from "electron/main";+import path from "node:path";+import { posixPath } from "../utils/path";++export const selectDirectory = async () => {+ const result = await dialog.showOpenDialog({+ properties: ["openDirectory"],+ });+ const dirPath = result.filePaths[0];+ return dirPath ? posixPath(dirPath) : undefined;+};++/**+ * Open the given {@link dirPath} in the system's folder viewer.+ *+ * For example, on macOS this'll open {@link dirPath} in Finder.+ */+export const openDirectory = async (dirPath: string) => {+ const res = await shell.openPath(path.normalize(dirPath));+ // shell.openPath resolves with a string containing the error message+ // corresponding to the failure if a failure occurred, otherwise "".+ if (res) throw new Error(`Failed to open directory ${dirPath}: res`);+};++/**+ * Open the app's log directory in the system's folder viewer.+ *+ * @see {@link openDirectory}+ */+export const openLogDirectory = () => openDirectory(logDirectoryPath());++/**+ * Return the path where the logs for the app are saved.+ *+ * [Note: Electron app paths]+ *+ * By default, these paths are at the following locations:+ *+ * - macOS: `~/Library/Application Support/ente`+ * - Linux: `~/.config/ente`+ * - Windows: `%APPDATA%`, e.g. `C:\Users\<username>\AppData\Local\ente`+ * - Windows: C:\Users\<you>\AppData\Local\<Your App Name>+ *+ * https://www.electronjs.org/docs/latest/api/app+ *+ */+const logDirectoryPath = () => app.getPath("logs");diff --git a/desktop/src/main/services/ffmpeg.ts b/desktop/src/main/services/ffmpeg.tsindex 35977409ae..78b7a9e9a3 100644--- a/desktop/src/main/services/ffmpeg.ts+++ b/desktop/src/main/services/ffmpeg.ts@@ -3,12 +3,12 @@ import fs from "node:fs/promises";import type { ZipItem } from "../../types/ipc";import log from "../log";import { withTimeout } from "../utils";-import { execAsync } from "../utils-electron";+import { execAsync } from "../utils/electron";import {deleteTempFile,makeFileForDataOrPathOrZipItem,makeTempFilePath,-} from "../utils-temp";+} from "../utils/temp";/* Duplicated in the web app's code (used by the WASM FFmpeg implementation). */const ffmpegPathPlaceholder = "FFMPEG";diff --git a/desktop/src/main/fs.ts b/desktop/src/main/services/fs.tssimilarity index 100%rename from desktop/src/main/fs.tsrename to desktop/src/main/services/fs.tsdiff --git a/desktop/src/main/services/image.ts b/desktop/src/main/services/image.tsindex 273607c4bc..957fe81200 100644--- a/desktop/src/main/services/image.ts+++ b/desktop/src/main/services/image.ts@@ -4,12 +4,12 @@ import fs from "node:fs/promises";import path from "node:path";import { CustomErrorMessage, type ZipItem } from "../../types/ipc";import log from "../log";-import { execAsync, isDev } from "../utils-electron";+import { execAsync, isDev } from "../utils/electron";import {deleteTempFile,makeFileForDataOrPathOrZipItem,makeTempFilePath,-} from "../utils-temp";+} from "../utils/temp";export const convertToJPEG = async (imageData: Uint8Array) => {const inputFilePath = await makeTempFilePath();diff --git a/desktop/src/main/services/ml-clip.ts b/desktop/src/main/services/ml-clip.tsindex cdd2baab76..99e512aa61 100644--- a/desktop/src/main/services/ml-clip.ts+++ b/desktop/src/main/services/ml-clip.ts@@ -11,7 +11,7 @@ import * as ort from "onnxruntime-node";import Tokenizer from "../../thirdparty/clip-bpe-ts/mod";import log from "../log";import { writeStream } from "../stream";-import { deleteTempFile, makeTempFilePath } from "../utils-temp";+import { deleteTempFile, makeTempFilePath } from "../utils/temp";import { makeCachedInferenceSession } from "./ml";const cachedCLIPImageSession = makeCachedInferenceSession(diff --git a/desktop/src/main/services/watch.ts b/desktop/src/main/services/watch.tsindex 85463ae49e..5e57df3e5e 100644--- a/desktop/src/main/services/watch.ts+++ b/desktop/src/main/services/watch.ts@@ -3,10 +3,10 @@ import { BrowserWindow } from "electron/main";import fs from "node:fs/promises";import path from "node:path";import { FolderWatch, type CollectionMapping } from "../../types/ipc";-import { fsIsDir } from "../fs";import log from "../log";import { watchStore } from "../stores/watch";-import { posixPath } from "../utils-path";+import { posixPath } from "../utils/path";+import { fsIsDir } from "./fs";/*** Create and return a new file system watcher.diff --git a/desktop/src/main/utils-electron.ts b/desktop/src/main/utils/electron.tssimilarity index 53%rename from desktop/src/main/utils-electron.tsrename to desktop/src/main/utils/electron.tsindex e8a98f1dfe..97d05ea6d0 100644--- a/desktop/src/main/utils-electron.ts+++ b/desktop/src/main/utils/electron.ts@@ -1,10 +1,8 @@import shellescape from "any-shell-escape";-import { shell } from "electron"; /* TODO(MR): Why is this not in /main? */import { app } from "electron/main";import { exec } from "node:child_process";-import path from "node:path";import { promisify } from "node:util";-import log from "./log";+import log from "../log";/** `true` if the app is running in development mode. */export const isDev = !app.isPackaged;@@ -41,39 +39,3 @@ export const execAsync = (command: string | string[]) => {};const execAsync_ = promisify(exec);--/**- * Open the given {@link dirPath} in the system's folder viewer.- *- * For example, on macOS this'll open {@link dirPath} in Finder.- */-export const openDirectory = async (dirPath: string) => {- const res = await shell.openPath(path.normalize(dirPath));- // shell.openPath resolves with a string containing the error message- // corresponding to the failure if a failure occurred, otherwise "".- if (res) throw new Error(`Failed to open directory ${dirPath}: res`);-};--/**- * Open the app's log directory in the system's folder viewer.- *- * @see {@link openDirectory}- */-export const openLogDirectory = () => openDirectory(logDirectoryPath());--/**- * Return the path where the logs for the app are saved.- *- * [Note: Electron app paths]- *- * By default, these paths are at the following locations:- *- * - macOS: `~/Library/Application Support/ente`- * - Linux: `~/.config/ente`- * - Windows: `%APPDATA%`, e.g. `C:\Users\<username>\AppData\Local\ente`- * - Windows: C:\Users\<you>\AppData\Local\<Your App Name>- *- * https://www.electronjs.org/docs/latest/api/app- *- */-const logDirectoryPath = () => app.getPath("logs");diff --git a/desktop/src/main/utils.ts b/desktop/src/main/utils/index.tssimilarity index 100%rename from desktop/src/main/utils.tsrename to desktop/src/main/utils/index.tsdiff --git a/desktop/src/main/utils-path.ts b/desktop/src/main/utils/path.tssimilarity index 100%rename from desktop/src/main/utils-path.tsrename to desktop/src/main/utils/path.tsdiff --git a/desktop/src/main/utils-temp.ts b/desktop/src/main/utils/temp.tssimilarity index 98%rename from desktop/src/main/utils-temp.tsrename to desktop/src/main/utils/temp.tsindex 5928931f2e..28aea245d8 100644--- a/desktop/src/main/utils-temp.ts+++ b/desktop/src/main/utils/temp.ts@@ -3,7 +3,7 @@ import StreamZip from "node-stream-zip";import { existsSync } from "node:fs";import fs from "node:fs/promises";import path from "node:path";-import type { ZipItem } from "../types/ipc";+import type { ZipItem } from "../../types/ipc";/*** Our very own directory within the system temp directory. Go crazy, but