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 = () => {
addLogLine("exporting logs");
if (isElectron()) {
if (false && isElectron()) {
ElectronAPIs.openLogDirectory();
} else {
const logs = getDebugLogs();

View file

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

View file

@ -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<Blob> => {
// 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);

View file

@ -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);

View file

@ -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) {

View file

@ -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)}` : ""}

View file

@ -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));
};

View file

@ -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<T extends new () => InstanceType<T>> {
@ -21,7 +20,8 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
addLocalLog(() => `Initiated ${this.name}`);
const comlink = wrap<T>(this.worker);
this.remote = new comlink() as Promise<Remote<InstanceType<T>>>;
expose(WorkerSafeElectronClient, this.worker);
// expose(WorkerSafeElectronClient, this.worker);
expose(workerBridge, this.worker);
}
public getName() {
@ -33,3 +33,16 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {
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);