From 69fc2d94ee7a138e71fc7a4c2e2f045f3ee628c8 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 14 May 2025 19:04:13 +0200 Subject: [PATCH] Clean up persisted windows after the feature is disabled (#18910) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ✅ --- src/cascadia/WindowsTerminal/WindowEmperor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index d0ab37175a..381b7f4c8e 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -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();