Skip to content

win32: drop application handler on WM_ENDSESSION#4425

Open
Legend-Master wants to merge 4 commits intorust-windowing:masterfrom
Legend-Master:wm-endsession
Open

win32: drop application handler on WM_ENDSESSION#4425
Legend-Master wants to merge 4 commits intorust-windowing:masterfrom
Legend-Master:wm-endsession

Conversation

@Legend-Master
Copy link
Copy Markdown
Contributor

@Legend-Master Legend-Master commented Nov 25, 2025

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

Reference tao PR: tauri-apps/tao#1126
Implemented the solution talked in #4149 (comment)

Comment thread winit/src/event_loop.rs
}
#[cfg(windows_platform)]
{
self.event_loop.run_app_on_demand(app)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this a separate call on Windows to pass in the ownership of app instead of &mut app so we can drop it later, but I am not exactly sure why it was done like this

let result = self.event_loop.run_app_on_demand(&mut app);
// SAFETY: unsure that the state is dropped before the exit from the event loop.
drop(app);
result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was done like that, because run_on_demand borrows, so you can not drop from it, since you'll be dropping & more likely, which won't work, but in run_app it's :static thus the actual value is being dropped.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that it's wrong too? run_app_on_demand doesn't borrow, and passing a reference prevents it from Drop-ing when e.g. NSApplicationDelegate is terminated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I change this for all platforms?

Comment thread winit-win32/src/event_loop.rs Outdated
@Legend-Master Legend-Master marked this pull request as ready for review November 25, 2025 01:55
if wparam == true as usize {
// Sent from Restart Manager
// > https://learn.microsoft.com/en-us/windows/win32/rstmgr/guidelines-for-applications
if lparam == ENDSESSION_CLOSEAPP as isize {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help testing this, you could try https://github.com/Legend-Master/windows-restart-manager-test, replace let file_path = HSTRING::from(r""); to the executable path you want to terminate, and cargo run

@madsmtm madsmtm added the DS - win32 Affects the Win32/Windows backend label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - win32 Affects the Win32/Windows backend

Development

Successfully merging this pull request may close these issues.

3 participants