Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions bilibili_mgba_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"""查找并激活 mGBA 窗口(改进版本)"""
def enum_windows(hwnd, results):
if win32gui.IsWindowVisible(hwnd):
title = win32gui.GetWindowText(hwnd)
if search_text in title:
results.append(hwnd)

hwnd_list = []
win32gui.EnumWindows(enum_windows, hwnd_list)

if not hwnd_list:
hwnd=win32gui.FindWindow(None,search_text)
Comment thread
huxinchi marked this conversation as resolved.
if not hwnd:
logger.error(f"No window found with '{search_text}' in title")
return False

hwnd = hwnd_list[0]
with window_lock: # 线程安全
try:
# 检查窗口是否已经是前台窗口
Expand Down