Skip to content

Conversation

@bagusindrayana
Copy link
Contributor

in ipcLogger.ts there code that get electron webcontens based on id

const mainWindow = require('electron').webContents.fromId(1);

on mac os when the app is closed (not exited) and reopened webContents id allwasy change (increment) so webContents element that have id 1 no longer available, this make mainWindow will be undefined

and make error in next line when call .send function from mainWindow that undefined

the solution is to get webContents not based on id, but between getting the first item directly or filtering by a certain attribute whose value is always the same

my solution is if initial mainWindow is undefined we will loop and find webContents that have send function

const contents = require('electron').webContents.getAllWebContents();
   let mainWindow = require('electron').webContents.fromId(1);
   contents.forEach(content => {
      if (content.send && mainWindow === undefined) {
         mainWindow = content;
      }
   });

i only test it for mac os version

@Fabio286 Fabio286 added enhancement 🚀 New feature or request MacOS 🍎 Something related to MacOS bug 🪲 Something isn't working and removed enhancement 🚀 New feature or request labels Apr 28, 2025
@Fabio286 Fabio286 linked an issue Apr 28, 2025 that may be closed by this pull request
@bagusindrayana
Copy link
Contributor Author

issue that mentioned about this
#750
#490

@Fabio286 Fabio286 changed the base branch from master to develop April 28, 2025 07:50
@Fabio286 Fabio286 merged commit c966cc4 into antares-sql:develop Apr 28, 2025
1 check passed
@antares-sql antares-sql deleted a comment from allcontributors bot Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working MacOS 🍎 Something related to MacOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read properties of undefined (reading 'send')

2 participants