Clean up persisted windows after the feature is disabled (#18910)

I finally realized the missing piece.
We need to clear the state array unconditionally,
as otherwise it won't get cleared. Duh.

Closes #18584

## Validation Steps Performed
* Craft a state.json with a layout
* Launch Terminal while the feature is disabled
* state.json is cleaned up on exit 

(cherry picked from commit 69fc2d94ee7a138e71fc7a4c2e2f045f3ee628c8)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgaZGpY
Service-Version: 1.23
This commit is contained in:
Leonard Hecker 2025-05-14 19:04:13 +02:00 committed by Dustin L. Howett
parent 9476d0f9fa
commit 90a55ed3d9

View File

@ -925,9 +925,15 @@ void WindowEmperor::_finalizeSessionPersistence() const
{
const auto state = ApplicationState::SharedInstance();
if (_forcePersistence || _app.Logic().Settings().GlobalSettings().ShouldUsePersistedLayout())
// Calling an `ApplicationState` setter triggers a write to state.json.
// With this if condition we avoid an unnecessary write when persistence is disabled.
if (state.PersistedWindowLayouts())
{
state.PersistedWindowLayouts(nullptr);
}
if (_forcePersistence || _app.Logic().Settings().GlobalSettings().ShouldUsePersistedLayout())
{
for (const auto& w : _windows)
{
w->Logic().PersistState();