From 08691f88a155a2795045e26be11ddb460f2eda07 Mon Sep 17 00:00:00 2001 From: Lenochxd <81lennoch@gmail.com> Date: Sun, 25 Feb 2024 15:38:09 +0100 Subject: [PATCH] Fix: macro when yuzu settings are open Also fixed apostrophe in notifications --- join_room.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/join_room.py b/join_room.py index d297d7b..141f6db 100644 --- a/join_room.py +++ b/join_room.py @@ -30,6 +30,7 @@ def send_error(message): set_global_variable(window) def send_info(message): + print(message) window = get_global_variable() window.evaluate_js(f"showInfo('{message}');", callback) focus_webview() @@ -61,12 +62,12 @@ def yuzu_ready(): break if not found: - send_error("Yuzu doesn't seem to be launched.") + send_error("Yuzu doesn't seem to be launched.") return False return yuzu_window - def focus_yuzu(): + def focus_yuzu_window(): yuzu_window = yuzu_ready() if yuzu_window != False: try: @@ -74,10 +75,29 @@ def focus_yuzu(): except gw.PyGetWindowException: pass win32gui.ShowWindow(yuzu_window._hWnd, 9) # Restore window if minimized + return True - return False + def focus_yuzu(): + print('1') + if not 'yuzu' in gw.getActiveWindow().title.lower(): + print('2') + windows = gw.getAllWindows() + + for window in windows: + title = window.title.lower() + if "yuzu" in title and not "yuzu 1" in title: + try: + window.activate() # Focus window + except gw.PyGetWindowException: + pass + win32gui.ShowWindow(window._hWnd, 9) # Restore window if minimized + pyautogui.press("esc") + return focus_yuzu_window() + + return True + def focus_webview(): windows = gw.getAllWindows() @@ -103,7 +123,13 @@ def handle_room_failed(ip, port, username, password): answer = messagebox.askyesno("Failed to join the room.", "Retry?") if answer: - macro(ip, port, username, password) + if focus_yuzu() == True: + time.sleep(0.5) + macro(ip, str(port), username, password) + + print("Room joined") + else: + print("Failed to join room") else: send_info( f" Go on Yuzu -> Ctrl+C, and then enter:

Adress: {ip}
Port: {port}
Password: {password}
" @@ -112,6 +138,9 @@ def handle_room_failed(ip, port, username, password): def macro(ip, port, username, password): pyautogui.press("esc") + pyautogui.press("esc") + pyautogui.press("esc") + time.sleep(0.1) pyautogui.hotkey("ctrl", "c") window_rect = pyautogui.getActiveWindow()