From f13417b37a430b35fb9c05783112275b6a379783 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Thu, 23 Jul 2020 14:00:13 -0700 Subject: [PATCH] Add support for playing alert sound on MacOS (flutter/engine#19970) flutter/flutter#62143 --- .../framework/Source/FlutterViewController.mm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 7ef1636ace..bb928da63a 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -146,7 +146,7 @@ struct KeyboardState { - (void)sendInitialSettings; /** - * Responsds to updates in the user settings and passes this data to the engine. + * Responds to updates in the user settings and passes this data to the engine. */ - (void)onSettingsChanged:(NSNotification*)notification; @@ -155,6 +155,12 @@ struct KeyboardState { */ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result; +/** + * Plays a system sound. |soundType| specifies which system sound to play. Valid + * values can be found in the SystemSoundType enum in the services SDK package. + */ +- (void)playSystemSound:(NSString*)soundType; + /** * Reads the data from the clipboard. |format| specifies the media type of the * data to obtain. @@ -490,6 +496,9 @@ static void CommonInit(FlutterViewController* controller) { if ([call.method isEqualToString:@"SystemNavigator.pop"]) { [NSApp terminate:self]; result(nil); + } else if ([call.method isEqualToString:@"SystemSound.play"]) { + [self playSystemSound:call.arguments]; + result(nil); } else if ([call.method isEqualToString:@"Clipboard.getData"]) { result([self getClipboardData:call.arguments]); } else if ([call.method isEqualToString:@"Clipboard.setData"]) { @@ -500,6 +509,12 @@ static void CommonInit(FlutterViewController* controller) { } } +- (void)playSystemSound:(NSString*)soundType { + if ([soundType isEqualToString:@"SystemSoundType.alert"]) { + NSBeep(); + } +} + - (NSDictionary*)getClipboardData:(NSString*)format { NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; if ([format isEqualToString:@(kTextPlainFormat)]) {