Skip to content

Commit

Permalink
fix a crash on startup where we might not have yet loaded the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jan 20, 2022
1 parent 0b18ae4 commit 4275c50
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,12 @@ namespace winrt::TerminalApp::implementation

bool AppLogic::ShouldImmediatelyHandoffToElevated()
{
if (!_loadedInitialSettings)
{
// Load settings if we haven't already
LoadSettings();
}

return _root != nullptr ? _root->ShouldImmediatelyHandoffToElevated(_settings) : false;
}
void AppLogic::HandoffToElevated()
Expand Down
20 changes: 18 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,37 @@ namespace winrt::TerminalApp::implementation
return true;
}

// Method Description:
// - Escape hatch for immediately dispatching requests to elevated windows
// when first launched. At this point in startup, the window doesn't exist
// yet, XAML hasn't been started, but we need to dispatch these actions.
// We can't just go through ProcessStartupActions, because that processes
// the actions async using the XAL dispatcher (which doesn't exist yet)
// - DON'T CALL THIS if you haven't already checked
// ShouldImmediatelyHandoffToElevated. If you're thinking about calling
// this outside of the one place it's used, that's probably the wrong
// solution.
// Arguments:
// - settings: the settings we should use for dispatching these actions. At
// this point in startup, we hadn't otherwise been initialized with these,
// so use them now.
// Return Value:
// - <none>
void TerminalPage::HandoffToElevated(CascadiaSettings& settings)
{
if (!_startupActions)
{
return;
}

// Hookup our event handlers to the ShortcutActionDispatch
_settings = settings;
_HookupKeyBindings(_settings.ActionMap());

// Hookup our event handlers to the ShortcutActionDispatch
_RegisterActionCallbacks();

for (const auto& action : _startupActions)
{
// only process new tabs and split panes. They're all going to the elevated window anyways.
if (action.Action() == ShortcutAction::NewTab || action.Action() == ShortcutAction::SplitPane)
{
_actionDispatch->DoAction(action);
Expand Down
9 changes: 7 additions & 2 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,15 @@ void AppHost::_HandleCommandlineArgs()
}
}

// TODO!
// This is a fix for GH#12190 andhopefully GH#12169.
//
// If the commandline we were provided is going to result in us only
// opening elevated terminal instances, then we need to not even create
// the window at all here. In that case, we're going through this
// special escape hatch to dispatch all the calls to elevate-shim, and
// then we're going to exit immediately.
if (_logic.ShouldImmediatelyHandoffToElevated())
{
// DebugBreak();
_shouldCreateWindow = false;
_logic.HandoffToElevated();
return;
Expand Down

0 comments on commit 4275c50

Please sign in to comment.