mirror of
https://github.com/ente-io/ente.git
synced 2025-05-30 22:33:15 +00:00
28 lines
872 B
TypeScript
28 lines
872 B
TypeScript
import { ComlinkWorker } from "@/next/worker/comlink-worker";
|
|
import { Remote } from "comlink";
|
|
import { DedicatedCryptoWorker } from "./internal/crypto.worker";
|
|
|
|
class ComlinkCryptoWorker {
|
|
private comlinkWorkerInstance:
|
|
| Promise<Remote<DedicatedCryptoWorker>>
|
|
| undefined;
|
|
|
|
async getInstance() {
|
|
if (!this.comlinkWorkerInstance) {
|
|
const comlinkWorker = getDedicatedCryptoWorker();
|
|
this.comlinkWorkerInstance = comlinkWorker.remote;
|
|
}
|
|
return this.comlinkWorkerInstance;
|
|
}
|
|
}
|
|
|
|
export const getDedicatedCryptoWorker = () => {
|
|
const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedCryptoWorker>(
|
|
"ente-crypto-worker",
|
|
new Worker(new URL("internal/crypto.worker.ts", import.meta.url)),
|
|
);
|
|
return cryptoComlinkWorker;
|
|
};
|
|
|
|
export default new ComlinkCryptoWorker();
|