@@ -18,12 +18,16 @@ static constexpr char kFailedError[] = "Failed";
1818static constexpr char kGetClipboardDataMethod [] = " Clipboard.getData" ;
1919static constexpr char kSetClipboardDataMethod [] = " Clipboard.setData" ;
2020static constexpr char kClipboardHasStringsMethod [] = " Clipboard.hasStrings" ;
21+ static constexpr char kPlaySoundMethod [] = " SystemSound.play" ;
2122static constexpr char kSystemNavigatorPopMethod [] = " SystemNavigator.pop" ;
2223static constexpr char kTextKey [] = " text" ;
2324static constexpr char kValueKey [] = " value" ;
2425
2526static constexpr char kTextPlainFormat [] = " text/plain" ;
2627
28+ static constexpr char kSoundTypeAlert [] = " SystemSoundType.alert" ;
29+ static constexpr char kSoundTypeClick [] = " SystemSoundType.click" ;
30+
2731struct _FlPlatformPlugin {
2832 GObject parent_instance;
2933
@@ -136,6 +140,29 @@ static FlMethodResponse* clipboard_has_strings_async(
136140 return nullptr ;
137141}
138142
143+ // Called when Flutter wants to play a sound.
144+ static FlMethodResponse* system_sound_play (FlPlatformPlugin* self,
145+ FlValue* args) {
146+ if (fl_value_get_type (args) != FL_VALUE_TYPE_STRING) {
147+ return FL_METHOD_RESPONSE (fl_method_error_response_new (
148+ kBadArgumentsError , " Expected string" , nullptr ));
149+ }
150+
151+ const gchar* type = fl_value_get_string (args);
152+ if (strcmp (type, kSoundTypeAlert ) == 0 ) {
153+ GdkDisplay* display = gdk_display_get_default ();
154+ if (display != nullptr ) {
155+ gdk_display_beep (display);
156+ }
157+ } else if (strcmp (type, kSoundTypeClick ) == 0 ) {
158+ // We don't make sounds for keyboard on desktops.
159+ } else {
160+ g_warning (" Ignoring unknown sound type %s in SystemSound.play.\n " , type);
161+ }
162+
163+ return FL_METHOD_RESPONSE (fl_method_not_implemented_response_new ());
164+ }
165+
139166// Called when Flutter wants to quit the application.
140167static FlMethodResponse* system_navigator_pop (FlPlatformPlugin* self) {
141168 GApplication* app = g_application_get_default ();
@@ -165,6 +192,8 @@ static void method_call_cb(FlMethodChannel* channel,
165192 response = clipboard_get_data_async (self, method_call);
166193 } else if (strcmp (method, kClipboardHasStringsMethod ) == 0 ) {
167194 response = clipboard_has_strings_async (self, method_call);
195+ } else if (strcmp (method, kPlaySoundMethod ) == 0 ) {
196+ response = system_sound_play (self, args);
168197 } else if (strcmp (method, kSystemNavigatorPopMethod ) == 0 ) {
169198 response = system_navigator_pop (self);
170199 } else {
0 commit comments