-
Notifications
You must be signed in to change notification settings - Fork 594
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
Add extension for Do Not Disturb Mode (and underlay User Preference extension) #1706
Conversation
@@ -0,0 +1,17 @@ | |||
hs.notdisturbmode = require("hs.notdisturbmode") | |||
|
|||
function testNotDisturbMode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W111) setting non-standard global variable 'testNotDisturbMode'
local isOn = hs.notdisturbmode.status() | ||
|
||
hs.notdisturbmode.off() | ||
assertIsEqual(false, hs.notdisturbmode.status()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'assertIsEqual'
assertIsEqual(false, hs.notdisturbmode.status()) | ||
|
||
hs.notdisturbmode.on() | ||
assertIsEqual(true, hs.notdisturbmode.status()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'assertIsEqual'
hs.notdisturbmode.off() | ||
end | ||
|
||
return success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'success'
@@ -0,0 +1,25 @@ | |||
hs.userpreference = require("hs.userpreference") | |||
|
|||
function testUserPreference() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W111) setting non-standard global variable 'testUserPreference'
|
||
hs.userpreference.set("test_user_preference", false, "com.hammerspoon.hammerspoon") | ||
val = hs.userpreference.get("test_user_preference", "com.hammerspoon.hammerspoon") | ||
assertIsEqual(val, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'assertIsEqual'
|
||
hs.userpreference.set("test_user_preference", "aaa", "com.hammerspoon.hammerspoon") | ||
val = hs.userpreference.get("test_user_preference", "com.hammerspoon.hammerspoon") | ||
assertIsEqual(val, "aaa") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'assertIsEqual'
hs.userpreference.set("test_user_preference", "aaa", "com.hammerspoon.hammerspoon") | ||
val = hs.userpreference.get("test_user_preference", "com.hammerspoon.hammerspoon") | ||
assertIsEqual(val, "aaa") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W611) line contains only whitespace
|
||
hs.userpreference.set("test_user_preference", nil, "com.hammerspoon.hammerspoon") | ||
val = hs.userpreference.get("test_user_preference", "com.hammerspoon.hammerspoon") | ||
assertIsEqual(val, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'assertIsEqual'
|
||
hs.userpreference.sync("com.hammerspoon.hammerspoon") | ||
|
||
return success() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W113) accessing undefined variable 'success'
Amazing work @waynezhang! My only question is, how does See issues:
|
(will report some thoughts later, just wanted to quickly drop in to say ignore the sticker CI comments, it doesn't know what it's talking about) |
@cmsj - I've just made a tweak in #1707 which I think will solve the @stickler-ci errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff, but I think I'd like to change the names - notdisturbmode
doesn't match up with the English name for the macOS feature, so maybe it should be hs.donotdisturb
?
Also I think hs.userpreference
would be better as hs.userpreferences
extensions/userpreference/internal.m
Outdated
kCFPreferencesCurrentUser, | ||
kCFPreferencesCurrentHost); | ||
if (ref != nil) { | ||
[skin pushNSObject:(__bridge NSObject *)ref]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing, but we tend to use __bridge_transfer
rather than __bridge
and CFAutorelease()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at c043e28
@waynezhang Would love to see this merged so I can control DND from the keyboard. Anything I can do to help? |
@dbalatero Sorry for late reply. I'm gonna fix this recently when I have time. The tasks left will be:
|
@waynezhang any updates/thoughts around resolving these items so @cmsj can merge? |
I'd love to get @asmagill's thoughts in regards to |
when will this merged? |
@cmsj & @asmagill - In the interest of merging in the code to solve the original issue in this pull request, I wonder if it's worth just removing |
Sorry I didn't look at this earlier... @latenitefilms since you are the only one I know has used hs._asm.cfpreferences much beyond my initial tests, what are your thoughts on it? What does it need/lack before being submitted for inclusion? It looks like userpreferences here is a subset, so we could create a wrapper (or even rename mine) if the name seems to make more sense... and since I do note in cfpreferences's limitations that it can't access the "AnyUser" key for writing, renaming mine might actually be worthwhile... the label "cfpreferences" is just a nod to the underlying foundation library being used and wouldn't make sense to someone not somewhat familiar with macOS programming... |
Currently I'm using a mixture of From memory, the reason we're using There were also cases where Ideally, I'd love to drop I think renaming Note to self - these plugins use
These plugins use
Also, note to self, that ----------------------------------------------------------------------------------
-- TODO: This code currently doesn't work with hs.plist, which is why we're still
-- using cp.plist. Will re-investigate once we have hs.plist.readString()
---------------------------------------------------------------------------------- Will do some experimenting over the coming days to work out what use-cases |
@asmagill - Re-looking at this issue, the For example: > cfpreferences = require("hs._asm.cfpreferences")
> cfpreferences.getValue("doNotDisturb", "com.apple.notificationcenterui")
false
> cfpreferences.getValue("doNotDisturb", "com.apple.notificationcenterui")
true Given that, I'd suggest we try and merge As discussed above, I think renaming |
Sorry for leaving this issue untouched for so long a time. @latenitefilms Thanks for the advice. I'm happy to do the migration to |
@@ -0,0 +1,17 @@ | |||
hs.donotdisturb = require("hs.donotdisturb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W122) setting read-only field 'donotdisturb' of global 'hs'
@@ -0,0 +1,25 @@ | |||
hs.userpreferences = require("hs.userpreferences") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W122) setting read-only field 'userpreferences' of global 'hs'
hs.userpreferences = require("hs.userpreferences") | ||
|
||
function testUserPreferences() | ||
local val = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W311) value assigned to variable 'val' is overwritten on line 7 before use
hs.userpreferences.set("test_user_preferences", "aaa", "com.hammerspoon.hammerspoon") | ||
val = hs.userpreferences.get("test_user_preferences", "com.hammerspoon.hammerspoon") | ||
assertIsEqual(val, "aaa") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(W611) line contains only whitespace
I've renamed it to |
Rename hs.userpreference to hs.userpreferences
Nothing to add here but excited to see this 👍 |
I want to leave this for 0.9.80 -- I plan to work on the merging of cfpreferences, preferences, settings, etc. after getting 0.9.79 out the door and this would be a perfect fit at that time. |
I'm very interested in this feature. Do you have a rough timeline? |
@cmsj & @asmagill - I've said this before, but just to suggest again... in the interest of merging in the code to solve the original issue in this pull request, I wonder if it's worth just removing |
I think in Mojave/Catalina, DND was turned on via user preferences: https://github.com/dbalatero/dotfiles/blob/master/hammerspoon/pairing-mode.lua#L32-L44 However, the only way I was able to enable it on Big Sur is via UI automation + AppleScript: https://github.com/dbalatero/dotfiles/blob/master/hammerspoon/pairing-mode.lua#L9-L30 Apple seems to have dropped the user preferences way in favor of something more custom and opaque. Just a heads up that maintaining a DND module might be a moving target in the future! (I wish Apple would just ship a CLI program to toggle DND, honestly) |
I'd love this feature; for the time being I'm using this method: https://spinscale.de/posts/2020-10-30-using-hammerspoon-do-not-disturb-screen-sharing-zoom.html |
For anyone else thinking about this in the meantime: if you are on Big Sur you can trigger a shortcut using For now… this works really well for me, and I'm ok. |
Add a new extension to control Do Not Disturb Mode
And because it's depended on user preference, I also isolated it as a standalone extension