Skip to content

Commit

Permalink
Fix: macro when yuzu settings are open
Browse files Browse the repository at this point in the history
Also fixed apostrophe in notifications
  • Loading branch information
Lenochxd committed Feb 25, 2024
1 parent 2e0ce03 commit 08691f8
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions join_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -61,23 +62,42 @@ 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:
yuzu_window.activate() # Focus window
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()

Expand All @@ -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:<BR><BR>Adress: {ip}<BR>Port: {port}<BR>Password: {password}<BR>"
Expand All @@ -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()
Expand Down

0 comments on commit 08691f8

Please sign in to comment.