tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[docs] Clarification needed: Graceful shutdown when the operating system shuts down

Open crisby-ftapi opened this issue 4 weeks ago • 4 comments

I’m currently implementing logic to persist and handle application state when the operating system is shutting down. I checked the Tauri documentation and expected that the RunEvent::Exit or RunEvent::ExitRequested events would trigger during an OS-initiated shutdown. However, these events do not seem to fire when Windows shuts down the application as part of the system shutdown process.

At the moment I’m unsure what the recommended way is to handle this use case in Tauri and whether there is a specific API or pattern for detecting OS-level shutdown events. Since gracefully handling state on system shutdown is a common requirement for many desktop applications, I believe this would be useful to clarify or document.

My current development is on Windows, though I’m not sure whether OS-specific behavior should be considered for the docs.

Could the documentation be extended to explain:

  • How Tauri applications should detect and respond to operating system shutdowns?
  • Whether Exit or ExitRequested is expected to fire on OS shutdown, or if another mechanism should be used?
  • Any OS-specific considerations (e.g., Windows, macOS, Linux)?
  • Examples or recommended patterns for graceful shutdown in this scenario?

Thank you!

crisby-ftapi avatar Nov 25 '25 14:11 crisby-ftapi

i think for windows this is the relevant PR https://github.com/tauri-apps/tao/pull/1157

on macos applicationShouldTerminate should be called unless the user changed a macOS setting that will terminate apps forcefully instead (forgot it's name but it used to be a thing) - this also has an open PR https://github.com/tauri-apps/tao/pull/1003 :/

no idea about linux

FabianLars avatar Nov 25 '25 14:11 FabianLars

Thanks @FabianLars for the quick reply. From the PR, I understand that this isn’t a documentation issue. The functionality is already under consideration and may soon be implemented. With that in mind, I believe this documentation request is obsolete and can be closed.

Thanks 👍

crisby-ftapi avatar Nov 25 '25 14:11 crisby-ftapi

I believe RunEvent::Exit should be called on system shutdown already after it's implemented in https://github.com/tauri-apps/tao/pull/1126, https://github.com/tauri-apps/tao/pull/1157 is for the Restart Manager Try update tao to latest and see if that works, if not then we have a bug

The RunEvent::ExitRequested event on system shutdown is not yet supported though, that requires this event in tao from either https://github.com/tauri-apps/tao/pull/1003 or someone adds it for the Windows implementation

Nonetheless, we should add some documentation around this

Legend-Master avatar Nov 26 '25 03:11 Legend-Master

Thanks, @Legend-Master! You were right — RunEvent::Exit works perfectly, while RunEvent::ExitRequested doesn’t. This solved my problem. I really appreciate your help!

Hopefully I’ll find some time this week to contribute to the documentation about this. :)

crisby-ftapi avatar Nov 26 '25 14:11 crisby-ftapi