max-mapper / max-mapper/menubar

Error: Object has been destroyed when sending message from Main to Renderer

Open
#266 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
6.8k
Forks
363
PR merge metrics
No merged PRs in 30d

Description

Description

I am trying to send a message from Main to the Renderer and whenever I do, I get "Error: Object has been destroyed"

I can't figure out if I'm doing something incorrectly or if this is not possible with menubar.

I have successfully gotten messages to send to the menubar renderer when it is already open using the event reply method:

ipcMain.on('testFromRenderer', (event) => {
  event.reply('responseFromMain', 'responseContent')
})

However, I get an error when I try to trigger an event that isn't a direct response to an event from the Renderer

mb.window.send('triggerFromMain')
mb.window.webContents.send('triggerFromMain')

const mb = menubar({
  browserWindow: { webPreferences: { nodeIntegration: true } },
  dir: APP_PATH,
  icon: path.resolve(APP_PATH, './icon.png'),
  preloadWindow: true,
  showDockIcon: false,
  showOnAllWorkspaces: true,
  tooltip: 'Runner',
})

I create the menubar in one file and am trying to send this message from a very different part of the codebase. I have tried importing it, and also tried attaching mb to global. Not sure how to best approach this.

Steps to Reproduce the Problem
  1. Create a new menubar
  2. Attempt to send a message from Main
Expected Behaviour

Should be able to send a message

Actual Behaviour

Error: Object has been destroyed

Specifications
  • Menubar version: 7.2.0
  • Platform: OSX Catalina 10.15.1
  • Electron version: 7.1.10 (Run electron -v or node_modules/.bin/electron -v to get it)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the menubar creation shown in the issue and trace the ipcMain, mb.window.send, and mb.window.webContents.send calls. Reproduce the error using the stated menubar 7.2.0 and Electron 7.1.10 versions, then verify that a main-process message can be sent when the renderer is open without producing "Object has been destroyed".

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
desktop-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.