Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use

Manav Rathia32c8116a22f
diff --git a/desktop/src/main/services/ml-worker.ts b/desktop/src/main/services/ml-worker.ts
index fa6ebd1790..cb94de0a50 100644
--- a/desktop/src/main/services/ml-worker.ts
+++ b/desktop/src/main/services/ml-worker.ts
@@ -15,6 +15,7 @@ import { existsSync } from "fs";
import fs from "node:fs/promises";
import path from "node:path";
import * as ort from "onnxruntime-node";
+import { z } from "zod";
import log from "../log-worker";
import { messagePortMainEndpoint } from "../utils/comlink";
import { wait } from "../utils/common";
@@ -50,17 +51,10 @@ let _userDataPath: string | undefined;
/** Equivalent to app.getPath("userData") */
const userDataPath = () => _userDataPath!;
+const MLWorkerInitData = z.object({ userDataPath: z.string() });
+
const parseInitData = (data: unknown) => {
- if (
- data &&
- typeof data == "object" &&
- "userDataPath" in data &&
- typeof data.userDataPath == "string"
- ) {
- _userDataPath = data.userDataPath;
- } else {
- log.error("Unparseable initialization data");
- }
+ _userDataPath = MLWorkerInitData.parse(data).userDataPath;
};
/**
diff --git a/desktop/src/main/services/workers.ts b/desktop/src/main/services/workers.ts
index e44b72cd3b..1dd5e5ae67 100644
--- a/desktop/src/main/services/workers.ts
+++ b/desktop/src/main/services/workers.ts
@@ -103,7 +103,7 @@ export const triggerCreateMLUtilityProcess = (window: BrowserWindow) => {
const child = utilityProcess.fork(path.join(__dirname, "ml-worker.js"));
const userDataPath = app.getPath("userData");
- child.postMessage({ userDataPath }, [port1]);
+ child.postMessage(/* MLWorkerInitData */ { userDataPath }, [port1]);
window.webContents.postMessage("utilityProcessPort/ml", undefined, [port2]);