Skip to content

armgit / ente

Public Imported from GitHub
0

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

Rename

Manav Rathi10d7162d6e76
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index b99fae7173..24043fe10d 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -47,7 +47,7 @@ import {
} from "./services/fs";
import { convertToJPEG, generateImageThumbnail } from "./services/image";
import { logout } from "./services/logout";
-import { createMLWorker } from "./services/ml";
+import { createMLUtilityProcess } from "./services/ml";
import {
lastShownChangelogVersion,
masterKeyB64,
@@ -235,7 +235,9 @@ export const attachIPCHandlers = () => {
export const attachMainWindowIPCHandlers = (mainWindow: BrowserWindow) => {
// - ML
- ipcMain.on("createMLWorker", () => createMLWorker(mainWindow));
+ ipcMain.on("createMLUtilityProcess", () =>
+ createMLUtilityProcess(mainWindow),
+ );
};
/**
diff --git a/desktop/src/main/services/ml-worker.ts b/desktop/src/main/services/ml-worker.ts
index 8ce5deebc8..fa6ebd1790 100644
--- a/desktop/src/main/services/ml-worker.ts
+++ b/desktop/src/main/services/ml-worker.ts
@@ -21,7 +21,7 @@ import { wait } from "../utils/common";
import { writeStream } from "../utils/stream";
import { fsStatMtime } from "./fs";
-log.debugString("Started ML worker process");
+log.debugString("Started ML utility process");
process.parentPort.once("message", (e) => {
// Initialize ourselves with the data we got from our parent.
diff --git a/desktop/src/main/services/ml.ts b/desktop/src/main/services/ml.ts
index 91a0712c0a..263a6cfe63 100644
--- a/desktop/src/main/services/ml.ts
+++ b/desktop/src/main/services/ml.ts
@@ -11,11 +11,11 @@ import { app, utilityProcess } from "electron/main";
import path from "node:path";
import log, { processUtilityProcessLogMessage } from "../log";
-/** The active ML worker (utility) process, if any. */
+/** The active ML utility process, if any. */
let _child: UtilityProcess | undefined;
/**
- * Create a new ML worker process, terminating the older ones (if any).
+ * Create a new ML utility process, terminating the older ones (if any).
*
* [Note: ML IPC]
*
@@ -70,9 +70,9 @@ let _child: UtilityProcess | undefined;
* The RPC protocol is handled using comlink on both ends. The port itself needs
* to be relayed using `postMessage`.
*/
-export const createMLWorker = (window: BrowserWindow) => {
+export const createMLUtilityProcess = (window: BrowserWindow) => {
if (_child) {
- log.debug(() => "Terminating previous ML worker process");
+ log.debug(() => "Terminating previous ML utility process");
_child.kill();
_child = undefined;
}
@@ -83,7 +83,9 @@ export const createMLWorker = (window: BrowserWindow) => {
const userDataPath = app.getPath("userData");
child.postMessage({ userDataPath }, [port1]);
- window.webContents.postMessage("createMLWorker/port", undefined, [port2]);
+ window.webContents.postMessage("createMLUtilityProcess/port", undefined, [
+ port2,
+ ]);
handleMessagesFromUtilityProcess(child);
@@ -118,6 +120,6 @@ const handleMessagesFromUtilityProcess = (child: UtilityProcess) => {
if (processUtilityProcessLogMessage("[ml-worker]", m)) {
return;
}
- log.info("Ignoring unknown message from ML worker", m);
+ log.info("Ignoring unknown message from ML utility process", m);
});
};
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index ef586210dd..60a9c6074b 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -217,16 +217,16 @@ const ffmpegExec = (
// - ML
-const createMLWorker = () => {
+const createMLUtilityProcess = () => {
const l = (event: IpcRendererEvent) => {
void windowLoaded.then(() => {
// "*"" is the origin to send to.
- window.postMessage("createMLWorker/port", "*", event.ports);
- ipcRenderer.off("createMLWorker/port", l);
+ window.postMessage("createMLUtilityProcess/port", "*", event.ports);
+ ipcRenderer.off("createMLUtilityProcess/port", l);
});
};
- ipcRenderer.on("createMLWorker/port", l);
- ipcRenderer.send("createMLWorker");
+ ipcRenderer.on("createMLUtilityProcess/port", l);
+ ipcRenderer.send("createMLUtilityProcess");
};
// - Watch
@@ -393,7 +393,7 @@ contextBridge.exposeInMainWorld("electron", {
// - ML
- createMLWorker,
+ createMLUtilityProcess,
// - Watch
diff --git a/web/packages/base/types/ipc.ts b/web/packages/base/types/ipc.ts
index 22cbf7ffdb..d68a7d8434 100644
--- a/web/packages/base/types/ipc.ts
+++ b/web/packages/base/types/ipc.ts
@@ -373,11 +373,11 @@ export interface Electron {
// - ML
/**
- * Create a new ML worker, terminating the older ones (if any).
+ * Create a new ML utility process, terminating the older ones (if any).
*
* This creates a new Node.js utility process, and sets things up so that we
* can communicate directly with that utility process using a
- * {@link MessagePort} that gets posted using "createMLWorker/port".
+ * {@link MessagePort} that gets posted using "createMLUtilityProcess/port".
*
* At the other end of that port will be an object that conforms to the
* {@link ElectronMLWorker} interface.
@@ -385,9 +385,9 @@ export interface Electron {
* For more details about the IPC flow, see: [Note: ML IPC].
*
* Note: For simplicity of implementation, we assume that there is at most
- * one outstanding call to {@link createMLWorker}.
+ * one outstanding call to {@link createMLUtilityProcess}.
*/
- createMLWorker: () => void;
+ createMLUtilityProcess: () => void;
// - Watch
@@ -592,7 +592,8 @@ export interface Electron {
/**
* The shape of the object exposed by the Node.js ML worker process on the
- * message port that the web layer obtains by doing {@link createMLWorker}.
+ * message port that the web layer obtains by doing
+ * {@link createMLUtilityProcess}.
*/
export interface ElectronMLWorker {
/**
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index d6bf07f330..70a4f57b79 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -135,7 +135,7 @@ const createComlinkWorker = async () => {
const delegate = { workerDidUpdateStatus, workerDidUnawaitedIndex };
// Obtain a message port from the Electron layer.
- const messagePort = await createMLWorker(electron);
+ const messagePort = await createMLUtilityProcess(electron);
const cw = new ComlinkWorker<typeof MLWorker>(
"ML",
@@ -168,19 +168,19 @@ export const terminateMLWorker = async () => {
/**
* Obtain a port from the Node.js layer that can be used to communicate with the
- * ML worker process.
+ * ML utility process.
*/
-const createMLWorker = (electron: Electron): Promise<MessagePort> => {
+const createMLUtilityProcess = (electron: Electron): Promise<MessagePort> => {
// The main process will do its thing, and send back the port it created to
- // us by sending an message on the "createMLWorker/port" channel via the
- // postMessage API. This roundabout way is needed because MessagePorts
+ // us by sending an message on the "createMLUtilityProcess/port" channel via
+ // the postMessage API. This roundabout way is needed because MessagePorts
// cannot be transferred via the usual send/invoke pattern.
const port = new Promise<MessagePort>((resolve) => {
const l = ({ source, data, ports }: MessageEvent) => {
// The source check verifies that the message is coming from our own
// preload script. The data is the message that was posted.
- if (source == window && data == "createMLWorker/port") {
+ if (source == window && data == "createMLUtilityProcess/port") {
window.removeEventListener("message", l);
resolve(ports[0]!);
}
@@ -188,7 +188,7 @@ const createMLWorker = (electron: Electron): Promise<MessagePort> => {
window.addEventListener("message", l);
});
- electron.createMLWorker();
+ electron.createMLUtilityProcess();
return port;
};