Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow immediate MacOS notifications #16060

Merged
merged 4 commits into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion atom/browser/api/atom_api_system_preferences.h
Expand Up @@ -68,7 +68,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
base::Callback<void(const std::string&, const base::DictionaryValue&)>;

void PostNotification(const std::string& name,
const base::DictionaryValue& user_info);
const base::DictionaryValue& user_info,
mate::Arguments* args);
int SubscribeNotification(const std::string& name,
const NotificationCallback& callback);
void UnsubscribeNotification(int id);
Expand Down
50 changes: 21 additions & 29 deletions atom/browser/api/atom_api_system_preferences_mac.mm
Expand Up @@ -106,10 +106,18 @@ AVMediaType ParseMediaType(const std::string& media_type) {

} // namespace

void SystemPreferences::PostNotification(
const std::string& name,
const base::DictionaryValue& user_info) {
DoPostNotification(name, user_info, kNSDistributedNotificationCenter);
codebytere marked this conversation as resolved.
Show resolved Hide resolved
void SystemPreferences::PostNotification(const std::string& name,
const base::DictionaryValue& user_info,
mate::Arguments* args) {
bool immediate = false;
args->GetNext(&immediate);

NSDistributedNotificationCenter* center =
[NSDistributedNotificationCenter defaultCenter];
[center postNotificationName:base::SysUTF8ToNSString(name)
object:nil
userInfo:DictionaryValueToNSDictionary(user_info)
deliverImmediately:immediate];
}

int SystemPreferences::SubscribeNotification(
Expand All @@ -126,7 +134,10 @@ AVMediaType ParseMediaType(const std::string& media_type) {
void SystemPreferences::PostLocalNotification(
const std::string& name,
const base::DictionaryValue& user_info) {
DoPostNotification(name, user_info, kNSNotificationCenter);
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center postNotificationName:base::SysUTF8ToNSString(name)
object:nil
userInfo:DictionaryValueToNSDictionary(user_info)];
}

int SystemPreferences::SubscribeLocalNotification(
Expand All @@ -142,7 +153,11 @@ AVMediaType ParseMediaType(const std::string& media_type) {
void SystemPreferences::PostWorkspaceNotification(
const std::string& name,
const base::DictionaryValue& user_info) {
DoPostNotification(name, user_info, kNSWorkspaceNotificationCenter);
NSNotificationCenter* center =
[[NSWorkspace sharedWorkspace] notificationCenter];
[center postNotificationName:base::SysUTF8ToNSString(name)
object:nil
userInfo:DictionaryValueToNSDictionary(user_info)];
}

int SystemPreferences::SubscribeWorkspaceNotification(
Expand All @@ -156,29 +171,6 @@ AVMediaType ParseMediaType(const std::string& media_type) {
DoUnsubscribeNotification(request_id, kNSWorkspaceNotificationCenter);
}

void SystemPreferences::DoPostNotification(
const std::string& name,
const base::DictionaryValue& user_info,
NotificationCenterKind kind) {
NSNotificationCenter* center;
switch (kind) {
case kNSDistributedNotificationCenter:
center = [NSDistributedNotificationCenter defaultCenter];
break;
case kNSNotificationCenter:
center = [NSNotificationCenter defaultCenter];
break;
case kNSWorkspaceNotificationCenter:
center = [[NSWorkspace sharedWorkspace] notificationCenter];
break;
default:
break;
}
[center postNotificationName:base::SysUTF8ToNSString(name)
object:nil
userInfo:DictionaryValueToNSDictionary(user_info)];
}

codebytere marked this conversation as resolved.
Show resolved Hide resolved
int SystemPreferences::DoSubscribeNotification(
const std::string& name,
const NotificationCallback& callback,
Expand Down
3 changes: 2 additions & 1 deletion docs/api/system-preferences.md
Expand Up @@ -59,10 +59,11 @@ Returns `Boolean` - Whether the system is in Dark Mode.

Returns `Boolean` - Whether the Swipe between pages setting is on.

### `systemPreferences.postNotification(event, userInfo)` _macOS_
### `systemPreferences.postNotification(event, userInfo[, deliverImmediately])` _macOS_

* `event` String
* `userInfo` Object
* `deliverImmediately` Boolean (optional) - `true` to post notifications immediately regardless of whether or not the subscribing app is active or not.
codebytere marked this conversation as resolved.
Show resolved Hide resolved

Posts `event` as native notifications of macOS. The `userInfo` is an Object
that contains the user information dictionary sent along with the notification.
Expand Down