From 1cf094e38b695d480574bd07161933da6c859331 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 20 May 2019 16:15:58 -0400 Subject: [PATCH] Macos systemnavigator pop (flutter/engine#9019) Adds the flutter/platform channel to the macOS shell, and implements SystemNavigator.pop. Other methods from this channel will be implement in the future. macOS part of flutter/flutter#30713 --- .../framework/Source/FLEViewController.mm | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm index 29bf82d377..dd7f9379f5 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FLEViewController.mm @@ -101,6 +101,11 @@ static const int kDefaultWindowFramebuffer = 0; */ - (void)onSettingsChanged:(NSNotification*)notification; +/** + * Handles messages received from the Flutter engine on the _*Channel channels. + */ +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result; + @end #pragma mark - Static methods provided to engine configuration @@ -194,6 +199,9 @@ static bool HeadlessOnMakeResourceCurrent(FLEViewController* controller) { // A message channel for sending user settings to the flutter engine. FlutterBasicMessageChannel* _settingsChannel; + + // A method channel for miscellaneous platform functionality. + FlutterMethodChannel* _platformChannel; } @dynamic view; @@ -316,6 +324,14 @@ static void CommonInit(FLEViewController* controller) { [FlutterBasicMessageChannel messageChannelWithName:@"flutter/settings" binaryMessenger:self codec:[FlutterJSONMessageCodec sharedInstance]]; + _platformChannel = + [FlutterMethodChannel methodChannelWithName:@"flutter/platform" + binaryMessenger:self + codec:[FlutterJSONMethodCodec sharedInstance]]; + __weak FLEViewController* weakSelf = self; + [_platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + [weakSelf handleMethodCall:call result:result]; + }]; } - (BOOL)launchEngineInternalWithAssetsPath:(NSURL*)assets @@ -515,6 +531,15 @@ static void CommonInit(FLEViewController* controller) { [self onSettingsChanged:nil]; } +- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + if ([call.method isEqualToString:@"SystemNavigator.pop"]) { + [NSApp terminate:self]; + result(nil); + } else { + result(FlutterMethodNotImplemented); + } +} + #pragma mark - FLEReshapeListener /**