zaaack / node-systray

A cross-platform systray library for nodejs.
https://zaaack.github.io/node-systray/
MIT License
84 stars 26 forks source link

On Windows the icon stays visible after exiting the app until you move your mouse over it #1

Open alinnert opened 6 years ago

alinnert commented 6 years ago

I'm using Windows 10 (1709). I wrote a simple test script and everything works fine so far. But when I exit the app the icon in the systray doesn't get removed. It stays there until I hover the mouse pointer over it. I know this behavior from apps that crash. Windows doesn't seem to recognize that the app isn't running anymore.

I've tried to exit the app the following ways:

// v1
systray.kill()
// v2
process.exit(0)
// v3
systray.kill()
process.exit(0)

None of them makes the icon disappear after the app stops running.

zaaack commented 6 years ago

Sorry I haven't tested in windows yet, maybe I should quit in go side, I'll look into this as soon as possible, thanks for your report!

zaaack commented 6 years ago

@alinnert Just published a new version (systray@1.0.2), should fixed your issue.

zaaack commented 6 years ago

BTW, if you want to implement something on systray, you might also want to check this out:

https://github.com/zaaack/aria2c-node-gui (A demo project to shows how to integrate with opn, node-notifier, and also include pack script by node-packer to create a single executable file).

alinnert commented 6 years ago

@zaaack Thank you, I'll try it again this evening.

And thanks, I'll check it out. The funny thing is, I'm already using opn. node-notifier seems useful, too.

But thanks for mentioning node-packer. Currently, I'm using a .cmd file and was looking for a way to convert that to a .exe. node-packer might be worth a try.

alinnert commented 6 years ago

@zaaack unfortunately it did not fix the issue. I've looked up the node_modules/systray folder. The version got updated to 1.0.2. Also when I start tray_windows(_release).exe on its own (just out of curiousity) it behaves the same way.

zaaack commented 6 years ago

Can you run tray_windows.exe in cmd.exe directly, and copy test/menu.json's content to the command prompt, then press enter,and find the tray icon, and press ctrl+c to see if the icon still there?

zaaack commented 6 years ago

Can you run tray_windows.exe in cmd.exe directly, and copy test/menu.json's content to the command prompt, then press enter,and find the tray icon, and press ctrl+c to see if the icon still there?

zaaack commented 6 years ago

I tried https://github.com/zaaack/aria2c-node-gui in a win10 machine, and it works well, but I reproduced your issue when quit the node process immediately after call systray.kill(). I think I know why, the systray process is killed without cleaning after nodejs process exit. You should wait for the systray process quit before exit nodejs process.

I'll try to fix this later, for now, you can find a workaround example here: https://github.com/zaaack/aria2c-node-gui/blob/master/src/main.ts#L92-L99

zaaack commented 6 years ago

Updated systray.kill() method, now it would automatic quit current nodejs process with less-buggy way, unless you pass a bool param.

alinnert commented 6 years ago

No, it's still not working for me. I've noticed it does work if I call tray_windows.exe via cmd. It also works if I open the exe with a double click and close the opening console window via ctrl + c. But it doesn't if a close this window with the "X" in the title bar. But I think that's just how the console works.

I've removed the process.exit(), tried systray.kill() with true, false and no parameter. I've also tried your workaround with the current version. But since the exe is working the problem should be on the JS side, right?

zaaack commented 6 years ago

If you close the console by close button, the systray process was killed without cleaning, it need time to notify windows that it's quit, and this is how the trick works.

Are you quit by tray menu? Actually i tried https://github.com/zaaack/aria2c-node-gui , and quiting by tray menu works, can you try this demo project? The only dependence is it need aria2c.exe in your path environment, you can find here: https://github.com/saaiful/aria2-win64-rpc/blob/master/aria2c.exe

Maybe you can add a setTimeout(()=> {console.log("quit node now"); process.exit(0)}, 500) after systray.kill(false) to delay node process' quitting.

alinnert commented 6 years ago

Well, I tried to try the demo project, but it fails at npm start. It says that bin is an illegal option in del ./bin/** (from the clean task). But anyway, I'm using systray.kill() from inside systray.onClick(), just like the demo project. Also the setTimeout you mentioned didn't help. Now I've also tried systray.kill() right after initializing it (new SysTray()). With a setTimeout it's the same behavior. But without setTimeout the icon doesn't even show up. Maybe the systray process isn't able to finish loading in that case?

zaaack commented 6 years ago

You are right, could you post your code here? Or a minimal project would be best.

alinnert commented 6 years ago

project-hub-src.zip

I've created a ZIP with my current project. The only thing it does is listing all directories inside C:\projects (via ajax).

zaaack commented 6 years ago

I have reproduced this bug with your code, and my code, too(strange that I didn't notice it before). I'm not sure I can fix this, but the upstream project having some updates, I'll give a try after I finish my current work (just need several days).

gp-slick-coder commented 6 years ago

have the same issue :-| Maybe here somewhere is a solution for the problem? https://github.com/nwjs/nw.js/tree/nw30/src/api/tray

Any help would be gorgeous. 🥇

genesy commented 5 years ago

This is still an issue :(

felixhao28 commented 3 years ago

@genesy and generally everyone on this thread, I forked this repo and fixed this issue and published it as systray2 on npm. I will continue to maintain systray project as systray2 since this project is pretty much abandoned.