Skip to content

Commit

Permalink
Tray Icon PR followup (#10938)
Browse files Browse the repository at this point in the history
Some followups to #10368:
- Accidentally reverted a defapp change where the Monarch should not by default register itself as a handoff server.
- Destroy the tray icon if we're a monarch otherwise if we're a quake window we request the monarch to hide the icon.
  • Loading branch information
leonMSFT authored Aug 19, 2021
1 parent 46fd7ca commit 482dcec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/cascadia/Remoting/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// - <none>
// Return Value:
// - <none>
void WindowManager::RequestShowTrayIcon()
winrt::fire_and_forget WindowManager::RequestShowTrayIcon()
{
co_await winrt::resume_background();
_peasant.RequestShowTrayIcon();
}

Expand All @@ -543,8 +544,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// - <none>
// Return Value:
// - <none>
void WindowManager::RequestHideTrayIcon()
winrt::fire_and_forget WindowManager::RequestHideTrayIcon()
{
auto strongThis{ get_strong() };
co_await winrt::resume_background();
_peasant.RequestHideTrayIcon();
}

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/Remoting/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void SummonAllWindows();
Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> GetPeasantNames();

void RequestShowTrayIcon();
void RequestHideTrayIcon();
winrt::fire_and_forget RequestShowTrayIcon();
winrt::fire_and_forget RequestHideTrayIcon();
bool DoesQuakeWindowExist();

TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);
Expand Down
23 changes: 11 additions & 12 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ AppHost::AppHost() noexcept :

AppHost::~AppHost()
{
if (_window->IsQuakeWindow())
{
_windowManager.RequestHideTrayIcon();
}

// destruction order is important for proper teardown here
_window = nullptr;
_app.Close();
Expand Down Expand Up @@ -325,6 +320,15 @@ void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /*
// - <none>
void AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::TerminalApp::LastTabClosedEventArgs& /*args*/)
{
if (_windowManager.IsMonarch() && _trayIcon)
{
_DestroyTrayIcon();
}
else if (_window->IsQuakeWindow())
{
_HideTrayIconRequested();
}

_window->Close();
}

Expand Down Expand Up @@ -657,9 +661,6 @@ void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*s
{
_setupGlobalHotkeys();

// The monarch is just going to be THE listener for inbound connections.
_listenForInboundConnections();

if (_windowManager.DoesQuakeWindowExist() ||
_window->IsQuakeWindow() ||
(_logic.GetAlwaysShowTrayIcon() || _logic.GetMinimizeToTray()))
Expand Down Expand Up @@ -1056,11 +1057,10 @@ void AppHost::_DestroyTrayIcon()
}
}

winrt::fire_and_forget AppHost::_ShowTrayIconRequested()
void AppHost::_ShowTrayIconRequested()
{
if constexpr (Feature_TrayIcon::IsEnabled())
{
co_await winrt::resume_background();
if (_windowManager.IsMonarch())
{
if (!_trayIcon)
Expand All @@ -1075,11 +1075,10 @@ winrt::fire_and_forget AppHost::_ShowTrayIconRequested()
}
}

winrt::fire_and_forget AppHost::_HideTrayIconRequested()
void AppHost::_HideTrayIconRequested()
{
if constexpr (Feature_TrayIcon::IsEnabled())
{
co_await winrt::resume_background();
if (_windowManager.IsMonarch())
{
// Destroy it only if our settings allow it
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class AppHost

void _CreateTrayIcon();
void _DestroyTrayIcon();
winrt::fire_and_forget _ShowTrayIconRequested();
winrt::fire_and_forget _HideTrayIconRequested();
void _ShowTrayIconRequested();
void _HideTrayIconRequested();
std::unique_ptr<TrayIcon> _trayIcon;
winrt::event_token _ReAddTrayIconToken;
winrt::event_token _TrayIconPressedToken;
Expand Down

0 comments on commit 482dcec

Please sign in to comment.