Skip to content

Commit

Permalink
fix: 修复获取窗口id失败
Browse files Browse the repository at this point in the history
当使用xdotool获取窗口ID时,终端输出最后包含一个回车,如果查询到多个窗口,代码中直接使用按回车split,会导致生成的列表最后存在一个空字符串,这在将窗口ID转化为int类型时会导致错误。

Log: 修复获取窗口id失败
  • Loading branch information
zhao-george committed Nov 14, 2023
1 parent 3e3ef37 commit c5eebb6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/button_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit c5eebb6

Please sign in to comment.