mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-07 21:25:41 +00:00
Eagerly persist on WM_ENDSESSION (#18912)
Once an application has returned from handling `WM_ENDSESSION` the OS may kill the app at any point. This means we must persist our state while inside the message handler. Closes #17179 ## Validation Steps Performed Honestly, none. It's a race condition in the first place.
This commit is contained in:
@@ -899,7 +899,8 @@ LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM c
|
||||
RegisterApplicationRestart(nullptr, RESTART_NO_CRASH | RESTART_NO_HANG);
|
||||
return TRUE;
|
||||
case WM_ENDSESSION:
|
||||
_forcePersistence = true;
|
||||
_finalizeSessionPersistence();
|
||||
_skipPersistence = true;
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
@@ -946,7 +947,7 @@ void WindowEmperor::_persistState(const ApplicationState& state, bool serializeB
|
||||
state.PersistedWindowLayouts(nullptr);
|
||||
}
|
||||
|
||||
if (_forcePersistence || _app.Logic().Settings().GlobalSettings().ShouldUsePersistedLayout())
|
||||
if (_app.Logic().Settings().GlobalSettings().ShouldUsePersistedLayout())
|
||||
{
|
||||
for (const auto& w : _windows)
|
||||
{
|
||||
@@ -960,6 +961,13 @@ void WindowEmperor::_persistState(const ApplicationState& state, bool serializeB
|
||||
|
||||
void WindowEmperor::_finalizeSessionPersistence() const
|
||||
{
|
||||
if (_skipPersistence)
|
||||
{
|
||||
// We received WM_ENDSESSION and persisted the state.
|
||||
// We don't need to persist it again.
|
||||
return;
|
||||
}
|
||||
|
||||
const auto state = ApplicationState::SharedInstance();
|
||||
|
||||
_persistState(state, true);
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
UINT WM_TASKBARCREATED = 0;
|
||||
HMENU _currentWindowMenu = nullptr;
|
||||
bool _notificationIconShown = false;
|
||||
bool _forcePersistence = false;
|
||||
bool _skipPersistence = false;
|
||||
bool _needsPersistenceCleanup = false;
|
||||
SafeDispatcherTimer _persistStateTimer;
|
||||
std::optional<bool> _currentSystemThemeIsDark;
|
||||
|
||||
Reference in New Issue
Block a user