Skip to content

armgit / ente

Public Imported from GitHub
0

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

Scaffold

Manav Rathi67a941752835
diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts
index 37ee0478e5..f891fb390b 100644
--- a/desktop/src/main/ipc.ts
+++ b/desktop/src/main/ipc.ts
@@ -42,6 +42,7 @@ import {
} from "./services/fs";
import { convertToJPEG, generateImageThumbnail } from "./services/image";
import { logout } from "./services/logout";
+import { createMLSession } from "./services/ml";
import {
computeCLIPImageEmbedding,
computeCLIPTextEmbeddingIfAvailable,
@@ -187,6 +188,8 @@ export const attachIPCHandlers = () => {
// - ML
+ ipcMain.on("createMLSession", () => createMLSession());
+
ipcMain.handle("computeCLIPImageEmbedding", (_, input: Float32Array) =>
computeCLIPImageEmbedding(input),
);
diff --git a/desktop/src/main/services/ml.ts b/desktop/src/main/services/ml.ts
index d7ea06caec..4f69fd90b1 100644
--- a/desktop/src/main/services/ml.ts
+++ b/desktop/src/main/services/ml.ts
@@ -65,5 +65,5 @@ export const createMLSession = () => {
const child = utilityProcess.fork("./ml-util-test");
child.postMessage(/* unused */ "", [port1]);
- ipcRenderer.postMessage("ml-session-port", /* unused */ "", [port2]);
+ ipcRenderer.postMessage("createMLSession/port", /* unused */ "", [port2]);
};
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index f2366aa63d..16b271ce9f 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -163,6 +163,21 @@ const ffmpegExec = (
// - ML
+const createMLSession = () => {
+ ipcRenderer.send("createMLSession");
+
+ // The main process will do its thing, and send back the port it created to
+ // us by sending an message on the "createMLSession/port" channel via the
+ // postMessage API. This roundabout way is needed because MessagePorts
+ // cannot be transferred via the usual send/invoke pattern.
+
+ return new Promise((resolve) => {
+ ipcRenderer.on("createMLSession/port", (event) => {
+ resolve(event.ports[0]);
+ });
+ });
+};
+
const computeCLIPImageEmbedding = (input: Float32Array) =>
ipcRenderer.invoke("computeCLIPImageEmbedding", input);
@@ -339,6 +354,7 @@ contextBridge.exposeInMainWorld("electron", {
// - ML
+ createMLSession,
computeCLIPImageEmbedding,
computeCLIPTextEmbeddingIfAvailable,
detectFaces,
diff --git a/web/packages/base/types/ipc.ts b/web/packages/base/types/ipc.ts
index ebf2670da2..7188019408 100644
--- a/web/packages/base/types/ipc.ts
+++ b/web/packages/base/types/ipc.ts
@@ -342,6 +342,9 @@ export interface Electron {
* {@link MessagePort} we get back.
*
* 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 createMLSession}.
*/
createMLSession: () => Promise<MessagePort>;
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index c3432b1023..493ac6612f 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -114,6 +114,11 @@ export const canEnableML = async () =>
*/
export const initML = () => {
_isMLEnabled = isMLEnabledLocal();
+ void (async () => {
+ console.log("yyy", 1);
+ const port = await ensureElectron().createMLSession();
+ console.log("yyy", port);
+ })();
};
export const logoutML = async () => {