Repository: microsoft/terminal (language: cpp)

Issue:
Settings error/warning dialog seems to self-dismiss on startup
### Windows Terminal version

56d451ded7cf9ca64abc511740221b963c98ded3

### Windows build number

10.0.22621.1555

### Other Software

_No response_

### Steps to reproduce

1. Checkout the main branch at 56d451ded7cf9ca64abc511740221b963c98ded3
2. Make your settings file invalid
3. Start Terminal

### Expected Behavior

The settings error dialog should be displayed.

### Actual Behavior

The settings error dialog displays for a fraction of a second and then disappears. See video below - you can just see a glimpse of the dialog. This also happens if you've got warnings (which is how I found it originally). This didn't happen whilst I was developing #15082 (which was merged with main at 0105807be22571c8470fc3be6b660da64683528e) - as I tested the duplicate environment variables warning numerous times, so I'd guess this is caused by #15078.


https://user-images.githubusercontent.com/5821575/231422935-3313c80b-3d64-4233-9bce-b63482c1fd28.mp4




Discussion / hints:
![image](https://user-images.githubusercontent.com/18356694/231483451-08e87d32-7fc8-4215-aeed-78fc7e5500a9.png)


Fix patch:
diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp
index 163d056df88..1bd3455b7be 100644
--- a/src/cascadia/WindowsTerminal/AppHost.cpp
+++ b/src/cascadia/WindowsTerminal/AppHost.cpp
@@ -1157,6 +1157,10 @@ void AppHost::_SystemMenuChangeRequested(const winrt::Windows::Foundation::IInsp
 // - <none>
 void AppHost::_WindowMoved()
 {
+    if (_isWindowInitialized < WindowInitializedState::Initialized)
+    {
+        return;
+    }
     if (_windowLogic)
     {
         // Ensure any open ContentDialog is dismissed.
@@ -1214,6 +1218,8 @@ void AppHost::_PropertyChangedHandler(const winrt::Windows::Foundation::IInspect
 winrt::fire_and_forget AppHost::_WindowInitializedHandler(const winrt::Windows::Foundation::IInspectable& /*sender*/,
                                                           const winrt::Windows::Foundation::IInspectable& /*arg*/)
 {
+    _isWindowInitialized = WindowInitializedState::Initializing;
+
     // GH#11561: We're totally done being initialized. Resize the window to
     // match the initial settings, and then call ShowWindow to finally make us
     // visible.
@@ -1235,7 +1241,6 @@ winrt::fire_and_forget AppHost::_WindowInitializedHandler(const winrt::Windows::
     // paints.
     co_await wil::resume_foreground(_windowLogic.GetRoot().Dispatcher(), winrt::Windows::UI::Core::CoreDispatcherPriority::Low);
 
-    _isWindowInitialized = true;
     ShowWindow(_window->GetHandle(), nCmdShow);
 
     // If we didn't start the window hidden (in one way or another), then try to
@@ -1252,6 +1257,16 @@ winrt::fire_and_forget AppHost::_WindowInitializedHandler(const winrt::Windows::
         SetForegroundWindow(_window->GetHandle());
         _peasantNotifyActivateWindow();
     }
+
+    // Don't set our state to Initialized until after the call to ShowWindow.
+    // When we call ShowWindow, the OS will also send us a WM_MOVE, which we'll
+    // then use to try and dismiss an open dialog. This creates the unintended
+    // side effect of immediately dismissing the initial warning dialog, if
+    // there were settings load warnings.
+    //
+    // In AppHost::_WindowMoved, we'll make sure we're at least initialized
+    // before dismissing open dialogs.
+    _isWindowInitialized = WindowInitializedState::Initialized;
 }
 
 winrt::TerminalApp::TerminalWindow AppHost::Logic()
diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h
index 9ce5b49b05c..dc30ce82692 100644
--- a/src/cascadia/WindowsTerminal/AppHost.h
+++ b/src/cascadia/WindowsTerminal/AppHost.h
@@ -37,7 +37,15 @@ class AppHost
     winrt::Microsoft::Terminal::Remoting::Peasant _peasant{ nullptr };
 
     winrt::com_ptr<IVirtualDesktopManager> _desktopManager{ nullptr };
-    bool _isWindowInitialized = false;
+
+    enum WindowInitializedState : uint32_t
+    {
+        NotInitialized = 0,
+        Initializing = 1,
+        Initialized = 2,
+    };
+
+    WindowInitializedState _isWindowInitialized{ WindowInitializedState::NotInitialized };
     bool _useNonClientArea{ false };
     winrt::Microsoft::Terminal::Settings::Model::LaunchMode _launchMode{};
 


Test patch: