generated from StreamController/PluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: code quality improvements - phases 1-3 #34
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
Merged
Merged
Conversation
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
- Wrap UI updates with GLib.idle_add() for thread safety - AdSchedule.py: Wrap labels and color updates - ChatMode.py: Wrap set_center_label() calls - ShowViewers.py: Wrap set_center_label() calls - Add backend initialization error handling - Modified _setup_backend() to return bool - Added backend_initialized to track state - Added error logging for init failures - Updated settings.py to check init status Fixes race conditions and crashes from UI updates on non-main threads, provides better error visibility
- Add descriptive error messages to all action files - Clip.py: Add context for clip creation failures - Marker.py: Add context for stream marker creation failures - SendMessage.py: Add channel name in error messages - ChatMode.py: Add mode name in toggle/update errors - PlayAd.py: Add ad duration in error messages - AdSchedule.py: Add specific context for schedule errors - Fix HTTP server lifecycle in twitch_backend.py - Properly cleanup server on disconnect - Clean up existing server before creating new one - Add error handling for server creation and cleanup - Set server references to None after cleanup - Consolidate AdSchedule threads into single update loop - Reduce from 2 threads to 1 consolidated thread - Fetch ad schedule every 30s, update display every 1s - Eliminate nested loops, improve resource efficiency
Create centralized constants.py for magic numbers
- Create constants.py with timing and OAuth config - Update all action files to use constants: - VIEWER_UPDATE_INTERVAL_SECONDS - AD_SCHEDULE/DISPLAY_UPDATE_INTERVAL_SECONDS - CHAT_MODE_UPDATE_INTERVAL_SECONDS - ERROR_DISPLAY_DURATION_SECONDS - Update twitch_backend.py to use OAuth constants - Centralize configuration for easier modification
- Add rate limit: 100 calls per 60 seconds - Implement thread-safe RateLimiter (sliding window) - Apply rate limiting to all Twitch API methods - Rate limiter auto-waits when limit reached - Prevent hitting Twitch API throttling (800/min)
- Add typing imports: Optional, Callable, Any - Update twitch_backend.py with complete type hints - Update main.py with complete type hints - Add return type annotations to all methods
Add type hints to settings.py and TwitchCore
- Add type hints to all 7 action files - Add null checks for Optional values - Import typing (Any, Optional, List, Union)
- Add RateLimiter docstring explaining algorithm - Add Backend class docstring - Add docstrings to key Backend methods - Add PluginTemplate docstring
e15bf37 to
f121c4d
Compare
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
This PR implements comprehensive code quality improvements across three phases:
Changes Overview
Phase 1: Thread Safety & Initialization
GLib.idle_add()wrappers for all UI updates from background threadsPhase 2: Error Handling & Server Lifecycle
Phase 3: Code Quality
constants.py(10 commits)Stats
Testing
All changes maintain backward compatibility. The plugin should work identically
to before, but with:
Commit Convention
All commits follow Angular format with lines ≤ 100 characters:
fix(threading): Thread safety improvementsfix(errors): Error handling improvementsfeat(constants): Configuration constantsrefactor(config): Extract magic numbersfeat(api): Rate limiting implementationfeat(types): Type hints additionsdocs: Documentation improvements