This was my prototyped fix for the crash, but uuhhhhggggggg

This commit is contained in:
Mike Griese
2022-01-12 17:00:23 -06:00
parent 63790b9a5f
commit 46c6403ac1
6 changed files with 37 additions and 1 deletions

View File

@@ -1472,6 +1472,11 @@ namespace winrt::TerminalApp::implementation
return _root != nullptr ? _root->ShouldUsePersistedLayout(_settings) : false;
}
bool AppLogic::ShouldActuallySpawnPersistedLayouts()
{
return _root != nullptr ? _root->ShouldActuallySpawnPersistedLayouts() : false;
}
void AppLogic::SaveWindowLayoutJsons(const Windows::Foundation::Collections::IVector<hstring>& layouts)
{
std::vector<WindowLayout> converted;

View File

@@ -81,6 +81,7 @@ namespace winrt::TerminalApp::implementation
bool AlwaysOnTop() const;
bool ShouldUsePersistedLayout();
bool ShouldActuallySpawnPersistedLayouts();
hstring GetWindowLayoutJson(Microsoft::Terminal::Settings::Model::LaunchPosition position);
void SaveWindowLayoutJsons(const Windows::Foundation::Collections::IVector<hstring>& layouts);
void IdentifyWindow();

View File

@@ -93,6 +93,7 @@ namespace TerminalApp
TaskbarState TaskbarState{ get; };
Boolean ShouldUsePersistedLayout();
Boolean ShouldActuallySpawnPersistedLayouts();
String GetWindowLayoutJson(Microsoft.Terminal.Settings.Model.LaunchPosition position);
void SaveWindowLayoutJsons(Windows.Foundation.Collections.IVector<String> layouts);

View File

@@ -302,6 +302,31 @@ namespace winrt::TerminalApp::implementation
settings.GlobalSettings().FirstWindowPreference() == FirstWindowPreference::PersistedWindowLayout;
}
bool TerminalPage::ShouldActuallySpawnPersistedLayouts() const
{
if (!_startupActions || IsElevated())
{
// there arent startup actions, or we're elevated. In that case, go for it.
return true;
}
// Check that there's at least one action that's not just an elevated newTab action.
for (const auto& action : _startupActions)
{
if (action.Action() == ShortcutAction::NewTab)
{
const auto& args{ action.Args().try_as<NewTabArgs>() };
if (args && args.TerminalArgs().Elevate())
{
continue;
}
}
return true;
}
return false;
}
// Method Description;
// - Checks if the current window is configured to load a particular layout
// Arguments:

View File

@@ -64,6 +64,7 @@ namespace winrt::TerminalApp::implementation
void Create();
bool ShouldUsePersistedLayout(Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const;
bool ShouldActuallySpawnPersistedLayouts() const;
std::optional<uint32_t> LoadPersistedLayoutIdx(Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const;
winrt::Microsoft::Terminal::Settings::Model::WindowLayout LoadPersistedLayout(Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const;
Microsoft::Terminal::Settings::Model::WindowLayout GetWindowLayout();

View File

@@ -231,7 +231,10 @@ void AppHost::_HandleCommandlineArgs()
{
const auto numPeasants = _windowManager.GetNumberOfPeasants();
const auto layouts = ApplicationState::SharedInstance().PersistedWindowLayouts();
if (_logic.ShouldUsePersistedLayout() && layouts && layouts.Size() > 0)
if (_logic.ShouldUsePersistedLayout() &&
layouts &&
layouts.Size() > 0 &&
_logic.ShouldActuallySpawnPersistedLayouts())
{
uint32_t startIdx = 0;
// We want to create a window for every saved layout.