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
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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);
@@ -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);
This conversation was marked as resolved by codebytere

This comment has been minimized.

Copy link
@nornagon

nornagon Dec 14, 2018

Contributor

can we delete the NotificationCenterKind enum now?

This comment has been minimized.

Copy link
@codebytere

codebytere Dec 14, 2018

Author Member

no, we need it for DoSubscribeNotification and DoUnsubscribeNotification

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(
@@ -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(
@@ -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(
@@ -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)];
}

This conversation was marked as resolved by codebytere

This comment has been minimized.

Copy link
@ckerr

ckerr Dec 14, 2018

Member

This function declaration should be removed from atom_api_system_preferences.h too

int SystemPreferences::DoSubscribeNotification(
const std::string& name,
const NotificationCallback& callback,
@@ -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.
This conversation was marked as resolved by codebytere

This comment has been minimized.

Copy link
@nornagon

nornagon Dec 14, 2018

Contributor
Suggested change
* `deliverImmediately` Boolean (optional) - `true` to post notifications immediately regardless of whether or not the subscribing app is active or not.
* `deliverImmediately` Boolean (optional) - `true` to post notifications immediately regardless of whether or not the subscribing app is active or not. Defaults to `false`. See [NSDistributedNotificationCenter documentation](https://developer.apple.com/documentation/foundation/nsdistributednotificationcenter/1418360-postnotificationname) for details.

Posts `event` as native notifications of macOS. The `userInfo` is an Object
that contains the user information dictionary sent along with the notification.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.