From a96ad6dfa28d518edcb35d723eb510928df138c6 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 8 Apr 2024 12:40:03 +0530 Subject: [PATCH 1/3] WIP --- .../src/components/Sidebar/DebugSection.tsx | 2 +- web/apps/photos/src/utils/file/index.ts | 1 + web/apps/photos/src/worker/convert.worker.ts | 3 ++ web/packages/shared/logging/index.ts | 28 +++++++++++++++---- web/packages/shared/logging/web.ts | 13 +++++++-- web/packages/shared/sentry/index.ts | 1 + .../shared/storage/localStorage/index.ts | 3 +- web/packages/shared/worker/comlinkWorker.ts | 21 +++++++++++--- web/packages/shared/worker/worker-bridge.ts | 12 ++++++++ 9 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 web/packages/shared/worker/worker-bridge.ts diff --git a/web/apps/photos/src/components/Sidebar/DebugSection.tsx b/web/apps/photos/src/components/Sidebar/DebugSection.tsx index b2d07bb47..b65548377 100644 --- a/web/apps/photos/src/components/Sidebar/DebugSection.tsx +++ b/web/apps/photos/src/components/Sidebar/DebugSection.tsx @@ -47,7 +47,7 @@ export default function DebugSection() { const downloadDebugLogs = () => { addLogLine("exporting logs"); - if (isElectron()) { + if (false && isElectron()) { ElectronAPIs.openLogDirectory(); } else { const logs = getDebugLogs(); diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index 8ae0a9562..96f4749bf 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -452,6 +452,7 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { imageBlob.size, )}`, ); + throw new Error("bypass"); convertedImageBlob = await imageProcessor.convertToJPEG( imageBlob, fileName, diff --git a/web/apps/photos/src/worker/convert.worker.ts b/web/apps/photos/src/worker/convert.worker.ts index d8ab22d3a..d3f0441df 100644 --- a/web/apps/photos/src/worker/convert.worker.ts +++ b/web/apps/photos/src/worker/convert.worker.ts @@ -1,3 +1,4 @@ +import { logError } from "@ente/shared/sentry"; import * as Comlink from "comlink"; import HeicConvert from "heic-convert"; import { getUint8ArrayView } from "services/readerService"; @@ -16,6 +17,8 @@ Comlink.expose(DedicatedConvertWorker, self); * Both the input and output are blobs. */ export const convertHEICToJPEG = async (heicBlob: Blob): Promise => { + // throw new Error("test error"); + logError(new Error("test error"), "test message"); const filedata = await getUint8ArrayView(heicBlob); const result = await HeicConvert({ buffer: filedata, format: "JPEG" }); const convertedFileData = new Uint8Array(result); diff --git a/web/packages/shared/logging/index.ts b/web/packages/shared/logging/index.ts index 12ff5bf6e..db9938300 100644 --- a/web/packages/shared/logging/index.ts +++ b/web/packages/shared/logging/index.ts @@ -1,12 +1,21 @@ -import { isDevBuild } from "@/next/env"; +import { inWorker, isDevBuild } from "@/next/env"; import { logError } from "@ente/shared/sentry"; import isElectron from "is-electron"; -import { WorkerSafeElectronService } from "../electron/service"; +import ElectronAPIs from "../electron"; +import { workerBridge } from "../worker/worker-bridge"; import { formatLog, logWeb } from "./web"; export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB export const MAX_LOG_LINES = 1000; +export const logToDisk = (message: string) => { + if (isElectron()) { + ElectronAPIs.logToDisk(message); + } else { + logWeb(message); + } +}; + export function addLogLine( log: string | number | boolean, ...optionalParams: (string | number | boolean)[] @@ -16,10 +25,19 @@ export function addLogLine( if (isDevBuild) { console.log(completeLog); } - if (isElectron()) { - WorkerSafeElectronService.logToDisk(completeLog); + if (inWorker()) { + workerBridge + .logToDisk(completeLog) + .catch((e) => + console.error( + "Failed to log a message from worker", + e, + "\nThe message was", + completeLog, + ), + ); } else { - logWeb(completeLog); + logToDisk(completeLog); } } catch (e) { logError(e, "failed to addLogLine", undefined, true); diff --git a/web/packages/shared/logging/web.ts b/web/packages/shared/logging/web.ts index 7b15851b8..9584cd385 100644 --- a/web/packages/shared/logging/web.ts +++ b/web/packages/shared/logging/web.ts @@ -1,4 +1,4 @@ -import { isDevBuild } from "@/next/env"; +import { inWorker, isDevBuild } from "@/next/env"; import { logError } from "@ente/shared/sentry"; import { getData, @@ -20,13 +20,22 @@ export interface Log { logLine: string; } -export function logWeb(logLine: string) { +export function logWeb(logLine2: string) { + const logLine = `${logLine2}`; + console.log("logWeb", logLine); try { const log: Log = { logLine, timestamp: Date.now() }; const logs = getLogs(); if (logs.length > MAX_LOG_LINES) { logs.slice(logs.length - MAX_LOG_LINES); } + console.log("inWorker", inWorker()); + console.log("pushing", logLine); + console.log("length", logLine.length); + logs.push({ + logLine: `length ${logLine.length}`, + timestamp: Date.now(), + }); logs.push(log); setLogs(logs); } catch (e) { diff --git a/web/packages/shared/sentry/index.ts b/web/packages/shared/sentry/index.ts index 2dae035b7..f8b14e43d 100644 --- a/web/packages/shared/sentry/index.ts +++ b/web/packages/shared/sentry/index.ts @@ -18,6 +18,7 @@ export const logError = async ( } ${error?.stack}`); } else { + console.log("here"); addLogLine( `error: ${error?.name} ${error?.message} msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ""} diff --git a/web/packages/shared/storage/localStorage/index.ts b/web/packages/shared/storage/localStorage/index.ts index 14901fdd4..6a115e8d5 100644 --- a/web/packages/shared/storage/localStorage/index.ts +++ b/web/packages/shared/storage/localStorage/index.ts @@ -32,7 +32,8 @@ export enum LS_KEYS { export const setData = (key: LS_KEYS, value: object) => { if (typeof localStorage === "undefined") { - return null; + console.log("early return"); + // return null; } localStorage.setItem(key, JSON.stringify(value)); }; diff --git a/web/packages/shared/worker/comlinkWorker.ts b/web/packages/shared/worker/comlinkWorker.ts index 49a1abf94..bcf3b4f3d 100644 --- a/web/packages/shared/worker/comlinkWorker.ts +++ b/web/packages/shared/worker/comlinkWorker.ts @@ -1,6 +1,5 @@ -import { WorkerSafeElectronClient } from "@ente/shared/electron/worker/client"; -import { addLocalLog } from "@ente/shared/logging"; -import { expose, Remote, wrap } from "comlink"; +import { addLocalLog, logToDisk } from "@ente/shared/logging"; +import { Remote, expose, wrap } from "comlink"; import { logError } from "../sentry"; export class ComlinkWorker InstanceType> { @@ -21,7 +20,8 @@ export class ComlinkWorker InstanceType> { addLocalLog(() => `Initiated ${this.name}`); const comlink = wrap(this.worker); this.remote = new comlink() as Promise>>; - expose(WorkerSafeElectronClient, this.worker); + // expose(WorkerSafeElectronClient, this.worker); + expose(workerBridge, this.worker); } public getName() { @@ -33,3 +33,16 @@ export class ComlinkWorker InstanceType> { addLocalLog(() => `Terminated ${this.name}`); } } + +/** + * A minimal set of utility functions that we expose to all workers that we + * create. + * + * Inside the worker's code, this can be accessed by + * `wrap(self).foo`. + */ +const workerBridge = { + logToDisk, +}; + +export type WorkerBridge = typeof workerBridge; diff --git a/web/packages/shared/worker/worker-bridge.ts b/web/packages/shared/worker/worker-bridge.ts new file mode 100644 index 000000000..7001dfe4c --- /dev/null +++ b/web/packages/shared/worker/worker-bridge.ts @@ -0,0 +1,12 @@ +import { wrap } from "comlink"; +import type { WorkerBridge } from "./comlinkWorker"; + +/** + * The web worker side handle to the {@link WorkerBridge} exposed by the main + * thread. + * + * This file is meant to be run inside a worker. Accessing the properties of + * this object will be transparently (but asynchrorously) relayed to the + * implementation of the {@link WorkerBridge} in `comlinkWorker.ts`. + */ +export const workerBridge = wrap(self); From da9a7040945a2b45dfd034361f04c28d6172bfc4 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 8 Apr 2024 12:50:11 +0530 Subject: [PATCH 2/3] fixing logging in workers WIP 2 --- .../photos/src/services/imageProcessor.ts | 72 ------------------- .../src/services/upload/thumbnailService.ts | 37 +++++++++- web/apps/photos/src/utils/file/index.ts | 35 ++++++++- web/packages/shared/electron/service.ts | 44 ------------ web/packages/shared/electron/worker/client.ts | 21 ------ web/packages/shared/logging/web.ts | 15 +--- web/packages/shared/worker/comlinkWorker.ts | 4 +- web/packages/shared/worker/worker-bridge.ts | 2 +- 8 files changed, 74 insertions(+), 156 deletions(-) delete mode 100644 web/apps/photos/src/services/imageProcessor.ts delete mode 100644 web/packages/shared/electron/service.ts delete mode 100644 web/packages/shared/electron/worker/client.ts diff --git a/web/apps/photos/src/services/imageProcessor.ts b/web/apps/photos/src/services/imageProcessor.ts deleted file mode 100644 index ac67c54ec..000000000 --- a/web/apps/photos/src/services/imageProcessor.ts +++ /dev/null @@ -1,72 +0,0 @@ -import ElectronAPIs from "@ente/shared/electron"; -import { WorkerSafeElectronService } from "@ente/shared/electron/service"; -import { CustomError } from "@ente/shared/error"; -import { addLogLine } from "@ente/shared/logging"; -import { logError } from "@ente/shared/sentry"; -import { convertBytesToHumanReadable } from "@ente/shared/utils/size"; -import { ElectronFile } from "types/upload"; - -class ElectronImageProcessorService { - async convertToJPEG(fileBlob: Blob, filename: string): Promise { - try { - const startTime = Date.now(); - const inputFileData = new Uint8Array(await fileBlob.arrayBuffer()); - const convertedFileData = - await WorkerSafeElectronService.convertToJPEG( - inputFileData, - filename, - ); - addLogLine( - `originalFileSize:${convertBytesToHumanReadable( - fileBlob?.size, - )},convertedFileSize:${convertBytesToHumanReadable( - convertedFileData?.length, - )}, native conversion time: ${Date.now() - startTime}ms `, - ); - return new Blob([convertedFileData]); - } catch (e) { - if ( - e.message !== - CustomError.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED - ) { - logError(e, "failed to convert to jpeg natively"); - } - throw e; - } - } - - async generateImageThumbnail( - inputFile: File | ElectronFile, - maxDimension: number, - maxSize: number, - ): Promise { - try { - const startTime = Date.now(); - const thumb = await ElectronAPIs.generateImageThumbnail( - inputFile, - maxDimension, - maxSize, - ); - addLogLine( - `originalFileSize:${convertBytesToHumanReadable( - inputFile?.size, - )},thumbFileSize:${convertBytesToHumanReadable( - thumb?.length, - )}, native thumbnail generation time: ${ - Date.now() - startTime - }ms `, - ); - return thumb; - } catch (e) { - if ( - e.message !== - CustomError.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED - ) { - logError(e, "failed to generate image thumbnail natively"); - } - throw e; - } - } -} - -export default new ElectronImageProcessorService(); diff --git a/web/apps/photos/src/services/upload/thumbnailService.ts b/web/apps/photos/src/services/upload/thumbnailService.ts index 64df2f016..61e42f9e9 100644 --- a/web/apps/photos/src/services/upload/thumbnailService.ts +++ b/web/apps/photos/src/services/upload/thumbnailService.ts @@ -1,3 +1,4 @@ +import ElectronAPIs from "@ente/shared/electron"; import { CustomError } from "@ente/shared/error"; import { addLogLine } from "@ente/shared/logging"; import { getFileNameSize } from "@ente/shared/logging/web"; @@ -8,7 +9,6 @@ import { BLACK_THUMBNAIL_BASE64 } from "constants/upload"; import isElectron from "is-electron"; import * as FFmpegService from "services/ffmpeg/ffmpegService"; import HeicConversionService from "services/heicConversionService"; -import imageProcessor from "services/imageProcessor"; import { ElectronFile, FileTypeInfo } from "types/upload"; import { isFileHEIC } from "utils/file"; import { getUint8ArrayView } from "../readerService"; @@ -86,7 +86,7 @@ async function generateImageThumbnail( ) { if (isElectron()) { try { - return await imageProcessor.generateImageThumbnail( + return await generateImageThumbnailInElectron( file, MAX_THUMBNAIL_DIMENSION, MAX_THUMBNAIL_SIZE, @@ -99,6 +99,39 @@ async function generateImageThumbnail( } } +const generateImageThumbnailInElectron = async ( + inputFile: File | ElectronFile, + maxDimension: number, + maxSize: number, +): Promise => { + try { + const startTime = Date.now(); + const thumb = await ElectronAPIs.generateImageThumbnail( + inputFile, + maxDimension, + maxSize, + ); + addLogLine( + `originalFileSize:${convertBytesToHumanReadable( + inputFile?.size, + )},thumbFileSize:${convertBytesToHumanReadable( + thumb?.length, + )}, native thumbnail generation time: ${ + Date.now() - startTime + }ms `, + ); + return thumb; + } catch (e) { + if ( + e.message !== + CustomError.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED + ) { + logError(e, "failed to generate image thumbnail natively"); + } + throw e; + } +}; + export async function generateImageThumbnailUsingCanvas( file: File | ElectronFile, fileTypeInfo: FileTypeInfo, diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index 96f4749bf..2e02794c4 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -53,8 +53,8 @@ import { import { FileTypeInfo } from "types/upload"; import { default as ElectronAPIs } from "@ente/shared/electron"; +import { workerBridge } from "@ente/shared/worker/worker-bridge"; import { t } from "i18next"; -import imageProcessor from "services/imageProcessor"; import { getFileExportPath, getUniqueFileExportName } from "utils/export"; const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000; @@ -452,8 +452,7 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { imageBlob.size, )}`, ); - throw new Error("bypass"); - convertedImageBlob = await imageProcessor.convertToJPEG( + convertedImageBlob = await convertToJPEGInElectron( imageBlob, fileName, ); @@ -485,6 +484,36 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { } } +const convertToJPEGInElectron = async ( + fileBlob: Blob, + filename: string, +): Promise => { + try { + const startTime = Date.now(); + const inputFileData = new Uint8Array(await fileBlob.arrayBuffer()); + const convertedFileData = await workerBridge.convertToJPEG( + inputFileData, + filename, + ); + addLogLine( + `originalFileSize:${convertBytesToHumanReadable( + fileBlob?.size, + )},convertedFileSize:${convertBytesToHumanReadable( + convertedFileData?.length, + )}, native conversion time: ${Date.now() - startTime}ms `, + ); + return new Blob([convertedFileData]); + } catch (e) { + if ( + e.message !== + CustomError.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED + ) { + logError(e, "failed to convert to jpeg natively"); + } + throw e; + } +}; + export function isFileHEIC(exactType: string) { return ( exactType.toLowerCase().endsWith(TYPE_HEIC) || diff --git a/web/packages/shared/electron/service.ts b/web/packages/shared/electron/service.ts deleted file mode 100644 index f926d20b2..000000000 --- a/web/packages/shared/electron/service.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { inWorker } from "@/next/env"; -import * as Comlink from "comlink"; -import { wrap } from "comlink"; -import { ElectronAPIsType } from "./types"; -import { WorkerSafeElectronClient } from "./worker/client"; - -export interface LimitedElectronAPIs - extends Pick {} - -class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs { - proxiedElectron: - | Comlink.Remote - | WorkerSafeElectronClient; - ready: Promise; - - constructor() { - this.ready = this.init(); - } - private async init() { - if (inWorker()) { - const workerSafeElectronClient = - wrap(self); - - this.proxiedElectron = await new workerSafeElectronClient(); - } else { - this.proxiedElectron = new WorkerSafeElectronClient(); - } - } - - async convertToJPEG( - inputFileData: Uint8Array, - filename: string, - ): Promise { - await this.ready; - return this.proxiedElectron.convertToJPEG(inputFileData, filename); - } - - async logToDisk(message: string) { - await this.ready; - return this.proxiedElectron.logToDisk(message); - } -} - -export const WorkerSafeElectronService = new WorkerSafeElectronServiceImpl(); diff --git a/web/packages/shared/electron/worker/client.ts b/web/packages/shared/electron/worker/client.ts deleted file mode 100644 index f6b99ee88..000000000 --- a/web/packages/shared/electron/worker/client.ts +++ /dev/null @@ -1,21 +0,0 @@ -import ElectronAPIs from "@ente/shared/electron"; - -export interface ProxiedLimitedElectronAPIs { - convertToJPEG: ( - inputFileData: Uint8Array, - filename: string, - ) => Promise; - logToDisk: (message: string) => void; -} - -export class WorkerSafeElectronClient implements ProxiedLimitedElectronAPIs { - async convertToJPEG( - inputFileData: Uint8Array, - filename: string, - ): Promise { - return await ElectronAPIs.convertToJPEG(inputFileData, filename); - } - logToDisk(message: string) { - return ElectronAPIs.logToDisk(message); - } -} diff --git a/web/packages/shared/logging/web.ts b/web/packages/shared/logging/web.ts index 9584cd385..45127121b 100644 --- a/web/packages/shared/logging/web.ts +++ b/web/packages/shared/logging/web.ts @@ -1,8 +1,8 @@ -import { inWorker, isDevBuild } from "@/next/env"; +import { isDevBuild } from "@/next/env"; import { logError } from "@ente/shared/sentry"; import { - getData, LS_KEYS, + getData, removeData, setData, } from "@ente/shared/storage/localStorage"; @@ -20,22 +20,13 @@ export interface Log { logLine: string; } -export function logWeb(logLine2: string) { - const logLine = `${logLine2}`; - console.log("logWeb", logLine); +export function logWeb(logLine: string) { try { const log: Log = { logLine, timestamp: Date.now() }; const logs = getLogs(); if (logs.length > MAX_LOG_LINES) { logs.slice(logs.length - MAX_LOG_LINES); } - console.log("inWorker", inWorker()); - console.log("pushing", logLine); - console.log("length", logLine.length); - logs.push({ - logLine: `length ${logLine.length}`, - timestamp: Date.now(), - }); logs.push(log); setLogs(logs); } catch (e) { diff --git a/web/packages/shared/worker/comlinkWorker.ts b/web/packages/shared/worker/comlinkWorker.ts index bcf3b4f3d..0cbae504c 100644 --- a/web/packages/shared/worker/comlinkWorker.ts +++ b/web/packages/shared/worker/comlinkWorker.ts @@ -1,5 +1,6 @@ import { addLocalLog, logToDisk } from "@ente/shared/logging"; import { Remote, expose, wrap } from "comlink"; +import ElectronAPIs from "../electron"; import { logError } from "../sentry"; export class ComlinkWorker InstanceType> { @@ -20,7 +21,6 @@ export class ComlinkWorker InstanceType> { addLocalLog(() => `Initiated ${this.name}`); const comlink = wrap(this.worker); this.remote = new comlink() as Promise>>; - // expose(WorkerSafeElectronClient, this.worker); expose(workerBridge, this.worker); } @@ -43,6 +43,8 @@ export class ComlinkWorker InstanceType> { */ const workerBridge = { logToDisk, + convertToJPEG: (inputFileData: Uint8Array, filename: string) => + ElectronAPIs.convertToJPEG(inputFileData, filename), }; export type WorkerBridge = typeof workerBridge; diff --git a/web/packages/shared/worker/worker-bridge.ts b/web/packages/shared/worker/worker-bridge.ts index 7001dfe4c..e783e4b67 100644 --- a/web/packages/shared/worker/worker-bridge.ts +++ b/web/packages/shared/worker/worker-bridge.ts @@ -9,4 +9,4 @@ import type { WorkerBridge } from "./comlinkWorker"; * this object will be transparently (but asynchrorously) relayed to the * implementation of the {@link WorkerBridge} in `comlinkWorker.ts`. */ -export const workerBridge = wrap(self); +export const workerBridge = wrap(globalThis); From 84d21984e07e14af049cf9a24061cd0efaf8e866 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 8 Apr 2024 13:02:12 +0530 Subject: [PATCH 3/3] Test complete Tested logging from both worker (in web app) and when running in Electron. Refs: - https://github.com/GoogleChromeLabs/comlink/issues/506 - https://github.com/GoogleChromeLabs/comlink/issues/568 --- web/apps/photos/src/components/Sidebar/DebugSection.tsx | 2 +- web/apps/photos/src/worker/convert.worker.ts | 3 --- web/packages/shared/sentry/index.ts | 1 - web/packages/shared/storage/localStorage/index.ts | 3 +-- web/packages/shared/worker/comlinkWorker.ts | 6 +++--- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/web/apps/photos/src/components/Sidebar/DebugSection.tsx b/web/apps/photos/src/components/Sidebar/DebugSection.tsx index b65548377..b2d07bb47 100644 --- a/web/apps/photos/src/components/Sidebar/DebugSection.tsx +++ b/web/apps/photos/src/components/Sidebar/DebugSection.tsx @@ -47,7 +47,7 @@ export default function DebugSection() { const downloadDebugLogs = () => { addLogLine("exporting logs"); - if (false && isElectron()) { + if (isElectron()) { ElectronAPIs.openLogDirectory(); } else { const logs = getDebugLogs(); diff --git a/web/apps/photos/src/worker/convert.worker.ts b/web/apps/photos/src/worker/convert.worker.ts index d3f0441df..d8ab22d3a 100644 --- a/web/apps/photos/src/worker/convert.worker.ts +++ b/web/apps/photos/src/worker/convert.worker.ts @@ -1,4 +1,3 @@ -import { logError } from "@ente/shared/sentry"; import * as Comlink from "comlink"; import HeicConvert from "heic-convert"; import { getUint8ArrayView } from "services/readerService"; @@ -17,8 +16,6 @@ Comlink.expose(DedicatedConvertWorker, self); * Both the input and output are blobs. */ export const convertHEICToJPEG = async (heicBlob: Blob): Promise => { - // throw new Error("test error"); - logError(new Error("test error"), "test message"); const filedata = await getUint8ArrayView(heicBlob); const result = await HeicConvert({ buffer: filedata, format: "JPEG" }); const convertedFileData = new Uint8Array(result); diff --git a/web/packages/shared/sentry/index.ts b/web/packages/shared/sentry/index.ts index f8b14e43d..2dae035b7 100644 --- a/web/packages/shared/sentry/index.ts +++ b/web/packages/shared/sentry/index.ts @@ -18,7 +18,6 @@ export const logError = async ( } ${error?.stack}`); } else { - console.log("here"); addLogLine( `error: ${error?.name} ${error?.message} msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ""} diff --git a/web/packages/shared/storage/localStorage/index.ts b/web/packages/shared/storage/localStorage/index.ts index 6a115e8d5..14901fdd4 100644 --- a/web/packages/shared/storage/localStorage/index.ts +++ b/web/packages/shared/storage/localStorage/index.ts @@ -32,8 +32,7 @@ export enum LS_KEYS { export const setData = (key: LS_KEYS, value: object) => { if (typeof localStorage === "undefined") { - console.log("early return"); - // return null; + return null; } localStorage.setItem(key, JSON.stringify(value)); }; diff --git a/web/packages/shared/worker/comlinkWorker.ts b/web/packages/shared/worker/comlinkWorker.ts index 0cbae504c..f8e72778f 100644 --- a/web/packages/shared/worker/comlinkWorker.ts +++ b/web/packages/shared/worker/comlinkWorker.ts @@ -21,7 +21,7 @@ export class ComlinkWorker InstanceType> { addLocalLog(() => `Initiated ${this.name}`); const comlink = wrap(this.worker); this.remote = new comlink() as Promise>>; - expose(workerBridge, this.worker); + expose(workerBridge, worker); } public getName() { @@ -38,8 +38,8 @@ export class ComlinkWorker InstanceType> { * A minimal set of utility functions that we expose to all workers that we * create. * - * Inside the worker's code, this can be accessed by - * `wrap(self).foo`. + * Inside the worker's code, this can be accessed by using the sibling + * `workerBridge` object by importing `worker-bridge.ts`. */ const workerBridge = { logToDisk,