felixhao28 / node-systray

A cross-platform systray library for nodejs.
https://www.npmjs.com/package/systray2
MIT License
32 stars 8 forks source link

Cannot read property 'on' of null #1

Closed alinnert closed 4 years ago

alinnert commented 4 years ago

First of all, I'm super happy you continue this project. I'm still very interested in this.

I've tried out your version of the library but already the demo code causes this error:

C:\projects\systray-test\node_modules\systray2\lib\index.js:184
        this._rl.on("line", function (line) {
                 ^

TypeError: Cannot read property 'on' of null
    at SysTray.onClick (C:\projects\systray-test\node_modules\systray2\lib\index.js:184:18)
    at Object.<anonymous> (C:\projects\systray-test\index.js:38:9)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
felixhao28 commented 4 years ago

Sorry, I forgot to mention I added an "init" method to call before actually spawning the tray process. The point of using an "init" function is to provide an async way of starting the tray process.

async function startTray() {
    const systray = new SysTray({...});
    await systray.init();
    systray.onClick(...);
}
felixhao28 commented 4 years ago

On second thought, I am going to change the behavior to not requiring to call "Systray.init()" but instead provide a "Systray.ready" to wait for the tray to be ready,

felixhao28 commented 4 years ago

This should be fixed in v2.0.4 . @alinnert will you try again?

alinnert commented 4 years ago

Awesome, it works now. Thanks a lot.