+
Skip to content

Conversation

savely-krasovsky
Copy link
Contributor

@savely-krasovsky savely-krasovsky commented Nov 8, 2024

Description of Change

Current Electron version allows to handle only WM_ENDSESSION, but not WM_QUERYENDSESSION. This cause a lot of problems while Electron app is packaged into own MSI and is a menubar/tray app. For example currently we cannot close app using Restart Manager which is used by default since Windows Installer 4.0. We have to use util:CloseApplication or call taskkil.

Quote from Restart Manager guidelines for Applications:

Applications running on Windows Vista and Windows Server 2008 should adhere to these guidelines to ensure that the Restart Manager can shut down and restart applications if necessary to install updates.

GUI applications should listen for the WM_QUERYENDSESSION message and return a value of TRUE if the application is prepared to shut down and restart. If no application returns a value of FALSE, the Restart Manager sends a WM_ENDSESSION message with the lParam parameter set to ENDSESSION_CLOSEAPP (0x1) and the wparam parameter set to TRUE. [...] If any GUI application responds to a WM_QUERYENDSESSION message by returning a value of FALSE, the shutdown is canceled.

So to properly close GUI app we need to handle WM_QUERYENDSESSION properly and return TRUE. But for now for any unknown WM message it will cause us to return FALSE (see calling code: https://github.com/chromium/chromium/blob/134896c2d6148c6bd2f7b096b0664b1e4013cb5c/ui/views/win/hwnd_message_handler.cc#L1069).

My implementation will return TRUE by default (in case of WM_QUERYSESSION), so it could probably fix longstanding issues like this: #15880. ev.preventDefault() can still return old behaviour.

Also both query-session-end and session-end now return a reasons why they receiving this event, it could be shutdown, close-app, critical and logoff.

Checklist

Release Notes

Notes: Added query-session-end event and improved session-end events on Windows

Copy link

welcome bot commented Nov 8, 2024

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Nov 8, 2024
@savely-krasovsky savely-krasovsky changed the title feat: add query-session-end event for Windows feat: add query-session-end and improve session-end events on Windows Nov 8, 2024
Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@savely-krasovsky
Copy link
Contributor Author

@codebytere thanks for the review! Everything sounds reasonable. I would commit fixes soon.

@samuelmaddock samuelmaddock added semver/minor backwards-compatible functionality no-backport labels Nov 15, 2024
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Nov 15, 2024
Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

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

API LGTM

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
@savely-krasovsky
Copy link
Contributor Author

savely-krasovsky commented Nov 18, 2024

Any ideas what went wrong with Linux tests? I didn't change anything related. Could it just a flaky test?

Nevermind, it was a flaky test.

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

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

Left a small suggestion for the session-end event, but overall API LGTM

Co-authored-by: Will Anderson <will@itsananderson.com>
@savely-krasovsky
Copy link
Contributor Author

@itsananderson @samuelmaddock @codebytere requesting a last review I hope! Fixed everything you highlighted.

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this!

@VerteDinde VerteDinde merged commit c5ea177 into electron:main Nov 22, 2024
51 checks passed
Copy link

welcome bot commented Nov 22, 2024

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk
Copy link

release-clerk bot commented Nov 22, 2024

Release Notes Persisted

Added query-session-end event and improved session-end events on Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载