This commit is contained in:
Manav Rathi 2024-04-08 12:40:03 +05:30
parent 44666d6772
commit a96ad6dfa2
No known key found for this signature in database
9 changed files with 71 additions and 13 deletions

View file

@ -47,7 +47,7 @@ export default function DebugSection() {
const downloadDebugLogs = () => { const downloadDebugLogs = () => {
addLogLine("exporting logs"); addLogLine("exporting logs");
if (isElectron()) { if (false && isElectron()) {
ElectronAPIs.openLogDirectory(); ElectronAPIs.openLogDirectory();
} else { } else {
const logs = getDebugLogs(); const logs = getDebugLogs();

View file

@ -452,6 +452,7 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) {
imageBlob.size, imageBlob.size,
)}`, )}`,
); );
throw new Error("bypass");
convertedImageBlob = await imageProcessor.convertToJPEG( convertedImageBlob = await imageProcessor.convertToJPEG(
imageBlob, imageBlob,
fileName, fileName,

View file

@ -1,3 +1,4 @@
import { logError } from "@ente/shared/sentry";
import * as Comlink from "comlink"; import * as Comlink from "comlink";
import HeicConvert from "heic-convert"; import HeicConvert from "heic-convert";
import { getUint8ArrayView } from "services/readerService"; import { getUint8ArrayView } from "services/readerService";
@ -16,6 +17,8 @@ Comlink.expose(DedicatedConvertWorker, self);
* Both the input and output are blobs. * Both the input and output are blobs.
*/ */
export const convertHEICToJPEG = async (heicBlob: Blob): Promise<Blob> => { export const convertHEICToJPEG = async (heicBlob: Blob): Promise<Blob> => {
// throw new Error("test error");
logError(new Error("test error"), "test message");
const filedata = await getUint8ArrayView(heicBlob); const filedata = await getUint8ArrayView(heicBlob);
const result = await HeicConvert({ buffer: filedata, format: "JPEG" }); const result = await HeicConvert({ buffer: filedata, format: "JPEG" });
const convertedFileData = new Uint8Array(result); const convertedFileData = new Uint8Array(result);

View file

@ -1,12 +1,21 @@
import { isDevBuild } from "@/next/env"; import { inWorker, isDevBuild } from "@/next/env";
import { logError } from "@ente/shared/sentry"; import { logError } from "@ente/shared/sentry";
import isElectron from "is-electron"; 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"; import { formatLog, logWeb } from "./web";
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
export const MAX_LOG_LINES = 1000; export const MAX_LOG_LINES = 1000;
export const logToDisk = (message: string) => {
if (isElectron()) {
ElectronAPIs.logToDisk(message);
} else {
logWeb(message);
}
};
export function addLogLine( export function addLogLine(
log: string | number | boolean, log: string | number | boolean,
...optionalParams: (string | number | boolean)[] ...optionalParams: (string | number | boolean)[]
@ -16,10 +25,19 @@ export function addLogLine(
if (isDevBuild) { if (isDevBuild) {
console.log(completeLog); console.log(completeLog);
} }
if (isElectron()) { if (inWorker()) {
WorkerSafeElectronService.logToDisk(completeLog); workerBridge
.logToDisk(completeLog)
.catch((e) =>
console.error(
"Failed to log a message from worker",
e,
"\nThe message was",
completeLog,
),
);
} else { } else {
logWeb(completeLog); logToDisk(completeLog);
} }
} catch (e) { } catch (e) {
logError(e, "failed to addLogLine", undefined, true); logError(e, "failed to addLogLine", undefined, true);

View file

@ -1,4 +1,4 @@
import { isDevBuild } from "@/next/env"; import { inWorker, isDevBuild } from "@/next/env";
import { logError } from "@ente/shared/sentry"; import { logError } from "@ente/shared/sentry";
import { import {
getData, getData,
@ -20,13 +20,22 @@ export interface Log {
logLine: string; logLine: string;
} }
export function logWeb(logLine: string) { export function logWeb(logLine2: string) {
const logLine = `${logLine2}`;
console.log("logWeb", logLine);
try { try {
const log: Log = { logLine, timestamp: Date.now() }; const log: Log = { logLine, timestamp: Date.now() };
const logs = getLogs(); const logs = getLogs();
if (logs.length > MAX_LOG_LINES) { if (logs.length > MAX_LOG_LINES) {
logs.slice(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); logs.push(log);
setLogs(logs); setLogs(logs);
} catch (e) { } catch (e) {

View file

@ -18,6 +18,7 @@ export const logError = async (
} }
${error?.stack}`); ${error?.stack}`);
} else { } else {
console.log("here");
addLogLine( addLogLine(
`error: ${error?.name} ${error?.message} `error: ${error?.name} ${error?.message}
msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ""} msg: ${msg} ${info ? `info: ${JSON.stringify(info)}` : ""}

View file

@ -32,7 +32,8 @@ export enum LS_KEYS {
export const setData = (key: LS_KEYS, value: object) => { export const setData = (key: LS_KEYS, value: object) => {
if (typeof localStorage === "undefined") { if (typeof localStorage === "undefined") {
return null; console.log("early return");
// return null;
} }
localStorage.setItem(key, JSON.stringify(value)); localStorage.setItem(key, JSON.stringify(value));
}; };

View file

@ -1,6 +1,5 @@
import { WorkerSafeElectronClient } from "@ente/shared/electron/worker/client"; import { addLocalLog, logToDisk } from "@ente/shared/logging";
import { addLocalLog } from "@ente/shared/logging"; import { Remote, expose, wrap } from "comlink";
import { expose, Remote, wrap } from "comlink";
import { logError } from "../sentry"; import { logError } from "../sentry";
export class ComlinkWorker<T extends new () => InstanceType<T>> { export class ComlinkWorker<T extends new () => InstanceType<T>> {
@ -21,7 +20,8 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
addLocalLog(() => `Initiated ${this.name}`); addLocalLog(() => `Initiated ${this.name}`);
const comlink = wrap<T>(this.worker); const comlink = wrap<T>(this.worker);
this.remote = new comlink() as Promise<Remote<InstanceType<T>>>; this.remote = new comlink() as Promise<Remote<InstanceType<T>>>;
expose(WorkerSafeElectronClient, this.worker); // expose(WorkerSafeElectronClient, this.worker);
expose(workerBridge, this.worker);
} }
public getName() { public getName() {
@ -33,3 +33,16 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
addLocalLog(() => `Terminated ${this.name}`); 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<WorkerBridge>(self).foo`.
*/
const workerBridge = {
logToDisk,
};
export type WorkerBridge = typeof workerBridge;

View file

@ -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<WorkerBridge>(self);