Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tray Icon PR followup #10938

Merged
4 commits merged into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -92,11 +92,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 @@ -324,6 +319,15 @@ void AppHost::AppTitleChanged(const winrt::Windows::Foundation::IInspectable& /*
// - <none>
void AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable& /*sender*/, const winrt::TerminalApp::LastTabClosedEventArgs& /*args*/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might hate me for asking . . . but does this fire when you use the [x] on the window? I know that we try to kill all the tabs, but this might only be a side effect... unless it is the main effect 😀

Copy link
Contributor Author

@leonMSFT leonMSFT Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does in fact go off on the X button 🙂

{
if (_windowManager.IsMonarch() && _trayIcon)
{
_DestroyTrayIcon();
}
else if (_window->IsQuakeWindow())
{
_HideTrayIconRequested();
}

_window->Close();
}

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. Otherwise I'd approve this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this was originally removed as part of this defapp bug fix #10823, and my bad merge left it in 😥. In short, the fix made it so that instead of making the monarch receive default terminal handoffs by default, the monarch should first figure out which peasant (or itself) should handle a default terminal handoff and tell that window to receive the connection.


if (_windowManager.DoesQuakeWindowExist() ||
_window->IsQuakeWindow() ||
(_logic.GetAlwaysShowTrayIcon() || _logic.GetMinimizeToTray()))
Expand Down Expand Up @@ -1055,11 +1056,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 @@ -1074,11 +1074,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 @@ -86,8 +86,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