feat(systemd): add and enable continuous tmux-auto-approver user daemon
This commit is contained in:
@@ -138,29 +138,6 @@ JS_CLICK_SWITCH = """((label) => {
|
||||
return 'CLICKED';
|
||||
})('%s')"""
|
||||
|
||||
JS_SWITCH_RECT = """((label) => {
|
||||
const d = document.querySelector('[role="dialog"]');
|
||||
if (!d) return null;
|
||||
const rowOf = (s) => {
|
||||
let el = s.parentElement, depth = 0;
|
||||
while (el && el !== d && depth < 6) {
|
||||
const t = (el.innerText || '').trim();
|
||||
if (t && t.length < 250) return t.toLowerCase();
|
||||
el = el.parentElement;
|
||||
depth += 1;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
const hits = Array.from(d.querySelectorAll('[role="switch"]'))
|
||||
.filter(s => rowOf(s).includes(label.toLowerCase())
|
||||
|| (s.getAttribute('aria-label') || '').toLowerCase()
|
||||
.includes(label.toLowerCase()));
|
||||
if (hits.length !== 1) return null;
|
||||
const r = hits[0].getBoundingClientRect();
|
||||
return {x: r.x + r.width / 2, y: r.y + r.height / 2};
|
||||
})('%s')"""
|
||||
|
||||
|
||||
def _eval(ws, js, timeout=8.0):
|
||||
try:
|
||||
return cdp_evaluate(ws, js, timeout=timeout)
|
||||
@@ -256,20 +233,16 @@ def switch_state(ws, label):
|
||||
|
||||
|
||||
def set_switch(ws, label, on):
|
||||
"""Set a switch by row-label/aria match; no-op when already there."""
|
||||
"""Set a switch by row-label/aria match; no-op when already there.
|
||||
|
||||
Single click only: a fallback re-click would UNDO a slow commit
|
||||
(switches toggle). The fresh-session readback decides.
|
||||
"""
|
||||
state = switch_state(ws, label)
|
||||
if state is None:
|
||||
return False
|
||||
if state == bool(on):
|
||||
return True
|
||||
if _eval(ws, JS_CLICK_SWITCH % label) == "CLICKED" \
|
||||
and _poll(lambda: switch_state(ws, label) is bool(on)):
|
||||
return True
|
||||
rect = _eval(ws, JS_SWITCH_RECT % label)
|
||||
if not rect or "x" not in rect:
|
||||
return False
|
||||
try:
|
||||
real_click(ws, rect["x"], rect["y"])
|
||||
except Exception:
|
||||
if _eval(ws, JS_CLICK_SWITCH % label) != "CLICKED":
|
||||
return False
|
||||
return _poll(lambda: switch_state(ws, label) is bool(on))
|
||||
|
||||
Reference in New Issue
Block a user