From f9dd573839b66e5ed2b530fbaac38caaaa4776a1 Mon Sep 17 00:00:00 2001 From: zhao-george Date: Tue, 14 Nov 2023 15:05:37 +0800 Subject: [PATCH] fix: fix the issue of failing to retrieve window ID "When using xdotool to retrieve window IDs, if there are multiple windows, the output ends with '\n'. In the original code, directly splitting the string using split("\n") can result in the last element of the resulting list being an empty string. This situation leads to errors when iterating through the window IDs and converting them to int type." Log: fix the issue of failing to retrieve window ID --- src/button_center.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/button_center.py b/src/button_center.py index 158c9ebb..e558bb14 100644 --- a/src/button_center.py +++ b/src/button_center.py @@ -54,7 +54,7 @@ def window_info(self): interrupt=False, out_debug_flag=False, command_log=False, - ).split("\n") + ).strip().split("\n") app_id_list = [int(_id) for _id in app_id if _id] app_id_list.sort() logger.debug(f"app_id_list: {app_id_list}") @@ -557,7 +557,7 @@ def get_windows_number(cls, name: str) -> int: cmd = f"xdotool search --classname {name}" app_id = CmdCtl.run_cmd( cmd, interrupt=False, out_debug_flag=False, command_log=False - ) + ).strip() return len([i for i in app_id.split("\n") if i]) @classmethod @@ -570,7 +570,7 @@ def get_windows_id(cls, name: str) -> list: cmd = f"xdotool search --onlyvisible --classname {name}" app_id = CmdCtl.run_cmd( cmd, interrupt=False, out_debug_flag=False, command_log=False - ) + ).strip() if app_id: return [i for i in app_id.split("\n") if i] raise ApplicationStartError(app_id) @@ -600,7 +600,7 @@ def get_lastest_window_id(app_name: str) -> int: interrupt=False, out_debug_flag=False, command_log=False, - ).split("\n") + ).strip().split("\n") app_id_list = [int(_id) for _id in app_id if _id] # to int app_id_list.sort() return app_id_list[-1]