@@ -76,7 +76,8 @@ class TrayManagerPlugin : public flutter::Plugin {
7676 std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
7777 void TrayManagerPlugin::PopUpContextMenu (
7878 const flutter::MethodCall<flutter::EncodableValue>& method_call,
79- std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
79+ std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
80+ bool bringAppToFront);
8081 void TrayManagerPlugin::GetBounds (
8182 const flutter::MethodCall<flutter::EncodableValue>& method_call,
8283 std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
@@ -185,14 +186,12 @@ std::optional<LRESULT> TrayManagerPlugin::HandleWindowProc(HWND hWnd,
185186 } else if (message == WM_MYMESSAGE) {
186187 switch (lParam) {
187188 case WM_LBUTTONUP:
188- channel->InvokeMethod (
189- " onTrayIconMouseDown" ,
190- std::make_unique<flutter::EncodableValue>());
189+ channel->InvokeMethod (" onTrayIconMouseDown" ,
190+ std::make_unique<flutter::EncodableValue>());
191191 break ;
192192 case WM_RBUTTONUP:
193- channel->InvokeMethod (
194- " onTrayIconRightMouseDown" ,
195- std::make_unique<flutter::EncodableValue>());
193+ channel->InvokeMethod (" onTrayIconRightMouseDown" ,
194+ std::make_unique<flutter::EncodableValue>());
196195 break ;
197196 default :
198197 return DefWindowProc (hWnd, message, wParam, lParam);
@@ -287,7 +286,8 @@ void TrayManagerPlugin::SetContextMenu(
287286
288287void TrayManagerPlugin::PopUpContextMenu (
289288 const flutter::MethodCall<flutter::EncodableValue>& method_call,
290- std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
289+ std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
290+ bool bringAppToFront) {
291291 HWND hWnd = GetMainWindow ();
292292
293293 double x, y;
@@ -303,7 +303,9 @@ void TrayManagerPlugin::PopUpContextMenu(
303303 x = cursorPos.x ;
304304 y = cursorPos.y ;
305305
306- SetForegroundWindow (hWnd);
306+ if (bringAppToFront) {
307+ SetForegroundWindow (hWnd);
308+ }
307309 TrackPopupMenu (hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, static_cast <int >(x),
308310 static_cast <int >(y), 0 , hWnd, NULL );
309311 result->Success (flutter::EncodableValue (true ));
@@ -352,8 +354,12 @@ void TrayManagerPlugin::HandleMethodCall(
352354 SetToolTip (method_call, std::move (result));
353355 } else if (method_call.method_name ().compare (" setContextMenu" ) == 0 ) {
354356 SetContextMenu (method_call, std::move (result));
355- } else if (method_call.method_name ().compare (" popUpContextMenu" ) == 0 ) {
356- PopUpContextMenu (method_call, std::move (result));
357+ } else if (method_call.method_name ().compare (
358+ " popUpContextMenuAndNotForegroundApp" ) == 0 ) {
359+ PopUpContextMenu (method_call, std::move (result), false );
360+ } else if (method_call.method_name ().compare (
361+ " popUpContextMenuAndForegroundApp" ) == 0 ) {
362+ PopUpContextMenu (method_call, std::move (result), true );
357363 } else if (method_call.method_name ().compare (" getBounds" ) == 0 ) {
358364 GetBounds (method_call, std::move (result));
359365 } else {
0 commit comments