hs.hotkey: guard bind() against a callback-less no-op hotkey - #207
Merged
Merged
Conversation
bind() enables the hotkey immediately, so binding with no function callbacks (e.g. bind(mods, key, null, null)) would silently claim the key combination and do nothing. Guard against it and return null, while keeping create() permissive so callers can build a hotkey and assign callbacks later. Update the two bindSpec message tests to pass a callback (a message-only hotkey never fires its callback, so it is now correctly rejected), and add tests for the new guard and for create()'s deferred-assignment path. Docs (api.json/HTML/TS) intentionally not regenerated here; the updated bind() docstring flags that a docs refresh is still owed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR prevents
Confidence Score: 4/5The implementation appears safe to merge, with a non-blocking documentation refresh needed to expose the new API constraint. The guard follows existing callback validation conventions, bindSpec safely handles a null result, and tests cover both rejection by bind and continued permissiveness in create; only the checked-in API documentation remains inconsistent. Files Needing Attention: Hammerspoon 2/Modules/hs.hotkey/HSHotkeyModule.swift Important Files Changed
Prompt To Fix All With AI### Issue 1
Hammerspoon 2/Modules/hs.hotkey/HSHotkeyModule.swift:23
**API Documentation Is Stale**
The runtime now rejects callback-less `bind()` calls, but the checked-in API documentation still permits each callback to be null and describes null only as a generic binding failure. Regenerate or update the non-HTML API artifacts so users can discover the new requirement instead of encountering an unexplained compatibility change.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "hs.hotkey: require at least one callback..." | Re-trigger Greptile |
cmsj
approved these changes
Sep 10, 2026
cmsj
added a commit
that referenced
this pull request
Sep 11, 2026
PR #208 (dcee222, rebased here as e767bbd) intentionally left the docs refresh for later. Rebasing onto main also picked up #207's callback guard in bind(), so both land together. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VLGfVh2SKZmZAh1YQfbMfn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context / question
While reading through
hs.hotkeyI noticed thatbind()happily creates andenables a hotkey even when no function callback is given at all — e.g.
bind(mods, key, null, null)orbind(mods, key, null, null, null). Sincebind()enables immediately, the result is a hotkey that claims the key combination(swallowing it from other apps) but runs nothing — a silent no-op.
I'm genuinely not sure whether that's intended or just an edge case that never came up. Guarding against it in
bind()seemed sensible, but I may well be missing a reason it's allowed — I'm completely fine if this PR is dismissed and rejected.What this PR does
bind()returnsnull(and logs an error) unless at least one of them is a function:callbackPressed,callbackReleased, orcallbackRepeatcreate()is deliberately left permissive, so the "build now, assign callbacks later via properties" pattern still works.(Side note: the
messagetoast is shown just before a callback fires, so amessage-only hotkey never shows its message either — which is partly why a
callback-less hotkey feels like a mistake rather than a use case.)
Example
Log:
bind()logs the error and returnsnullwithout throwing, so the surroundingscript keeps running.
Changes
bind()requiring ≥1 function callback.bindSpecmessage tests to pass a callback (a message-only spec is now rejected under this rule).bindwith no callbacks →null;createwith no callbacks still succeeds.Notes
api.json/ HTML / TS) intentionally not regenerated here; the updatedbind()docstring flags that a docs refresh is owed.hs.hotkey); minor rebase possible depending on merge order.🤖 Generated with Claude Code