Shutdown Hook
See original GitHub issueIs there a way for us to detect user shutdown to call some other functions (DB cleanup, etc.)?
Edit:
Btw, I’m using nwjs-sdk-v0.16.1-win-x64
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
JVM Shutdown Hook in Java - GeeksforGeeks
Shutdown Hooks are a special construct that allows developers to plug in a piece of code to be executed when the JVM is...
Read more >Adding Shutdown Hooks for JVM Applications - Baeldung
The JVM allows registering functions to run before it completes its shutdown. These functions are usually a good place for releasing resources ...
Read more >Design of Shutdown Hooks API
First, it gives the user complete control over the thread upon which a shutdown action is executed. The thread can be created in...
Read more >Java ShutdownHook - javatpoint
A special construct that facilitates the developers to add some code that has to be run when the Java Virtual Machine (JVM) is...
Read more >Useful example of a shutdown hook in Java? - Stack Overflow
1 Answer 1 · Let the shutdown hook set some AtomicBoolean (or volatile boolean) "keepRunning" to false · (Optionally, .interrupt the working ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree this would be both challenging to implement as a user of nwjs and likely trivial for the nwjs team to hook and perform a callback. In the meantime you’ll probably have to hack something together as proposed and, while the concept is simple, if you haven’t done it before, it could be quite daunting.
Just note that, even with the hook developed by the nwjs team, your app could be killed by the system before your api call finishes (there are several factors in play).
And if you implement a hack, there are several more factors: if it’s a second window it may not get to your code and the process may have exited (depending on nwjs implementation). Worse, it could be non-deterministic.
Best approach would be to fork nwjs and hook it yourself and submit a PR so it gets into master. I don’t have nwjs building from source or I’d take a stab at it.
Yes also when I did it with python I created another window. I guess I should have noted in my previous message, I was listening for login switches rather than shutdown. So I never tried to do something before shutdown. That would be a good thing for the app I’m working on to do, now that I think about it.
So I can’t say definitively if it would close those other windows, you’ll have to try it. I guess I mainly trying to point out that WM_QUERYENDSESSION is not a signal, and hopefully point you in a slightly better direction.