Skip to content

Application closes when destroying tray object #6956

Closed

Description

@Dletta
  • Electron version: 2.14.20
  • Operating system: Windows 7 Professional SP 1

I am running following code:

ipcMain.on("timer-done", (ev, arg) => {
  console.log("received:" + ev.sender);
  tray.displayBalloon({
    icon:`${__dirname}/img/app.png`,
    title:"Timer done!",
    content:randomSentence()
  })
  setTimeout(tray.destroy(), 2000)
  setTimeout(createTray(), 3000)
  ev.returnValue = 'Done'
})

I am trying to randomize the "content" of the display bubble. I have re-written the code to make this work, but when the setTimeout is called to kill the tray the application closes completely with no errors in the console. This seems to be a bug. Since it should just delay the destruction of the tray, not kill the application.

Activity

  1. enlight commented on Aug 24, 2016

    @enlight
    Contributor

    Whatever else is going, this won't delay anything:

    setTimeout(tray.destroy(), 2000)

    You're just passing the return of value of tray.destroy() to setTimeout(). that value is probably undefined, though I think setTimeout() will just ignore that.

  2. MarshallOfSound commented on Aug 24, 2016

    @MarshallOfSound
    Member

    Can you provide an minimum sample application that reproduces this issue. It's hard to even guess at what is going on when we don't know what fires 'timer-done' or what createTray does.

    Worth noting as @enlight said that your timeouts probably want to be

    setTimeout(() => tray.destroy(), 2000)
    setTimeout(() => createTray(), 3000)
  3. added
    blocked/need-info ❌
    on Aug 24, 2016
  4. Dletta commented on Aug 24, 2016

    @Dletta
    Author

    Thanks @enlight and @MarshallOfSound, I slapped my forehead after reading your comments.

    The create Tray function is as follows

    let tray = null
    
    var createTray = function() {
      tray = new Tray(`${__dirname}/img/app.png`)
      const contextMenu = Menu.buildFromTemplate([
        {label: 'Start Timer',
         click(item) {
           mainWindow.webContents.send("start");
         }
       }
      ])
      tray.setToolTip('Timer Settings for SitTimer.')
      tray.setContextMenu(contextMenu)
    }
    

    A renderer process is running a timer and after a set amount of time ipcRenderer.sendSync is triggering on "timer-done" event.

    I have since taken the setTimeout function out, because I realized I didn't have to regenerate the tray every time to change the "content" of the bubble, but since it the application quit on me when I had the code this way, I figured this might be related to a bug, which should be reported.

    Removing the setTimeout Functions fixed it for me.

  5. MarshallOfSound commented on Aug 24, 2016

    @MarshallOfSound
    Member

    Without a crash dump, error log or minimum code that reproduces the issue there isn't much anyone can do.

    You can see crash dumps (if there is one) by setting the environment variable.

    ELECTRON_ENABLE_STACK_DUMPING=true
  6. zeke commented on Aug 24, 2016

    @zeke
    Contributor

    Removing the setTimeout Functions fixed it for me.

    Looks like this issue is resolved, yeah?

  7. Dletta commented on Aug 24, 2016

    @Dletta
    Author

    I am working on getting a recreatable barebones and a stack dump. Although I can do what I want, should we not try to trace why this is happening? If not, we can close the issue and I will move on.

  8. Dletta commented on Aug 24, 2016

    @Dletta
    Author

    The stack dump says this:

    Backtrace:
            (No symbol) [0x00000001400C1095]
            (No symbol) [0x00000001400BD168]
            (No symbol) [0x00000001400BD269]
            (No symbol) [0x00000001400BC85F]
            TranslateMessageEx [0x0000000077A39C11+669]
            SetWindowTextW [0x0000000077A372F7+643]
            IsDialogMessageW [0x0000000077A36839+361]
            KiUserCallbackDispatcher [0x0000000077B6BA75+31]
            KillTimer [0x0000000077A3917A+26]
            (No symbol) [0x000007FEFBE210F4]
            (No symbol) [0x0000000000000003]
            TranslateMessageEx [0x0000000077A39AE6+370]
            CreateDialogParamW [0x0000000077A476E6+422]
    

    When I use the setTimeout correctly with the functions executing the function, such as I should have been using them, the application does not exit.

  9. Dletta commented on Aug 31, 2016

    @Dletta
    Author

    It seems it is caused by the way Node and V8 implement their timers. Close for Electron, thank you

  10. nalejandroveron commented on Apr 25, 2018

    @nalejandroveron

    I think that i've got it, just wrap the .destroy() in a setTimeout() like this:

    setTimeout(() => {
      myTray.destroy()
    }, 0)

    I don't understand why this issue was closed and even was not created on Node or V8 (if is their issue), furthermore, if we wrap the call on electron with the setTimeout should solve this right?

  11. Dletta commented on Apr 25, 2018

    @Dletta
    Author

    @Negan1911 I closed it, since I changed my code away from the use of setTimeout. This is 2 years ago and I can't remember why I did not create a new issue with Node or V8, but honestly I probably dug just deep enough to come to the conclusion that it wasn't electron that was causing the issue. (I'm not a professional coder)

  12. nalejandroveron commented on Apr 25, 2018

    @nalejandroveron

    @fuchidahiro oh sorry mate, i tought that was closed by a mantainer, my bad!

    This continues on #9982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked/need-info ❌

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions