Menu

Closing our window does not quit our app, and the line that makes that true is an empty event handler
📰

Closing our window does not quit our app, and the line that makes that true is an empty event handler

DEV Community: node·Daniel Pertu·20 days ago
#nCZ0pehp
#devtonodejs#devto#dev#mainwindow#window
Reading 0:00
15s threshold

Notifio is a desktop app that checks your rental searches every 30 seconds and emails you when a new listing appears. The entire value of it is that it is running when you are not looking, so the most product-critical code in the app is not the monitor. It is the handful of lifecycle hooks that decide what "closed" means.

There are five of them and they do not agree with each other on purpose.

Hook one: the close button does not close

mainWindow . on ( ' close ' , ( event ) => { if ( ! ( app as any ). isQuitting ) { event . preventDefault (); mainWindow ?. hide (); } });

Enter fullscreen mode

Exit fullscreen mode

Pressing the red button or Alt+F4 hides the window and leaves the process running. The flag is the only thing that distinguishes a real quit from a close, and it is set in exactly two places: the tray's Quit item, and before-quit .

That (app as any) cast is not something I am proud of.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.