mirror of
https://github.com/erenfro/keepassxc-unlocker.git
synced 2024-12-04 16:05:38 -05:00
Added retry handler for watch
This commit is contained in:
parent
97895234ff
commit
565337975d
1 changed files with 32 additions and 17 deletions
|
@ -109,26 +109,41 @@ def watch():
|
||||||
]
|
]
|
||||||
|
|
||||||
found_interface = False
|
found_interface = False
|
||||||
for interface, path in interfaces_to_monitor:
|
tries = 0
|
||||||
try:
|
|
||||||
proxy = session_bus.get_object(interface, path)
|
|
||||||
iface = dbus.Interface(proxy, dbus_interface=interface)
|
|
||||||
|
|
||||||
session_bus.add_signal_receiver(
|
while tries < 5 and found_interface == False:
|
||||||
on_signal_received,
|
tries += 1
|
||||||
dbus_interface=interface,
|
logging.info("Initializing D-Bus session interface monitor...")
|
||||||
signal_name="ActiveChanged",
|
for interface, path in interfaces_to_monitor:
|
||||||
)
|
try:
|
||||||
logging.info(f"Subscribed to {interface} at {path}")
|
proxy = session_bus.get_object(interface, path)
|
||||||
found_interface = True
|
iface = dbus.Interface(proxy, dbus_interface=interface)
|
||||||
except dbus.exceptions.DBusException as e:
|
|
||||||
pass
|
|
||||||
#logging.warning(f"Could not subscribe to {interface} at {path}: {e}")
|
|
||||||
|
|
||||||
if not found_interface:
|
session_bus.add_signal_receiver(
|
||||||
logging.error("No suitable interfaces were found. Exiting...")
|
on_signal_received,
|
||||||
return
|
dbus_interface=interface,
|
||||||
|
signal_name="ActiveChanged",
|
||||||
|
)
|
||||||
|
logging.info(f"Subscribed to {interface} at {path}")
|
||||||
|
found_interface = True
|
||||||
|
break
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Exiting by user interupt.")
|
||||||
|
sys.exit(0)
|
||||||
|
except dbus.exceptions.DBusException as e:
|
||||||
|
pass
|
||||||
|
#logging.warning(f"Could not subscribe to {interface} at {path}: {e}")
|
||||||
|
|
||||||
|
if not found_interface:
|
||||||
|
if tries < 5:
|
||||||
|
try:
|
||||||
|
time.sleep(5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Exiting by user interupt.")
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
logging.error("No suitable interfaces were found. Exiting...")
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
# Start the process monitoring thread
|
# Start the process monitoring thread
|
||||||
monitor_thread = threading.Thread(target=monitor_process, args=(process_name,))
|
monitor_thread = threading.Thread(target=monitor_process, args=(process_name,))
|
||||||
|
|
Loading…
Reference in a new issue