Browse Source

Rearrange

Manav Rathi 1 year ago
parent
commit
d6aeef85d6

+ 1 - 1
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.

+ 14 - 11
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 to

+ 1 - 1
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.

+ 1 - 1
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) => {

+ 0 - 10
desktop/src/main/services/dialog.ts

@@ -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;
-};

+ 48 - 0
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");

+ 2 - 2
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";

+ 0 - 0
desktop/src/main/fs.ts → desktop/src/main/services/fs.ts


+ 2 - 2
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();

+ 1 - 1
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(

+ 2 - 2
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.

+ 1 - 39
desktop/src/main/utils-electron.ts → 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");

+ 0 - 0
desktop/src/main/utils.ts → desktop/src/main/utils/index.ts


+ 0 - 0
desktop/src/main/utils-path.ts → desktop/src/main/utils/path.ts


+ 1 - 1
desktop/src/main/utils-temp.ts → 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