Skip to content

Commit 12bd020

Browse files
committed
Add bringAppToFront param to popUpContextMenu method
1 parent 5b04acc commit 12bd020

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:mostly_reasonable_lints/flutter.yaml
1+
include: package:mostly_reasonable_lints/analysis_options.yaml

packages/tray_manager/example/lib/pages/home.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class _HomePageState extends State<HomePage> with TrayListener {
260260
trailing: Row(
261261
mainAxisSize: MainAxisSize.min,
262262
children: [
263-
Text('Should bring app to foreground'),
263+
const Text('Should bring app to foreground'),
264264
Switch(
265265
value: bringToForeground,
266266
onChanged: (value) {
@@ -270,8 +270,9 @@ class _HomePageState extends State<HomePage> with TrayListener {
270270
],
271271
),
272272
onTap: () async {
273-
await trayManager
274-
.popUpContextMenu(shouldForegroundOnContextMenu.value);
273+
await trayManager.popUpContextMenu(
274+
bringAppToFront: shouldForegroundOnContextMenu.value,
275+
);
275276
},
276277
);
277278
},
@@ -309,7 +310,9 @@ class _HomePageState extends State<HomePage> with TrayListener {
309310
if (kDebugMode) {
310311
print('onTrayIconMouseDown');
311312
}
312-
trayManager.popUpContextMenu(shouldForegroundOnContextMenu.value);
313+
trayManager.popUpContextMenu(
314+
bringAppToFront: shouldForegroundOnContextMenu.value,
315+
);
313316
}
314317

315318
@override

packages/tray_manager/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
18-
mostly_reasonable_lints: ^0.1.1
18+
mostly_reasonable_lints: ^0.1.2
1919

2020
flutter:
2121
uses-material-design: true

packages/tray_manager/lib/src/tray_manager.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,12 @@ class TrayManager {
183183
await _channel.invokeMethod('setContextMenu', arguments);
184184
}
185185

186-
/// Pops up the context menu of the tray icon and can foreground the app if `true` is passed as an argument.
187-
Future<void> popUpContextMenu([bool bringAppToForeground = false]) async {
188-
if (bringAppToForeground) {
189-
_popUpContextMenuAndForegroundApp();
190-
} else {
191-
_popUpContextMenuAndNotForegroundApp();
192-
}
193-
}
194-
195-
// Pops up the context menu of the tray icon and do not bring app to the foreground.
196-
Future<void> _popUpContextMenuAndNotForegroundApp() async {
197-
await _channel.invokeMethod('popUpContextMenuAndNotForegroundApp');
198-
}
199-
200-
// Pops up the context menu of the tray icon and bring the app to the foreground.
201-
Future<void> _popUpContextMenuAndForegroundApp() async {
202-
await _channel.invokeMethod('popUpContextMenuAndForegroundApp');
186+
/// Pops up the context menu of the tray icon.
187+
Future<void> popUpContextMenu({bool bringAppToFront = false}) async {
188+
final Map<String, dynamic> arguments = {
189+
'bringAppToFront': bringAppToFront,
190+
};
191+
await _channel.invokeMethod('popUpContextMenu', arguments);
203192
}
204193

205194
/// The bounds of this tray icon.

packages/tray_manager/windows/tray_manager_plugin.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ 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,
80-
bool bringAppToFront);
79+
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
8180
void TrayManagerPlugin::GetBounds(
8281
const flutter::MethodCall<flutter::EncodableValue>& method_call,
8382
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
@@ -286,8 +285,13 @@ void TrayManagerPlugin::SetContextMenu(
286285

287286
void TrayManagerPlugin::PopUpContextMenu(
288287
const flutter::MethodCall<flutter::EncodableValue>& method_call,
289-
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
290-
bool bringAppToFront) {
288+
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
289+
const flutter::EncodableMap& args =
290+
std::get<flutter::EncodableMap>(*method_call.arguments());
291+
292+
bool bringAppToFront =
293+
std::get<bool>(args.at(flutter::EncodableValue("bringAppToFront")));
294+
291295
HWND hWnd = GetMainWindow();
292296

293297
double x, y;
@@ -354,12 +358,8 @@ void TrayManagerPlugin::HandleMethodCall(
354358
SetToolTip(method_call, std::move(result));
355359
} else if (method_call.method_name().compare("setContextMenu") == 0) {
356360
SetContextMenu(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);
361+
} else if (method_call.method_name().compare("popUpContextMenu") == 0) {
362+
PopUpContextMenu(method_call, std::move(result));
363363
} else if (method_call.method_name().compare("getBounds") == 0) {
364364
GetBounds(method_call, std::move(result));
365365
} else {

0 commit comments

Comments
 (0)