Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 48f9088

Browse files
authored
Add support for playing alert sound on MacOS (#19970)
flutter/flutter#62143
1 parent 50a0767 commit 48f9088

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ - (void)dispatchKeyEvent:(NSEvent*)event ofType:(NSString*)type;
146146
- (void)sendInitialSettings;
147147

148148
/**
149-
* Responsds to updates in the user settings and passes this data to the engine.
149+
* Responds to updates in the user settings and passes this data to the engine.
150150
*/
151151
- (void)onSettingsChanged:(NSNotification*)notification;
152152

@@ -155,6 +155,12 @@ - (void)onSettingsChanged:(NSNotification*)notification;
155155
*/
156156
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
157157

158+
/**
159+
* Plays a system sound. |soundType| specifies which system sound to play. Valid
160+
* values can be found in the SystemSoundType enum in the services SDK package.
161+
*/
162+
- (void)playSystemSound:(NSString*)soundType;
163+
158164
/**
159165
* Reads the data from the clipboard. |format| specifies the media type of the
160166
* data to obtain.
@@ -490,6 +496,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
490496
if ([call.method isEqualToString:@"SystemNavigator.pop"]) {
491497
[NSApp terminate:self];
492498
result(nil);
499+
} else if ([call.method isEqualToString:@"SystemSound.play"]) {
500+
[self playSystemSound:call.arguments];
501+
result(nil);
493502
} else if ([call.method isEqualToString:@"Clipboard.getData"]) {
494503
result([self getClipboardData:call.arguments]);
495504
} else if ([call.method isEqualToString:@"Clipboard.setData"]) {
@@ -500,6 +509,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
500509
}
501510
}
502511

512+
- (void)playSystemSound:(NSString*)soundType {
513+
if ([soundType isEqualToString:@"SystemSoundType.alert"]) {
514+
NSBeep();
515+
}
516+
}
517+
503518
- (NSDictionary*)getClipboardData:(NSString*)format {
504519
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
505520
if ([format isEqualToString:@(kTextPlainFormat)]) {

0 commit comments

Comments
 (0)