When an application closes down, in some cases it needs to save some state information, possibly user data, settings, files to reopen on startup. Under Linux, your LCL apps probably (depending distro, widget set) will not get a chance to do so if that close down happens as the computer is being powered off.
Executive summary -- If the user manually closes the app before powering down the compute, LCL events like FormCloseQuery() works fine. No problems.
- If the app is still running when the user closed down the computer, its most likely a "graceful shutdown" of the app will not happen. In this case, TApplication.OnQueryEndSession is supposed to help, but probably not, read on -
- On Gnome, TApplication.OnQueryEndSession is not fired at PowerDown, any widget set.
- With gtk2, apparently TApplication.OnQueryEndSession never happens with any desktop.
- Non-GUI apps, built with FPC but not LCL can divert SigTERM and handle it successfully. They use TCustomApplication, it does not introduce the problem that TApplication does.
- Windows and MacOS don't seem to have a problem.
Details -Gnome Desktop. The default desktop for the major players in Linux, Debain, Ubuntu, Fedora, SUSE all do not trigger TApplication.OnQueryEndSession. This may be Wayland related, not certain. Installing XLibre gets Qt5/6 working in (only) some cases Fred.
GTK2 Widgetset. Does not trigger TApplication.OnQueryEndSession. The forum has discussions about this going back many years. However, there is a workaround, re-directing SigTERM to a handler of your choosing does seem to work in some systems for gtk2 only. Not Gnome, not Ubuntu (and derivatives, ie Linux Mint). See below.
Other Desktops. ie KDE, Mate, XFCe Cinnamon etc. Do seem to trigger TApplication.OnQueryEndSession when using Qt5 and Qt6, unpredictably a few GTK3 hits too. Not gtk2.
Given most of (linux) end uses use Gnome and most linux programmers use gtk2 (tbc), its fair to say, user data is at risk.
The really grotty details Attached source will build gtk2, gtk3, Qt5 and Qt6 versions of a test app. Launch one by double clicking from your file manager (not from command line, other issues). Then restart (not log off, other issues) and inspect the app_shutdown.log file in your home directory.
I created the
https://wiki.freepascal.org/Shutdown_and_Powerdown after some tests using Qt5 and XFCE, sadly that was grossly optimistic and will need a massive rewrite. I will, shortly, get my chart up there showing what does, and does not work. Its not pretty.
Anyone who cares to correct my mistakes is very welcome !
Davo
See also
https://forum.lazarus.freepascal.org/index.php/topic,72232.0.html