Skip to content

Handle InvalidStateError when registering keyboard shortcut - #10

Open
JS55CT wants to merge 9 commits into
WazeDev:mainfrom
JS55CT:main
Open

JS55CT wants to merge 9 commits into
WazeDev:mainfrom
JS55CT:main

Conversation

@JS55CT

@JS55CT JS55CT commented Mar 3, 2026

Copy link
Copy Markdown

Problem

When the addShield shortcut was registered with shortcutKeys: "A+83" or "ALT+S", if that key combination was already claimed by another script or WME feature, sdk.Shortcuts.createShortcut would throw an InvalidStateError. This exception was unhandled, causing setupOptions to abort silently — leaving layers, event listeners, and UI elements uninitialized.

Fix

Wrapped the createShortcut call in a try/catch with a two-stage fallback:

  1. First attempt — registers the shortcut with the default A+S key binding as before.
  2. On "already in use" error — retries with shortcutKeys: null, registering the shortcut without a key binding. The user can assign a conflict-free key manually via WME's keyboard shortcuts panel.
  3. Any other error — logged to console with the RSA: prefix and does not interrupt script initialization.

JS55CT and others added 9 commits March 3, 2026 16:55
Problem

When the addShield shortcut was registered with shortcutKeys: "A+83" or "ALT+S", if that key combination was already claimed by another script or WME feature, sdk.Shortcuts.createShortcut would throw an InvalidStateError. This exception was unhandled, causing setupOptions to abort silently — leaving layers, event listeners, and UI elements uninitialized.

Fix

Wrapped the createShortcut call in a try/catch with a two-stage fallback:

First attempt — registers the shortcut with the default A+S key binding as before.
On "already in use" error — retries with shortcutKeys: null, registering the shortcut without a key binding. The user can assign a conflict-free key manually via WME's keyboard shortcuts panel.
Any other error — logged to console with the RSA: prefix and does not interrupt script initialization.
- Refactored shortcut registration to use areShortcutKeysInUse() guard instead of catch block error handling
- Removed deprecated WazeWrap.Remote server synchronization code (serverSettings, serverSave)
- Migrated from Google Sheets REST API to Visualization API (/gviz/tq) to bypass 403 referrer restrictions
- Switched from native fetch() to GM_xmlhttpRequest() for proper Tampermonkey sandbox support
- Added @connect docs.google.com permission for cross-origin requests
- Implemented response caching to prevent duplicate Google Sheets requests
- Fixed race condition in isStreetCandidate by making function async and awaiting data loads
- Fixed Google Sheets response format parsing (regex pattern and shield ID mapping)
- Fixed "Cannot use 'in' operator" error by guarding RoadAbbr[countryId] type checks
- Parallelized state abbreviation loading with Promise.allSettled() for better performance
- Implemented lazy-loading of state-specific abbreviation data for instant startup (only loads default sheet initially, state sheets load on-demand)
- Improved shield direction label styling: white text with black outline, increased font size for better readability
- Refactored shortcut registration to use areShortcutKeysInUse() guard instead of catch block error handling
- Removed deprecated WazeWrap.Remote server synchronization code (serverSettings, serverSave)
- Migrated from Google Sheets REST API to Visualization API (/gviz/tq) to bypass 403 referrer restrictions
- Switched from native fetch() to GM_xmlhttpRequest() for proper Tampermonkey sandbox support
- Added @connect docs.google.com permission for cross-origin requests
- Implemented response caching to prevent duplicate Google Sheets requests
- Fixed race condition in isStreetCandidate by making function async and awaiting data loads
- Fixed Google Sheets response format parsing (regex pattern and shield ID mapping)
- Fixed "Cannot use 'in' operator" error by guarding RoadAbbr[countryId] type checks
- Parallelized state abbreviation loading with Promise.allSettled() for better performance
- Implemented lazy-loading of state-specific abbreviation data for instant startup (only loads default sheet initially, state sheets load on-demand)
- Improved shield direction label styling: white text with black outline, increased font size for better readability
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.

3 participants