Skip to content

Fix monterey detect DND status#27

Merged
felixrieseberg merged 7 commits intofelixrieseberg:masterfrom
nbashkankov:fix-monterey-detect
Feb 8, 2022
Merged

Fix monterey detect DND status#27
felixrieseberg merged 7 commits intofelixrieseberg:masterfrom
nbashkankov:fix-monterey-detect

Conversation

@nbashkankov
Copy link
Contributor

@nbashkankov nbashkankov commented Oct 29, 2021

Hello,
@felixrieseberg @MarshallOfSound

com.apple.ncprefs approach no longer works for Monterey.

And actually there could be issue - if you updated to Monterey with DND turned on - ncprefs will still have userPrefs with DND enabled value (MacOS even not erased it on update).

During some investigation i found that there is "~/Library/DoNotDisturb/DB/", which contains all DND setting state.
It updates immediately after manual/scheduled change of DND status. So, for Monterey i added logic to read it instead of ncprefs.

Probably its not proper fix, but anyway it works.
Feel free to provide better solution.

@felixrieseberg
Copy link
Owner

Thanks for this work! Do you happen to know if this works for older versions, too? I'd hate to break this library on older macOS versions.

@nbashkankov
Copy link
Contributor Author

Package already worked for BigSur and prior versions. My changes just added support for Monterey.
I did check BigSur with Intel - works as before, and Monterey with M1 - also works

@nbashkankov
Copy link
Contributor Author

@felixrieseberg do you still have concerns preventing to merge this?

@Fiser12
Copy link

Fiser12 commented Nov 22, 2021

I tested it on BigSur and Monterrey. On ARM and on Intel. It was working like a charm.

@nbashkankov
Copy link
Contributor Author

nbashkankov commented Jan 19, 2022

@felixrieseberg @MarshallOfSound - friendly reminder - please take a look

  • can we get this changes released?

@felixrieseberg felixrieseberg merged commit 1de0bf4 into felixrieseberg:master Feb 8, 2022
@felixrieseberg
Copy link
Owner

Sorry for the delay - and thanks for the email!

@nbashkankov
Copy link
Contributor Author

fixes issue #26

@hovancik
Copy link

could this be bumped in electron-notification-state as well? felixrieseberg/electron-notification-state#7

@schetle
Copy link

schetle commented Aug 11, 2022

I thought I would add that this does not work in Sandboxed apps, where they do not get direct access to ~/Library.

In a sandboxed app, this results in errors:
Failed to open °E¯ˇ, error Error Domain=NSCocoaErrorDomain Code=260 "The file “Assertions.json” couldn’t be opened because there is no such file." UserInfo={NSFilePath=<PathToLibrary>/Containers/<CFBundleIdentifier>/Data/Library/DoNotDisturb/DB/Assertions.json, NSUnderlyingError=0x600003f67c60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

The "correct" way to do this is to:

  1. Link with the "Intents" Framework
  2. Include the "com.apple.developer.usernotifications.communication" entitlement
  3. Request Authorization via ([[INFocusStatusCenter defaultCenter] requestAuthorizationWithCompletionHandler:...])
  4. Upon the user accepting the request, get the status [INFocusStatusCenter defaultCenter].focusStatus

Example:

[[INFocusStatusCenter defaultCenter] requestAuthorizationWithCompletionHandler:^(INFocusStatusAuthorizationStatus status) {
        if (status == INFocusStatusAuthorizationStatusAuthorized) {
            NSLog(@"Current Focus - isFocused?: %@", ([[INFocusStatusCenter defaultCenter].focusStatus isFocused] ? @"Yes!" : @"No!"));
        }
 }];

Which results in a request to query the status, and then a console output of:
2022-08-11 16:19:43.633072-0500 StatusTest[99579:687478] Current Focus - isFocused?: Yes!

I don't have time at the moment to implement this in macos-notification-state, but hopefully in the future I will free up to do so.

@tboulis
Copy link

tboulis commented Jan 19, 2023

@schetle It seems that the com.apple.developer.usernotifications.communication is not listed under the entitlements available when Sandbox is on:
https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html

@schetle
Copy link

schetle commented Jan 19, 2023

@tboulis It was long enough ago that it's likely changed. You can review the documentation for the INFocusStatusCenter to determine what is required as of today.

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.

6 participants