From 0b07ee1a879fba3e44210a56ff9172d267de2fd3 Mon Sep 17 00:00:00 2001 From: Bagus Indrayana Date: Mon, 28 Apr 2025 14:44:54 +0800 Subject: [PATCH] refactor: update logic to find webcontents that have send function --- src/main/libs/misc/ipcLogger.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/libs/misc/ipcLogger.ts b/src/main/libs/misc/ipcLogger.ts index 9451d518..87e824d6 100644 --- a/src/main/libs/misc/ipcLogger.ts +++ b/src/main/libs/misc/ipcLogger.ts @@ -4,7 +4,12 @@ export const ipcLogger = ({ content, cUid, level }: {content: string; cUid: stri if (level === 'error') { if (process.type !== undefined) { const contents = require('electron').webContents.getAllWebContents(); - const mainWindow = require('electron').webContents.fromId(1) ?? contents[0]; + let mainWindow = require('electron').webContents.fromId(1); + contents.forEach(content => { + if (content.send && mainWindow === undefined) { + mainWindow = content; + } + }); mainWindow.send('non-blocking-exception', { cUid, message: content, date: new Date() }); } if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(content); @@ -14,7 +19,12 @@ export const ipcLogger = ({ content, cUid, level }: {content: string; cUid: stri const escapedSql = content.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, '').replace(/\s\s+/g, ' '); if (process.type !== undefined) { const contents = require('electron').webContents.getAllWebContents(); - const mainWindow = require('electron').webContents.fromId(1) ?? contents[0]; + let mainWindow = require('electron').webContents.fromId(1); + contents.forEach(content => { + if (content.send && mainWindow === undefined) { + mainWindow = content; + } + }); mainWindow.send('query-log', { cUid, sql: escapedSql, date: new Date() }); } if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(escapedSql);