Skip to content

Commit 9054c81

Browse files
authored
Fix persistence of handoff'd tabs (#17268)
As it turns out, for handoff'd connections `Initialize` isn't called and this meant the `_sessionId` was always null. After this PR we still don't have a `_profileGuid` but that's probably not a critical issue, since that's an inherent flaw with handoff. It can only be solved in a robust manner if WT gets launched before the console app is launched, but it's unlikely for that to ever happen. ## Validation Steps Performed * Launch * Register that version of WT as the default * Close all tabs (Ctrl+Shift+W) * `persistedWindowLayouts` is empty ✅ * Launch cmd/pwsh via handoff * You get 1 window ✅ * Close the window (= press the X button) * Launch * You get 2 windows ✅
1 parent f62d2d5 commit 9054c81

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,10 @@ namespace winrt::TerminalApp::implementation
18991899

19001900
void TerminalPage::PersistState()
19011901
{
1902-
if (_startupState != StartupState::Initialized)
1902+
// This method may be called for a window even if it hasn't had a tab yet or lost all of them.
1903+
// We shouldn't persist such windows.
1904+
const auto tabCount = _tabs.Size();
1905+
if (_startupState != StartupState::Initialized || tabCount == 0)
19031906
{
19041907
return;
19051908
}
@@ -1915,7 +1918,7 @@ namespace winrt::TerminalApp::implementation
19151918

19161919
// if the focused tab was not the last tab, restore that
19171920
auto idx = _GetFocusedTabIndex();
1918-
if (idx && idx != _tabs.Size() - 1)
1921+
if (idx && idx != tabCount - 1)
19191922
{
19201923
ActionAndArgs action;
19211924
action.Action(ShortcutAction::SwitchToTab);

src/cascadia/TerminalConnection/ConptyConnection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
180180
const HANDLE hRef,
181181
const HANDLE hServerProcess,
182182
const HANDLE hClientProcess,
183-
TERMINAL_STARTUP_INFO startupInfo) :
183+
const TERMINAL_STARTUP_INFO& startupInfo) :
184184
_rows{ 25 },
185185
_cols{ 80 },
186186
_inPipe{ hIn },
187187
_outPipe{ hOut }
188188
{
189+
_sessionId = Utils::CreateGuid();
190+
189191
THROW_IF_FAILED(ConptyPackPseudoConsole(hServerProcess, hRef, hSig, &_hPC));
190192
_piClient.hProcess = hClientProcess;
191193

src/cascadia/TerminalConnection/ConptyConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
1919
const HANDLE hRef,
2020
const HANDLE hServerProcess,
2121
const HANDLE hClientProcess,
22-
TERMINAL_STARTUP_INFO startupInfo);
22+
const TERMINAL_STARTUP_INFO& startupInfo);
2323

2424
ConptyConnection() noexcept = default;
2525
void Initialize(const Windows::Foundation::Collections::ValueSet& settings);

0 commit comments

Comments
 (0)