Skip to content

fix: handle unsupported hotkey gracefully in menu builder#219

Closed
gamedevCloudy wants to merge 2 commits intoRustCastLabs:masterfrom
gamedevCloudy:master
Closed

fix: handle unsupported hotkey gracefully in menu builder#219
gamedevCloudy wants to merge 2 commits intoRustCastLabs:masterfrom
gamedevCloudy:master

Conversation

@gamedevCloudy
Copy link
Copy Markdown

[Bug]App crashes on launch with UnsupportedKey("OPT") panic in menu builder

Explanation:
Rustcast v0.7.0-beta crashes immediately on macOS when launched in standard (non-agent) mode. The app attempts to parse the default toggle hotkey (ALT+SPACE) and register it as a tray menu accelerator. On macOS, the ALT modifier maps to the Option key which tray-icon's Accelerator does not support. The unwrap() call on the parse result causes a panic that terminates the main thread, making the app completely unusable.

What we did to find it:

  • Observed the app process running but macOS showing "Application is not responding" with no visible UI
  • Enabled LSUIElement=false in Info.plist to expose the menu bar, which triggered the crash path
  • Ran the binary directly from terminal with RUST_BACKTRACE=1 to capture the panic and full stack trace
  • Identified the crash at src/app/menubar.rs:42 — unwrap() on UnsupportedKey("OPT") from HotKey::parse

How to reproduce:

  • Rustcast v0.7.0-beta
  • Launch the app in standard mode (or set LSUIElement=false in Info.plist)
  • The default toggle_hotkey = "ALT+SPACE" in the config triggers the crash on macOS
  • App panics immediately at startup before any UI is rendered

System info:

  • macOS (Apple Silicon, arm64)
  • Rustcast v0.7.0-beta
  • tray-icon v0.21.3 / global-hotkey v0.7.0

Fix applied:
Changed .unwrap() to .ok() on the hotkey parse and added graceful degradation, when the hotkey contains unsupported keys, the "Toggle View" menu item renders without an accelerator and the app uses a simplified event handler.

Disclosure: AI Used

  • Agent: Opencode
  • Model: Mimo-v2-pro

Panic occurred when toggle_hotkey config contained keys unsupported
by tray-icon's Accelerator (e.g. ALT/Option on macOS). Changed
unwrap to ok() and added fallback menu item without accelerator.
@unsecretised
Copy link
Copy Markdown
Collaborator

unsecretised commented Mar 25, 2026

  1. Instead of bringing the init_event_handler out of its function and just copy pasting that bit, instead can you use a Option as the function argument and handle it that way?
  2. Thank you for the AI disclosure, however, I do hope that for the above mentioned change you could implement it yourself
    as mentioned in (5) in https://github.com/unsecretised/rustcast?tab=contributing-ov-file , i don't mind AI usage but lease limit it to MAX 25% of AI / minimally 75% of Human code.

To me, this seems like more than 25% AI Code, and hence I cannot accept this change right now. If you are able to improve the code quality without using AI, I can merge this PR.

@unsecretised unsecretised self-requested a review March 25, 2026 07:25
@gamedevCloudy
Copy link
Copy Markdown
Author

Thank you for the review.
As of now, I do not know rust. I was trying to fix issue I had.
Thus, I cannot contribute meaningfully.

I understand the AI requirements, I will close this request.

@unsecretised
Copy link
Copy Markdown
Collaborator

No worries, since this is a beta version I'll add this feature for you, and it should be available either today or tomorrow (If you join the discord server you can opt in for new release pings)

unsecretised added a commit that referenced this pull request Mar 25, 2026
@unsecretised unsecretised mentioned this pull request Mar 25, 2026
@unsecretised
Copy link
Copy Markdown
Collaborator

@gamedevCloudy the fix has been added to rustcast!

@gamedevCloudy
Copy link
Copy Markdown
Author

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.

2 participants