feat: use Hammerspoon URL scheme for click-to-focus - #7
Open
iFwu wants to merge 1 commit into
Open
Conversation
…proving performance
Owner
|
I've been playing with this for the past 30 minutes and I can't get my window to focus when using the PR. Does cross-space window focusing work for you (including when you have multiple app windows open -- i.e. multiple VS Code projects in separate windows and spaces)? What OS + Hammerspoon versions are you on? |
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.
Summary
create_focus_commandbuilds a complex multi-line Lua script and passes it throughshlex.quote()→terminal-notifier -execute. The nested quoting (single quotes in Lua, shell escaping, terminal-notifier's own shell execution) causes the script to fail, triggering the "Could not restore window focus" error notification on every click.hsCLI process with ~1.8s startup overhead, making total click-to-focus take ~3.4s. The URL scheme is handled in-process by Hammerspoon, reducing latency to ~1.6s (just the macOS Space switch animation).Changes
cc_notifier.pycreate_focus_command(window_id) -> list[str]withcreate_focus_url(window_id) -> strthat returns ahammerspoon://focus?id=<window_id>URLsend_notificationto use-open <url>instead of-execute <shell_command>import shlex(no longer needed)README.mdhs.window.filter+hs.timerrequires withhs.urleventand thefocusURL event handlerBackward Compatibility
Fully backward compatible. Without Hammerspoon installed,
focus_window_idis never set (theget_focused_window_id()call raises and sets window ID to"UNAVAILABLE"), so the-opencode path is never reached.Test plan
-openflag sent)