From 3aa083ba9a4000eb6339d409316bfb3c3aaf1844 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 2 Mar 2023 14:00:09 -0600 Subject: [PATCH 1/3] sure. It doesn't matter' --- .../TerminalSettingsModel/ActionMap.cpp | 5 +---- .../TerminalSettingsModel/Command.cpp | 21 ++++++++----------- src/cascadia/TerminalSettingsModel/Command.h | 6 ++---- .../TerminalSettingsModel/Command.idl | 3 +-- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/ActionMap.cpp b/src/cascadia/TerminalSettingsModel/ActionMap.cpp index cd7b1427254..dae2adf1feb 100644 --- a/src/cascadia/TerminalSettingsModel/ActionMap.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionMap.cpp @@ -898,8 +898,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // WHILE also making sure that upon re-saving the commands, we don't // actually serialize the results of the expansion. I don't think it is. - auto warnings{ winrt::single_threaded_vector() }; - std::vector sortedSchemes; sortedSchemes.reserve(schemes.Size()); @@ -921,8 +919,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Command::ExpandCommands(copyOfCommands, profiles, - winrt::param::vector_view{ sortedSchemes }, - warnings); + winrt::param::vector_view{ sortedSchemes }); _ExpandedMapCache = copyOfCommands; } diff --git a/src/cascadia/TerminalSettingsModel/Command.cpp b/src/cascadia/TerminalSettingsModel/Command.cpp index f9f52dcedaf..e66901725a9 100644 --- a/src/cascadia/TerminalSettingsModel/Command.cpp +++ b/src/cascadia/TerminalSettingsModel/Command.cpp @@ -480,8 +480,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // - void Command::ExpandCommands(IMap commands, IVectorView profiles, - IVectorView schemes, - IVector warnings) + IVectorView schemes) { std::vector commandsToRemove; std::vector commandsToAdd; @@ -491,7 +490,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { auto cmd{ get_self(nameAndCmd.Value()) }; - auto newCommands = _expandCommand(cmd, profiles, schemes, warnings); + auto newCommands = _expandCommand(cmd, profiles, schemes); if (newCommands.size() > 0) { commandsToRemove.push_back(nameAndCmd.Key()); @@ -529,21 +528,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // Arguments: // - expandable: the Command to potentially turn into more commands // - profiles: A list of all the profiles that this command should be expanded on. - // - warnings: If there were any warnings during parsing, they'll be - // appended to this vector. // Return Value: // - and empty vector if the command wasn't expandable, otherwise a list of // the newly-created commands. std::vector Command::_expandCommand(Command* const expandable, IVectorView profiles, - IVectorView schemes, - IVector& warnings) + IVectorView schemes) { std::vector newCommands; if (expandable->HasNestedCommands()) { - ExpandCommands(expandable->_subcommands, profiles, schemes, warnings); + ExpandCommands(expandable->_subcommands, profiles, schemes); } if (expandable->_IterateOn == ExpandCommandType::None) @@ -564,18 +560,19 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation const auto actualDataEnd = newJsonString.data() + newJsonString.size(); if (!reader->parse(actualDataStart, actualDataEnd, &newJsonValue, &errs)) { - warnings.Append(SettingsLoadWarnings::FailedToParseCommandJson); // If we encounter a re-parsing error, just stop processing the rest of the commands. return false; } // Pass the new json back though FromJson, to get the new expanded value. - std::vector newWarnings; - if (auto newCmd{ Command::FromJson(newJsonValue, newWarnings) }) + // FromJson requires that we pass in a vector to hang on to the + // warnings, but ultimately, we don't care about warnings during + // expansion. + std::vector unused; + if (auto newCmd{ Command::FromJson(newJsonValue, unused) }) { newCommands.push_back(*newCmd); } - std::for_each(newWarnings.begin(), newWarnings.end(), [warnings](auto& warn) { warnings.Append(warn); }); return true; }; diff --git a/src/cascadia/TerminalSettingsModel/Command.h b/src/cascadia/TerminalSettingsModel/Command.h index 4f4dcbe2048..7d246da26b1 100644 --- a/src/cascadia/TerminalSettingsModel/Command.h +++ b/src/cascadia/TerminalSettingsModel/Command.h @@ -43,8 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static void ExpandCommands(Windows::Foundation::Collections::IMap commands, Windows::Foundation::Collections::IVectorView profiles, - Windows::Foundation::Collections::IVectorView schemes, - Windows::Foundation::Collections::IVector warnings); + Windows::Foundation::Collections::IVectorView schemes); static std::vector LayerJson(Windows::Foundation::Collections::IMap& commands, const Json::Value& json); @@ -83,8 +82,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static std::vector _expandCommand(Command* const expandable, Windows::Foundation::Collections::IVectorView profiles, - Windows::Foundation::Collections::IVectorView schemes, - Windows::Foundation::Collections::IVector& warnings); + Windows::Foundation::Collections::IVectorView schemes); friend class SettingsModelLocalTests::DeserializationTests; friend class SettingsModelLocalTests::CommandTests; }; diff --git a/src/cascadia/TerminalSettingsModel/Command.idl b/src/cascadia/TerminalSettingsModel/Command.idl index b749a79fb0a..6a5a5fb950d 100644 --- a/src/cascadia/TerminalSettingsModel/Command.idl +++ b/src/cascadia/TerminalSettingsModel/Command.idl @@ -45,7 +45,6 @@ namespace Microsoft.Terminal.Settings.Model static void ExpandCommands(Windows.Foundation.Collections.IMap commands, Windows.Foundation.Collections.IVectorView profiles, - Windows.Foundation.Collections.IVectorView schemes, - Windows.Foundation.Collections.IVector warnings); + Windows.Foundation.Collections.IVectorView schemes); } } From 2d6fbc97bf8ee3372547ee2c61e6c76ae9e8f9ae Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 2 Mar 2023 16:07:09 -0600 Subject: [PATCH 2/3] Merge branch 'dev/migrie/oop/3/quenta-silmarillion' into dev/migrie/oop/3/akallabeth # Conflicts: # src/cascadia/TerminalApp/TerminalPage.h --- src/cascadia/TerminalApp/AppLogic.cpp | 10 ++++++++++ src/cascadia/TerminalApp/AppLogic.h | 1 + src/cascadia/TerminalApp/AppLogic.idl | 1 + .../TerminalSettingsModel/GlobalAppSettings.idl | 1 + src/cascadia/TerminalSettingsModel/MTSMSettings.h | 1 + src/cascadia/WindowsTerminal/WindowEmperor.cpp | 5 ++++- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 1a62d88e1e9..c17e0143f2a 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -674,6 +674,16 @@ namespace winrt::TerminalApp::implementation return _settings.GlobalSettings().IsolatedMode(); } + bool AppLogic::AllowHeadless() + { + if (!_loadedInitialSettings) + { + // Load settings if we haven't already + ReloadSettings(); + } + return _settings.GlobalSettings().AllowHeadless(); + } + TerminalApp::TerminalWindow AppLogic::CreateNewWindow() { if (_settings == nullptr) diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 6ab4722a2aa..43f25e0573f 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -65,6 +65,7 @@ namespace winrt::TerminalApp::implementation Microsoft::Terminal::Settings::Model::Theme Theme(); bool IsolatedMode(); + bool AllowHeadless(); TerminalApp::TerminalWindow CreateNewWindow(); diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index dea3281142e..b3c13110ab5 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -43,6 +43,7 @@ namespace TerminalApp Microsoft.Terminal.Settings.Model.Theme Theme { get; }; Boolean IsolatedMode { get; }; + Boolean AllowHeadless { get; }; FindTargetWindowResult FindTargetWindow(String[] args); diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index c0ea9ddb302..a02c3f06ffa 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -98,6 +98,7 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_SETTING(IVector, NewTabMenu); INHERITABLE_SETTING(Boolean, EnableColorSelection); INHERITABLE_SETTING(Boolean, IsolatedMode); + INHERITABLE_SETTING(Boolean, AllowHeadless); Windows.Foundation.Collections.IMapView ColorSchemes(); void AddColorScheme(ColorScheme scheme); diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index 0887f64ee50..a37d95138d8 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -63,6 +63,7 @@ Author(s): X(bool, TrimPaste, "trimPaste", true) \ X(bool, EnableColorSelection, "experimental.enableColorSelection", false) \ X(winrt::Windows::Foundation::Collections::IVector, NewTabMenu, "newTabMenu", winrt::single_threaded_vector({ Model::RemainingProfilesEntry{} })) \ + X(bool, AllowHeadless, "compatibility.allowHeadless", true) \ X(bool, IsolatedMode, "compatibility.isolatedMode", false) #define MTSM_PROFILE_SETTINGS(X) \ diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index c92cef041f7..e2a9ecb80c1 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -151,12 +151,15 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co }), _windows.end()); - if (_windows.size() == 0) + if (_windows.size() == 0 && + !_app.Logic().AllowHeadless()) { _close(); } }); + // TODO! in AllowHeadless, if a window wants to _quit_, then we should exit when we get to 0 windows. + window->Start(); } From 41827424db3f5886b591070061b600cacf6c89eb Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 2 Mar 2023 16:15:19 -0600 Subject: [PATCH 3/3] oh this SO could have been one commit (cherry picked from commit 8428f666bf3c3e51978ec080c2ac29df64893917) --- src/cascadia/WindowsTerminal/WindowEmperor.cpp | 9 ++++++--- src/cascadia/WindowsTerminal/WindowEmperor.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index e2a9ecb80c1..db8bd94fe1c 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -151,15 +151,16 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co }), _windows.end()); + // When we run out of windows, exit our process if and only if: + // * We're not allowed to run headless OR + // * we've explicitly been told to "quit", which should fully exit the Terminal. if (_windows.size() == 0 && - !_app.Logic().AllowHeadless()) + (_quitting || !_app.Logic().AllowHeadless())) { _close(); } }); - // TODO! in AllowHeadless, if a window wants to _quit_, then we should exit when we get to 0 windows. - window->Start(); } @@ -235,6 +236,8 @@ void WindowEmperor::_numberOfWindowsChanged(const winrt::Windows::Foundation::II void WindowEmperor::_quitAllRequested(const winrt::Windows::Foundation::IInspectable&, const winrt::Microsoft::Terminal::Remoting::QuitAllRequestedArgs& args) { + _quitting = true; + // Make sure that the current timer is destroyed so that it doesn't attempt // to run while we are in the middle of quitting. if (_getWindowLayoutThrottler.has_value()) diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.h b/src/cascadia/WindowsTerminal/WindowEmperor.h index d9816192bff..8a0039eb417 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.h +++ b/src/cascadia/WindowsTerminal/WindowEmperor.h @@ -49,6 +49,7 @@ class WindowEmperor std::vector _hotkeys; std::unique_ptr _notificationIcon; + bool _quitting{ false }; void _becomeMonarch(); void _numberOfWindowsChanged(const winrt::Windows::Foundation::IInspectable&, const winrt::Windows::Foundation::IInspectable&);