Skip to content

激活窗口中查找窗口的部分改成使用Findwindow#5

Open
huxinchi wants to merge 3 commits intoNinot1Quyi:mainfrom
huxinchi:main
Open

激活窗口中查找窗口的部分改成使用Findwindow#5
huxinchi wants to merge 3 commits intoNinot1Quyi:mainfrom
huxinchi:main

Conversation

@huxinchi
Copy link
Copy Markdown

@huxinchi huxinchi commented Aug 30, 2025

使用findwindow寻找窗口

Summary by Sourcery

Simplify window activation by replacing manual window enumeration with a direct FindWindow API call

Enhancements:

  • Use win32gui.FindWindow to locate the mGBA window instead of EnumWindows enumeration
  • Standardize error logging with logging.error for missing windows

使用findwindow寻找窗口
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Aug 30, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactor activate_mgba_window to simplify window lookup by replacing manual enumeration with a direct FindWindow call, streamlining the search logic and error handling.

Sequence diagram for the updated mGBA window activation process

sequenceDiagram
    participant Caller
    participant win32gui
    participant Logger
    participant window_lock
    Caller->>win32gui: FindWindow(None, search_text)
    alt Window found
        Caller->>window_lock: Acquire lock
        window_lock-->>Caller: Lock acquired
        Caller->>win32gui: Check if window is foreground
        Note right of Caller: Proceed with activation logic
    else Window not found
        Caller->>Logger: logging.error("not find window")
    end
Loading

File-Level Changes

Change Details Files
Refactor window search to use FindWindow instead of enumerating all windows
  • Removed enum_windows callback and hwnd_list with EnumWindows
  • Replaced manual search logic with win32gui.FindWindow call
  • Updated error handling to use logging.error with a concise message
bilibili_mgba_controller.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `bilibili_mgba_controller.py:253` </location>
<code_context>
-    if not hwnd_list:
-        logger.error(f"No window found with '{search_text}' in title")
+    hwnd=win32gui.FindWindow(None,search_text)
+    if not hwnd:
+        logging.error("not find window")
         return False
-    
</code_context>

<issue_to_address>
Inconsistent use of logger for error reporting.

Using 'logging.error' instead of the configured 'logger.error' may bypass custom logging settings. Please use the same logger instance for consistency.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    hwnd=win32gui.FindWindow(None,search_text)
=======
    hwnd=win32gui.FindWindow(None,search_text)
    if not hwnd:
        logger.error(f"No window found with '{search_text}' in title")
        return False
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -249,20 +249,10 @@ def broadcast_danmaku(danmaku_data):

def activate_mgba_window(search_text: str = MGBA_WINDOW_TITLE):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:


Explanation

The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

huxinchi and others added 2 commits August 30, 2025 18:33
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
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