feat: Set macOS notification close button title by sethlu · Pull Request #11654 · electron/electron · GitHub
Skip to content

feat: Set macOS notification close button title#11654

Merged
zcbenz merged 4 commits into
electron:masterfrom
sethlu:set-notification-close-button-text
Feb 15, 2018
Merged

feat: Set macOS notification close button title#11654
zcbenz merged 4 commits into
electron:masterfrom
sethlu:set-notification-close-button-text

Conversation

@sethlu

@sethlu sethlu commented Jan 16, 2018

Copy link
Copy Markdown
Contributor

🍎 This addition allows developers to set custom & localized title for macOS notifications.

Resolves: #11594


With the following config:

  • NSUserNotificationAlertStyle set to alert in Info.plist of the app bundle
  • Probably check if alerts are enabled for the app in System Preferences (not only banners, otherwise the close button won't show)

Using the following script:

// This doesn't produce a window...
// But should be enough to produce a native notification
const electron = require('electron')
electron.app.on('ready', function (event) {

  let n = new electron.Notification({
    title: 'Notification',
    closeButtonText: 'Dismiss 😀', // It does support some emoji
  })

  n.show()

})

Screenshot:

screen shot 2018-01-16 at 11 26 20 am

@sethlu sethlu self-assigned this Jan 16, 2018
@sethlu sethlu requested review from a team January 16, 2018 19:34
@sethlu sethlu changed the title [WIP] feat: Set macOS notification close button title feat: Set macOS notification close button title Jan 16, 2018
@sethlu sethlu force-pushed the set-notification-close-button-text branch from 767b3a0 to 6f2c60b Compare January 16, 2018 20:09
@codebytere

Copy link
Copy Markdown
Member

@alexeykuzmin alexeykuzmin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the whole feature be placed under the #if defined(OS_MACOSX) condition?

@alexeykuzmin

Copy link
Copy Markdown
Contributor
  let n = new electron.Notification({
    title: 'Notification',
    closeButtonText: 'Dismiss 😀', // It does support some emoji
  })

@sethlu Can you please add a test that n.closeButtonText value is equal to the provided text?
And another test when closeButtonText is set to an empty string.

@sethlu

sethlu commented Jan 18, 2018

Copy link
Copy Markdown
Contributor Author

@alexeykuzmin Thanks for reviewing! This change set introduces a new member to the existing NotificationOptions struct. On platforms other than macOS, this closeButtonText will not be checked while interacting with the system API calls. However, I could wrap some of the macOS-only properties for optimization? (This hasn't been done yet however, probably due to it being an experimental feature? On that I also can't seem to find the notifications under the spec folder?)

prototype->SetClassName(mate::StringToV8(isolate, "Notification"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.MakeDestroyable()
auto _(mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of a better way to do this while keeping the items in order?

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@sethlu

On platforms other than macOS, this closeButtonText will not be checked while interacting with the system API calls. However, I could wrap some of the macOS-only properties for optimization?

I wasn't thinking about optimization, but about explicitly saying "these parts of code are Mac-specific".

I also can't seem to find the notifications under the spec folder

You are more than welcome to create a new file )
You can skip .closeButtonText tests on all platforms other than Mac by calling this.skip() in a before hook of a describe.

@sethlu

sethlu commented Jan 18, 2018

Copy link
Copy Markdown
Contributor Author

@alexeykuzmin

I wasn't thinking about optimization, but about explicitly saying "these parts of code are Mac-specific".

Would cd01eec address this? The feature's intended for macOS; historical additions to the Notifications API aren't so sensitive with the platform settings?

You are more than welcome to create a new file )

I'll probably address that in a separate PR since the entire Notification submodule needs its tests--probably only checking if the values are passed correctly to the electron lib?

@alexeykuzmin

Copy link
Copy Markdown
Contributor

Would cd01eec address this?

Looks good to me, but I would like to have someone else to review this too.

@alexeykuzmin

Copy link
Copy Markdown
Contributor

You are more than welcome to create a new file )

I'll probably address that in a separate PR

I just means that we risk to get some stuff broken in the master )

@MarshallOfSound

Copy link
Copy Markdown
Member

Would cd01eec address this?

I think we should discuss this more, not sure that I like the idea of pulling out these properties of Notification to be just on macOS. For instance there are PR's / WIP's to implement actions / replies on Windows. I'm all for being clear on where features are noops / implemented but the OS specific parts of Notification are in brightray currently and I believe having two sets of OS split files (brightray and atom_api_notification) will make dev harder / more confusing rather than easier.

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requesting to discuss

@MarshallOfSound

Copy link
Copy Markdown
Member

To further explain my point above the atom_api_notification file could be considered a "proxy" for the internal brightray notification API. It shouldn't be aware what OS does what / supports rather just pass a complete NotificationOptions object to the API and let the OS specific stuff in brightray handle the options as they see fit 👍

@sethlu

sethlu commented Jan 21, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound That's a good point. I think it's probably better to have those options all available in NotificationOptions so different platform implementations could read the applicable entries.

@alexeykuzmin What do you think?

@alexeykuzmin

alexeykuzmin commented Jan 21, 2018

Copy link
Copy Markdown
Contributor

@MarshallOfSound @sethlu

the atom_api_notification file could be considered a "proxy" for the internal brightray notification API. It shouldn't be aware what OS does what / supports rather just pass a complete NotificationOptions object to the API and let the OS specific stuff in brightray handle the options as they see fit

atom_api_notification is a user-facing interface, and it should match the documentation.
brightray is an implementation behind that interface, probably platform dependent.
We can have some stuff implemented in brightray without an API available for users,
but we can't have an API without implementation. Like if some API method is not available on a certain platform, the method shouldn't be noop, it should not exist at all.

That's why I think that we should have OS checks in the atom_api_notification.
I don't really care if some methods will end up in a separate file or not.

@MarshallOfSound

Copy link
Copy Markdown
Member

Like if some API method is not available on a certain platform, the method shouldn't be noop, it should not exist at all.

This goes against how most of our current API's work afaik, OS specific getters and setters exist most of the time on all platforms but only take affect on some. This is so that you can write JS code for all platforms without doing platform checks. I.e. I as a user shouldn't have to do a if (process.platform === 'darwin') check just to see if I can get/set the hasReply property. We should make writing cross-platform as easy for users as possible (that's kind of our thing 😄 )

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@MarshallOfSound Maybe it's a good way to use API, if we have platform-specific properties, ok.

@sethlu sethlu force-pushed the set-notification-close-button-text branch from adb196a to 878c561 Compare January 22, 2018 18:50
@sethlu

sethlu commented Jan 22, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound @alexeykuzmin I've just reverted the platform-specific code changes.
Let me know how it looks.

@alexeykuzmin

Copy link
Copy Markdown
Contributor

@sethlu Looks good to me. Already approved.

@sethlu

sethlu commented Feb 7, 2018

Copy link
Copy Markdown
Contributor Author

@sethlu sethlu force-pushed the set-notification-close-button-text branch from 36703ac to 38d2845 Compare February 10, 2018 11:20

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@zcbenz zcbenz merged commit af92b04 into electron:master Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Ability to change close label in notifications (Mac)

5 participants