Tray Icon PR followup (#10938)

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.
This commit is contained in:
Leon Liang 2021-08-19 10:38:18 -07:00 committed by GitHub
parent 46fd7caf5a
commit 482dcec60a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 18 deletions

View file

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

View file

@ -43,8 +43,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void SummonAllWindows(); void SummonAllWindows();
Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> GetPeasantNames(); Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> GetPeasantNames();
void RequestShowTrayIcon(); winrt::fire_and_forget RequestShowTrayIcon();
void RequestHideTrayIcon(); winrt::fire_and_forget RequestHideTrayIcon();
bool DoesQuakeWindowExist(); bool DoesQuakeWindowExist();
TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs); TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);

View file

@ -93,11 +93,6 @@ AppHost::AppHost() noexcept :
AppHost::~AppHost() AppHost::~AppHost()
{ {
if (_window->IsQuakeWindow())
{
_windowManager.RequestHideTrayIcon();
}
// destruction order is important for proper teardown here // destruction order is important for proper teardown here
_window = nullptr; _window = nullptr;
_app.Close(); _app.Close();
@ -325,6 +320,15 @@ void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /*
// - <none> // - <none>
void AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::TerminalApp::LastTabClosedEventArgs& /*args*/) 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(); _window->Close();
} }
@ -657,9 +661,6 @@ void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*s
{ {
_setupGlobalHotkeys(); _setupGlobalHotkeys();
// The monarch is just going to be THE listener for inbound connections.
_listenForInboundConnections();
if (_windowManager.DoesQuakeWindowExist() || if (_windowManager.DoesQuakeWindowExist() ||
_window->IsQuakeWindow() || _window->IsQuakeWindow() ||
(_logic.GetAlwaysShowTrayIcon() || _logic.GetMinimizeToTray())) (_logic.GetAlwaysShowTrayIcon() || _logic.GetMinimizeToTray()))
@ -1056,11 +1057,10 @@ void AppHost::_DestroyTrayIcon()
} }
} }
winrt::fire_and_forget AppHost::_ShowTrayIconRequested() void AppHost::_ShowTrayIconRequested()
{ {
if constexpr (Feature_TrayIcon::IsEnabled()) if constexpr (Feature_TrayIcon::IsEnabled())
{ {
co_await winrt::resume_background();
if (_windowManager.IsMonarch()) if (_windowManager.IsMonarch())
{ {
if (!_trayIcon) if (!_trayIcon)
@ -1075,11 +1075,10 @@ winrt::fire_and_forget AppHost::_ShowTrayIconRequested()
} }
} }
winrt::fire_and_forget AppHost::_HideTrayIconRequested() void AppHost::_HideTrayIconRequested()
{ {
if constexpr (Feature_TrayIcon::IsEnabled()) if constexpr (Feature_TrayIcon::IsEnabled())
{ {
co_await winrt::resume_background();
if (_windowManager.IsMonarch()) if (_windowManager.IsMonarch())
{ {
// Destroy it only if our settings allow it // Destroy it only if our settings allow it

View file

@ -87,8 +87,8 @@ private:
void _CreateTrayIcon(); void _CreateTrayIcon();
void _DestroyTrayIcon(); void _DestroyTrayIcon();
winrt::fire_and_forget _ShowTrayIconRequested(); void _ShowTrayIconRequested();
winrt::fire_and_forget _HideTrayIconRequested(); void _HideTrayIconRequested();
std::unique_ptr<TrayIcon> _trayIcon; std::unique_ptr<TrayIcon> _trayIcon;
winrt::event_token _ReAddTrayIconToken; winrt::event_token _ReAddTrayIconToken;
winrt::event_token _TrayIconPressedToken; winrt::event_token _TrayIconPressedToken;