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

Respect "Do Not Disturb" on macOS #760

Merged
merged 11 commits into from
Oct 8, 2019

Conversation

whitecrownclown
Copy link
Contributor

@whitecrownclown whitecrownclown commented Feb 8, 2019

Fixes #496

@sindresorhus
Copy link
Owner

We can't use this module as it uses native Node.js add-ons, which mean we'll no longer be able to build all the binaries on one system.

  • Disables bounce and messenger sound notification

Should it disable the Dock badge too?

  • Only works on init/refresh, if status changes while the app is on, it will not update. Any clue if and how can this be done?

You can listen to the com.apple.notificationcenterui.dndprefs_changed distributed Apple event with https://electronjs.org/docs/api/system-preferences#systempreferencessubscribenotificationevent-callback-macos

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 18, 2019

For macOS, you might not even need a module for this. I think you can just read the doNotDisturb key from the UserDefaults com.apple.notificationcenterui. (See Electron docs on how to read user defaults).

https://github.com/felixrieseberg/macos-notification-state/blob/07b4c6488252d45835201ce74500df8b806c5cd3/lib/do-not-disturb.mm#L4

@whitecrownclown
Copy link
Contributor Author

@sindresorhus I've been trying to get the doNotDisturb user default using Electron's API but i'm always gettings false, which also seems to be the case for any key that doesn't exist.

systemPreferences.getUserDefault('doNotDisturb', 'boolean');

Also my attempt to get the event didn't work, not getting any callback :

systemPreferences.subscribeNotification('com.apple.notificationcenterui.dndprefs_changed', callback)

@sindresorhus
Copy link
Owner

I've been trying to get the doNotDisturb user default using Electron's API but i'm always gettings false, which also seems to be the case for any key that doesn't exist.

You're not specifying the suite name, which is not surprising, since it's not currently possible in Electron. I've opened an issue about it: electron/electron#17031

systemPreferences.subscribeNotification('com.apple.notificationcenterui.dndprefs_changed', callback)

I have no idea why this is not working though...

@sindresorhus
Copy link
Owner

Seems it would be easiest to just go with https://github.com/sindresorhus/do-not-disturb and polling for now.

Ideally, the do-not-disturb package should have a change event though: sindresorhus/do-not-disturb#6

@felixfbecker
Copy link
Contributor

  • Only works on init/refresh, if status changes while the app is on, it will not update. Any clue if and how can this be done?

If that's true I would rather not have this feature...

@sindresorhus
Copy link
Owner

@felixfbecker Polling is an option, or implementing sindresorhus/do-not-disturb#6.

@whitecrownclown
Copy link
Contributor Author

@sindresorhus I can take on the polling approach. I'm not sure how to start on sindresorhus/do-not-disturb#6

@whitecrownclown whitecrownclown changed the title Implement doNotDisturb for mac&windows Implement doNotDisturb for macos Feb 27, 2019
@whitecrownclown
Copy link
Contributor Author

@sindresorhus I've implemented a polling solution. Would you mind having a look over it for any feedback? Thanks!

package.json Outdated Show resolved Hide resolved
source/browser.ts Outdated Show resolved Hide resolved
@whitecrownclown
Copy link
Contributor Author

Waiting on sindresorhus/do-not-disturb#8 to be merged.

@whitecrownclown whitecrownclown changed the title Implement doNotDisturb for macos [Feature] Implement doNotDisturb for macos Jun 20, 2019
@sindresorhus
Copy link
Owner

@whitecrownclown whitecrownclown changed the title [Feature] Implement doNotDisturb for macos WIP: Implement doNotDisturb for macos Jun 30, 2019
@whitecrownclown whitecrownclown force-pushed the feat/do-not-disturb branch 2 times, most recently from 5fb7530 to e33e501 Compare July 1, 2019 19:53
@whitecrownclown whitecrownclown changed the title WIP: Implement doNotDisturb for macos [Feature] Implement doNotDisturb for macos Jul 1, 2019
@sindresorhus sindresorhus changed the title [Feature] Implement doNotDisturb for macos Respect "Do Not Disturb" on macOS Jul 12, 2019
@sindresorhus
Copy link
Owner

Can you mention it in the readme highlights that it respects "Do Not Disturb" on macOS?

@sindresorhus
Copy link
Owner

If I have "Sounds" disabled, then turn on "Do Not Disturb" and then turn it off again, "Sounds" is then enabled. It should instead correctly revert back to the state before "Do Not Disturb".

@sindresorhus
Copy link
Owner

Dock badge shows even when "Do Not Disturb" is enabled.

Daniel Andrei and others added 3 commits August 12, 2019 01:19
Fix dock badge showing when DND is enabled
Revert to initial sounds value when toggling DND
@sindresorhus sindresorhus merged commit 88efe46 into sindresorhus:master Oct 8, 2019
@sindresorhus
Copy link
Owner

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect Do Not Disturb on macOS
3 participants