Skip to content

Comments

Added a BlueStacks instance selector in the GUI with Refresh, persist…#616

Open
AlanDCE wants to merge 9 commits intopyclashbot:masterfrom
AlanDCE:master
Open

Added a BlueStacks instance selector in the GUI with Refresh, persist…#616
AlanDCE wants to merge 9 commits intopyclashbot:masterfrom
AlanDCE:master

Conversation

@AlanDCE
Copy link
Contributor

@AlanDCE AlanDCE commented Dec 19, 2025

…ing your choice.

Implemented list_bluestacks_instances() to fetch instances without launching anything, and threaded instance_name through to the controller. Bot now starts on the chosen instance and proceeds with ADB + Clash Royale. Thanks to Macadan (Discord) for testing help.

…ing your choice.

Implemented list_bluestacks_instances() to fetch instances without launching anything, and threaded instance_name through to the controller.
Bot now starts on the chosen instance and proceeds with ADB + Clash Royale.
Thanks to Macadan (Discord) for testing help.
Copilot AI review requested due to automatic review settings December 19, 2025 01:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a BlueStacks instance selector to the GUI, allowing users to choose which BlueStacks instance the bot should run on. The selected instance is persisted across sessions and the list of available instances can be refreshed via a button in the UI.

Key changes:

  • Added a new list_bluestacks_instances() function that reads BlueStacks configuration files to enumerate available instances without launching anything
  • Enhanced the BlueStacks controller to accept and use a user-specified instance name, with fallback logic to select the first available instance if the requested one isn't found
  • Created GUI components (combobox and refresh button) for instance selection in the emulator settings tab

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pyclashbot/interface/ui.py Added BlueStacks instance selector UI components, callback registration, and value persistence logic
pyclashbot/interface/enums.py Added BLUESTACKS_INSTANCE enum field for configuration storage
pyclashbot/emulators/bluestacks.py Implemented list_bluestacks_instances() function, added instance_name parameter to constructor, added _ensure_target_instance() method with fallback logic, and updated instance detection logic
pyclashbot/bot/worker.py Threaded instance_name from configuration to BlueStacks controller constructor
pyclashbot/main.py Added callback implementations for getting and refreshing BlueStacks instances list, integrated with UI components

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

self.logger.change_status(f"Error refreshing BlueStacks instances: {e}")



Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank lines. There should only be one blank line between method definitions and two blank lines before top-level function definitions according to PEP 8 style guidelines.

Suggested change

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,3 @@
import csv
import io
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The csv module import was removed from the imports section but is still being used at line 684 with csv.reader(). This will cause a NameError at runtime when the _is_this_instance_running() method is called on Windows. The csv import must be added back to the imports at the top of the file.

Copilot uses AI. Check for mistakes.
Comment on lines +765 to 770
if elapsed > soft_wait:
self.logger.log("[BlueStacks 5] Proceeding without window title match; assuming launched.")
break
if elapsed > boot_timeout:
self.logger.change_status("Timeout waiting for pyclashbot instance to start - retrying...")
return False
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The soft_wait check will always break the loop after 15 seconds, making the boot_timeout check at line 768 unreachable. The condition order should be reversed so that boot_timeout is checked first to ensure proper timeout behavior. The logic should fail after boot_timeout but proceed optimistically after soft_wait if the instance hasn't been detected yet.

Suggested change
if elapsed > soft_wait:
self.logger.log("[BlueStacks 5] Proceeding without window title match; assuming launched.")
break
if elapsed > boot_timeout:
self.logger.change_status("Timeout waiting for pyclashbot instance to start - retrying...")
return False
if elapsed > boot_timeout:
self.logger.change_status("Timeout waiting for pyclashbot instance to start - retrying...")
return False
if elapsed > soft_wait:
self.logger.log("[BlueStacks 5] Proceeding without window title match; assuming launched.")
break

Copilot uses AI. Check for mistakes.
Comment on lines +700 to +701
# Fallback: if any BlueStacks player is running, assume ours to avoid hanging
if any_player:
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic that returns True if any BlueStacks player is running will incorrectly report that the specific instance is running even when it is not. This defeats the purpose of instance-specific checking and could cause the bot to attempt to connect to the wrong instance. Consider removing this fallback or making it conditional on whether a specific instance name was requested.

Suggested change
# Fallback: if any BlueStacks player is running, assume ours to avoid hanging
if any_player:
# Fallback: if any BlueStacks player is running, assume ours only when no specific title is requested
if any_player and not title:

Copilot uses AI. Check for mistakes.

The callback should return a list of available instance names.
"""
self._bluestacks_refresh_callback = callback
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line after the method definition. There should be a blank line between the register_bluestacks_refresh_callback method and the get_all_values method to follow PEP 8 style guidelines for spacing between method definitions.

Suggested change
self._bluestacks_refresh_callback = callback
self._bluestacks_refresh_callback = callback

Copilot uses AI. Check for mistakes.
"""Handle the BlueStacks refresh button click."""
self._update_bluestacks_instances()


Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line. There should only be one blank line between method definitions according to PEP 8 style guidelines.

Suggested change

Copilot uses AI. Check for mistakes.
@AlanDCE
Copy link
Contributor Author

AlanDCE commented Jan 18, 2026

Added BlueStacks instance selector and bug fixes

This update adds a GUI instance selector for BlueStacks, letting users choose which BlueStacks instance to run the bot on. The selector includes a refresh button to update the list of available instances, and your choice is saved in the config.

Also implemented list_bluestacks_instances() to fetch instances without launching anything, and threaded the instance_name through to the controller so the bot starts on your chosen instance.

Bug fixes:

  • Added missing csv import that was causing crashes when checking running instances
  • Improved error handling for Windows registry access (prevents crashes when BlueStacks isn't installed or registry permissions are denied)
  • Fixed trailing whitespace issues

The bot now starts on the selected BlueStacks instance and proceeds with ADB + Clash Royale as expected.

Thanks to Macadan (Discord) for testing help.

	deleted:    .vscode/settings.json

 Changes not staged for commit:
	modified:   .gitignore

 Untracked files:
	.vscode/settings.json
- Added ScheduleConfig class for time-based scheduling (start/end times)
- Integrated scheduler UI in Misc tab with hour/minute spinboxes
- Added ColoredFormatter for terminal log output (color-coded messages)
- LogColorMap auto-detects message type and applies appropriate color
- Supports Success (green), Error (red), Warning (yellow), Info (blue), Debug (cyan)
- Removed Presets feature after initial implementation
- All new modules import correctly and test successfully
- Added _check_scheduler() method in worker.py to verify schedule after each battle
- Bot now stops gracefully when outside configured time window
- Integrated ColoredFormatter into Logger class for terminal output
- Added colored output to log() and error() methods
- Logs now display with automatic color detection based on keywords
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.

1 participant