mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 00:48:23 -06:00
Fix session being persisted even when disabled (#17211)
This fixes 2 bugs: * `PersistState` being called when the window is closed (as opposed to closing the tab). The settings check was missing. * Session cleanup running depending on whether the feature is currently enabled as opposed to whether it was enabled on launch. Closes #17206 Closes #17207 ## Validation Steps Performed * Create a bunch of leftover buffer_*.txt files by running the current Dev version off of main * Build this branch, then open and close a window * All buffer_*.txt are gone and state.json is cleaned up ✅
This commit is contained in:
parent
0b76c51ba1
commit
dbac3a1fa3
@ -263,7 +263,7 @@ namespace winrt::TerminalApp::implementation
|
||||
AppLogic::Current()->NotifyRootInitialized();
|
||||
}
|
||||
|
||||
void TerminalWindow::Quit()
|
||||
void TerminalWindow::PersistState()
|
||||
{
|
||||
if (_root)
|
||||
{
|
||||
|
||||
@ -73,7 +73,7 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void Create();
|
||||
|
||||
void Quit();
|
||||
void PersistState();
|
||||
|
||||
winrt::fire_and_forget UpdateSettings(winrt::TerminalApp::SettingsLoadEventArgs args);
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ namespace TerminalApp
|
||||
Boolean ShouldImmediatelyHandoffToElevated();
|
||||
void HandoffToElevated();
|
||||
|
||||
void Quit();
|
||||
void PersistState();
|
||||
|
||||
Windows.UI.Xaml.UIElement GetRoot();
|
||||
|
||||
|
||||
@ -1184,13 +1184,16 @@ winrt::fire_and_forget AppHost::_QuitRequested(const winrt::Windows::Foundation:
|
||||
co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher());
|
||||
|
||||
const auto strongThis = weakThis.lock();
|
||||
// GH #16235: If we don't have a window logic, we're already refrigerating, and won't have our _window either.
|
||||
if (!strongThis || _windowLogic == nullptr)
|
||||
if (!strongThis)
|
||||
{
|
||||
co_return;
|
||||
}
|
||||
|
||||
_windowLogic.Quit();
|
||||
if (_appLogic && _windowLogic && _appLogic.ShouldUsePersistedLayout())
|
||||
{
|
||||
_windowLogic.PersistState();
|
||||
}
|
||||
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
|
||||
@ -348,6 +348,14 @@ void WindowEmperor::_becomeMonarch()
|
||||
|
||||
_revokers.WindowCreated = _manager.WindowCreated(winrt::auto_revoke, { this, &WindowEmperor::_numberOfWindowsChanged });
|
||||
_revokers.WindowClosed = _manager.WindowClosed(winrt::auto_revoke, { this, &WindowEmperor::_numberOfWindowsChanged });
|
||||
|
||||
// If a previous session of Windows Terminal stored buffer_*.txt files, then we need to clean all those up on exit
|
||||
// that aren't needed anymore, even if the user disabled the ShouldUsePersistedLayout() setting in the meantime.
|
||||
{
|
||||
const auto state = ApplicationState::SharedInstance();
|
||||
const auto layouts = state.PersistedWindowLayouts();
|
||||
_requiresPersistenceCleanupOnExit = layouts && layouts.Size() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
// sender and args are always nullptr
|
||||
@ -486,7 +494,7 @@ void WindowEmperor::_finalizeSessionPersistence() const
|
||||
// Ensure to write the state.json before we TerminateProcess()
|
||||
state.Flush();
|
||||
|
||||
if (!_app.Logic().ShouldUsePersistedLayout())
|
||||
if (!_requiresPersistenceCleanupOnExit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ private:
|
||||
|
||||
std::unique_ptr<NotificationIcon> _notificationIcon;
|
||||
|
||||
bool _requiresPersistenceCleanupOnExit = false;
|
||||
bool _quitting{ false };
|
||||
|
||||
void _windowStartedHandlerPostXAML(const std::shared_ptr<WindowThread>& sender);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user