From 5ea5c4a576e4c81518f4647acc40751ffd9a88a3 Mon Sep 17 00:00:00 2001 From: duma799 Date: Thu, 12 Feb 2026 01:10:56 +0400 Subject: [PATCH] Add reconnection logic and error logging to monitor-handler.py --- monitor-handler.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/monitor-handler.py b/monitor-handler.py index 2d05177..98034bf 100644 --- a/monitor-handler.py +++ b/monitor-handler.py @@ -4,6 +4,7 @@ import os import socket import subprocess +import sys import time def get_socket_path(): @@ -24,11 +25,7 @@ def handle_reload(): time.sleep(1) subprocess.Popen(["caelestia", "shell", "-d"]) -def main(): - path = get_socket_path() - if not path: - return - +def listen(path): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(path) buf = "" @@ -43,5 +40,29 @@ def main(): if line.startswith("configreloaded"): handle_reload() + sock.close() + +def main(): + path = get_socket_path() + if not path: + print("monitor-handler: HYPRLAND_INSTANCE_SIGNATURE not set", file=sys.stderr) + return + + while True: + try: + listen(path) + except (ConnectionRefusedError, FileNotFoundError): + pass + except Exception as e: + print(f"monitor-handler: {e}", file=sys.stderr) + + # Socket closed or errored — wait and retry + time.sleep(2) + + # Re-check socket path in case Hyprland restarted with new signature + new_path = get_socket_path() + if new_path: + path = new_path + if __name__ == "__main__": main()