Browse Source

fix logging inside worker (#1530)

Abhinav Kumar 1 năm trước cách đây
mục cha
commit
7835faae1a

+ 5 - 0
packages/shared/electron/service.ts

@@ -16,6 +16,7 @@ export interface LimitedElectronAPIs
         | 'deleteDiskCache'
         | 'getSentryUserID'
         | 'convertToJPEG'
+        | 'logToDisk'
     > {}
 
 class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
@@ -66,6 +67,10 @@ class WorkerSafeElectronServiceImpl implements LimitedElectronAPIs {
         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();

+ 4 - 0
packages/shared/electron/worker/client.ts

@@ -14,6 +14,7 @@ export interface ProxiedLimitedElectronAPIs {
         inputFileData: Uint8Array,
         filename: string
     ) => Promise<Uint8Array>;
+    logToDisk: (message: string) => void;
 }
 export interface ProxiedWorkerLimitedCache {
     match: (
@@ -51,6 +52,9 @@ export class WorkerSafeElectronClient implements ProxiedLimitedElectronAPIs {
     ): Promise<Uint8Array> {
         return await ElectronAPIs.convertToJPEG(inputFileData, filename);
     }
+    logToDisk(message: string) {
+        return ElectronAPIs.logToDisk(message);
+    }
 }
 
 function transformMatch(

+ 2 - 2
packages/shared/logging/index.ts

@@ -1,9 +1,9 @@
 import isElectron from 'is-electron';
-import ElectronAPIs from '@ente/shared/electron';
 import { logError } from '@ente/shared/sentry';
 import { getAppEnv } from '../apps/env';
 import { APP_ENV } from '../apps/constants';
 import { formatLog, logWeb } from './web';
+import { WorkerSafeElectronService } from '../electron/service';
 
 export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
 export const MAX_LOG_LINES = 1000;
@@ -18,7 +18,7 @@ export function addLogLine(
             console.log(completeLog);
         }
         if (isElectron()) {
-            ElectronAPIs.logToDisk(completeLog);
+            WorkerSafeElectronService.logToDisk(completeLog);
         } else {
             logWeb(completeLog);
         }