Skip to content

Commit

Permalink
[ainulindale] The Terminal shouldn't crash on a WM_SETTINGCHANGE
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 23, 2023
1 parent b1a867d commit 7649725
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void AppHost::Initialize()
_window->DragRegionClicked([this]() { _windowLogic.TitlebarClicked(); });

_window->WindowVisibilityChanged([this](bool showOrHide) { _windowLogic.WindowVisibilityChanged(showOrHide); });
_window->UpdateSettingsRequested([this]() { _appLogic.ReloadSettings(); });
_window->UpdateSettingsRequested({ this, &AppHost::_requestUpdateSettings });

_revokers.RequestedThemeChanged = _windowLogic.RequestedThemeChanged(winrt::auto_revoke, { this, &AppHost::_UpdateTheme });
_revokers.FullscreenChanged = _windowLogic.FullscreenChanged(winrt::auto_revoke, { this, &AppHost::_FullscreenChanged });
Expand Down Expand Up @@ -1228,3 +1228,11 @@ void AppHost::_handleSendContent(const winrt::Windows::Foundation::IInspectable&
{
_windowLogic.SendContentToOther(winrt::TerminalApp::RequestReceiveContentArgs{ args.SourceWindow(), args.TargetWindow(), args.TabIndex() });
}

// Bubble the update settings request up to the emperor. We're being called on
// the Window thread, but the Emperor needs to update the settings on the _main_
// thread.
void AppHost::_requestUpdateSettings()
{
_UpdateSettingsRequestedHandlers();
}
4 changes: 4 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class AppHost

static void s_DisplayMessageBox(const winrt::TerminalApp::ParseCommandlineResult& message);

WINRT_CALLBACK(UpdateSettingsRequested, winrt::delegate<void()>);

private:
std::unique_ptr<IslandWindow> _window;

Expand Down Expand Up @@ -123,6 +125,8 @@ class AppHost
void _handleAttach(const winrt::Windows::Foundation::IInspectable& sender,
winrt::Microsoft::Terminal::Remoting::AttachRequest args);

void _requestUpdateSettings();

// Page -> us -> monarch
void _handleReceiveContent(const winrt::Windows::Foundation::IInspectable& sender,
winrt::TerminalApp::RequestReceiveContentArgs args);
Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args, co
// Add a callback to the window's logic to let us know when the window's
// quake mode state changes. We'll use this to check if we need to add
// or remove the notification icon.
sender->Logic().IsQuakeWindowChanged([this](auto&&, auto&&) -> winrt::fire_and_forget {
sender->Logic().IsQuakeWindowChanged([this](auto&&, auto &&) -> winrt::fire_and_forget {
co_await wil::resume_foreground(this->_dispatcher);
this->_checkWindowsForNotificationIcon();
});
sender->UpdateSettingsRequested([this]() -> winrt::fire_and_forget {
// We MUST be on the main thread to update the settings. We will crash when trying to enumerate fragement extensions otherwise.
co_await wil::resume_foreground(this->_dispatcher);
_app.Logic().ReloadSettings();
});

// These come in on the sender's thread. Move back to our thread.
co_await wil::resume_foreground(_dispatcher);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/WindowThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void WindowThread::Start()
_args,
_manager,
_peasant);

_host->UpdateSettingsRequested([this]() { _UpdateSettingsRequestedHandlers(); });
// Enter the main window loop.
const auto exitCode = WindowProc();
_host = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/WindowThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WindowThread

WINRT_CALLBACK(Started, winrt::delegate<>);
WINRT_CALLBACK(Exited, winrt::delegate<uint64_t>);
WINRT_CALLBACK(UpdateSettingsRequested, winrt::delegate<void()>);

private:
winrt::Microsoft::Terminal::Remoting::Peasant _peasant{ nullptr };
Expand Down

0 comments on commit 7649725

Please sign in to comment.