diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 76ac9a87da64..1baa04d8d8d0 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -82,13 +82,15 @@ that contains the user information dictionary sent along with the notification. * `callback` Function * `event` String * `userInfo` Object + * `object` String Returns `Number` - The ID of this subscription Subscribes to native notifications of macOS, `callback` will be called with `callback(event, userInfo)` when the corresponding `event` happens. The `userInfo` is an Object that contains the user information dictionary sent -along with the notification. +along with the notification. The `object` is the sender of the notification, +and only supports `NSString` values for now. The `id` of the subscriber is returned, which can be used to unsubscribe the `event`. @@ -107,6 +109,7 @@ example values of `event` are: * `callback` Function * `event` String * `userInfo` Object + * `object` String Returns `Number` - The ID of this subscription @@ -119,6 +122,7 @@ This is necessary for events such as `NSUserDefaultsDidChangeNotification`. * `callback` Function * `event` String * `userInfo` Object + * `object` String Same as `subscribeNotification`, but uses `NSWorkspace.sharedWorkspace.notificationCenter`. This is necessary for events such as `NSWorkspaceDidActivateApplicationNotification`. diff --git a/shell/browser/api/atom_api_system_preferences.h b/shell/browser/api/atom_api_system_preferences.h index 6f7c465adefa..6ceb3d88a8a8 100644 --- a/shell/browser/api/atom_api_system_preferences.h +++ b/shell/browser/api/atom_api_system_preferences.h @@ -67,7 +67,8 @@ class SystemPreferences : public mate::EventEmitter #elif defined(OS_MACOSX) using NotificationCallback = base::RepeatingCallback; + const base::DictionaryValue&, + const std::string&)>; void PostNotification(const std::string& name, const base::DictionaryValue& user_info, diff --git a/shell/browser/api/atom_api_system_preferences_mac.mm b/shell/browser/api/atom_api_system_preferences_mac.mm index 8cd5f7f19476..6a12d6455f6b 100644 --- a/shell/browser/api/atom_api_system_preferences_mac.mm +++ b/shell/browser/api/atom_api_system_preferences_mac.mm @@ -210,13 +210,22 @@ int SystemPreferences::DoSubscribeNotification( usingBlock:^(NSNotification* notification) { std::unique_ptr user_info = NSDictionaryToDictionaryValue(notification.userInfo); + + std::string object = ""; + if ([notification.object isKindOfClass:[NSString class]]) { + object = base::SysNSStringToUTF8(notification.object); + } + if (user_info) { copied_callback.Run( - base::SysNSStringToUTF8(notification.name), *user_info); + base::SysNSStringToUTF8(notification.name), + *user_info, + object); } else { copied_callback.Run( base::SysNSStringToUTF8(notification.name), - base::DictionaryValue()); + base::DictionaryValue(), + object); } }]; return request_id;