question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is 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:open
  • Created 7 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gwickstedcommented, Mar 6, 2019

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.

1reaction
bluthencommented, Mar 4, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found