Stick `try:` outside all `xdotool` subproc calls

binance_ws_ep_update
Tyler Goodlet 2023-03-10 09:53:05 -05:00
parent 973e4b5f44
commit 78eb784091
1 changed files with 42 additions and 38 deletions

View File

@ -24,6 +24,10 @@ import subprocess
import tractor import tractor
from piker.log import get_logger
log = get_logger(__name__)
_reset_tech: Literal[ _reset_tech: Literal[
'vnc', 'vnc',
@ -134,54 +138,54 @@ def i3ipc_xdotool_manual_click_hack() -> None:
# 'IB', # gw running in i3 (newer version?) # 'IB', # gw running in i3 (newer version?)
] ]
for name in win_names: try:
results = t.find_titled(name) for name in win_names:
print(f'results for {name}: {results}') results = t.find_titled(name)
if results: print(f'results for {name}: {results}')
con = results[0] if results:
print(f'Resetting data feed for {name}') con = results[0]
win_id = str(con.window) print(f'Resetting data feed for {name}')
w, h = con.rect.width, con.rect.height win_id = str(con.window)
w, h = con.rect.width, con.rect.height
# TODO: seems to be a few libs for python but not sure # TODO: seems to be a few libs for python but not sure
# if they support all the sub commands we need, order of # if they support all the sub commands we need, order of
# most recent commit history: # most recent commit history:
# https://github.com/rr-/pyxdotool # https://github.com/rr-/pyxdotool
# https://github.com/ShaneHutter/pyxdotool # https://github.com/ShaneHutter/pyxdotool
# https://github.com/cphyc/pyxdotool # https://github.com/cphyc/pyxdotool
# TODO: only run the reconnect (2nd) kc on a detected # TODO: only run the reconnect (2nd) kc on a detected
# disconnect? # disconnect?
for key_combo, timeout in [ for key_combo, timeout in [
# only required if we need a connection reset. # only required if we need a connection reset.
# ('ctrl+alt+r', 12), # ('ctrl+alt+r', 12),
# data feed reset. # data feed reset.
('ctrl+alt+f', 6) ('ctrl+alt+f', 6)
]: ]:
subprocess.call([ subprocess.call([
'xdotool', 'xdotool',
'windowactivate', '--sync', win_id, 'windowactivate', '--sync', win_id,
# move mouse to bottom left of window (where there should # move mouse to bottom left of window (where
# be nothing to click). # there should be nothing to click).
'mousemove_relative', '--sync', str(w-4), str(h-4), 'mousemove_relative', '--sync', str(w-4), str(h-4),
# NOTE: we may need to stick a `--retry 3` in here.. # NOTE: we may need to stick a `--retry 3` in here..
'click', '--window', win_id, 'click', '--window', win_id,
'--repeat', '3', '1', '--repeat', '3', '1',
# hackzorzes # hackzorzes
'key', key_combo, 'key', key_combo,
], ],
timeout=timeout, timeout=timeout,
) )
# re-activate and focus original window # re-activate and focus original window
try:
subprocess.call([ subprocess.call([
'xdotool', 'xdotool',
'windowactivate', '--sync', str(orig_win_id), 'windowactivate', '--sync', str(orig_win_id),
'click', '--window', str(orig_win_id), '1', 'click', '--window', str(orig_win_id), '1',
]) ])
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
log.exception(f'xdotool timed out?') log.exception('xdotool timed out?')