From 1be09fac9ba41f57f5f158fcb17b12f4b71cac79 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 20 Apr 2022 09:54:36 -0700 Subject: [PATCH] Add Menu.isPluginAvailable to allow query of whether menus are available on the platform. (flutter/engine#32795) Added a "Menu.isPluginAvailable" call to allow the framework to query whether a plugin for creating platform menus is available on the current platform. This will allow the framework MenuBar.adaptive constructor to determine, based on the availability on the platform of the plugin, whether or not to render platform menus. This replaces the old way, which was just to hard code which platforms support it (i.e. just macOS), but that won't work well if someone adds a plugin that supports a particular platform that isn't macOS. --- .../darwin/macos/framework/Source/FlutterMenuPlugin.mm | 5 ++++- .../macos/framework/Source/FlutterMenuPluginTest.mm | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm index 80a9c26b6f..b9ba7fd4bd 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm @@ -12,6 +12,7 @@ // Channel constants static NSString* const kChannelName = @"flutter/menu"; +static NSString* const kIsPluginAvailableMethod = @"Menu.isPluginAvailable"; static NSString* const kMenuSetMenusMethod = @"Menu.setMenus"; static NSString* const kMenuSelectedCallbackMethod = @"Menu.selectedCallback"; static NSString* const kMenuOpenedMethod = @"Menu.opened"; @@ -377,7 +378,9 @@ static NSEventModifierFlags KeyEquivalentModifierMaskForModifiers(NSNumber* modi } - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([call.method isEqualToString:kMenuSetMenusMethod]) { + if ([call.method isEqualToString:kIsPluginAvailableMethod]) { + result(@YES); + } else if ([call.method isEqualToString:kMenuSetMenusMethod]) { NSDictionary* menus = call.arguments; [self setMenus:menus]; result(nil); diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm index a84168205d..b3a87e1040 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm @@ -106,6 +106,15 @@ ], }; + __block id available = @NO; + [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.isPluginAvailable" + arguments:nil] + result:^(id _Nullable result) { + available = result; + }]; + + EXPECT_TRUE(available); + [plugin handleMethodCall:[FlutterMethodCall methodCallWithMethodName:@"Menu.setMenus" arguments:testMenus] result:^(id _Nullable result){