mirror of
https://github.com/duma799/hyprduma-config.git
synced 2026-05-14 22:51:00 +00:00
Add reconnection logic and error logging to monitor-handler.py
This commit is contained in:
+26
-5
@@ -4,6 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def get_socket_path():
|
def get_socket_path():
|
||||||
@@ -24,11 +25,7 @@ def handle_reload():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
subprocess.Popen(["caelestia", "shell", "-d"])
|
subprocess.Popen(["caelestia", "shell", "-d"])
|
||||||
|
|
||||||
def main():
|
def listen(path):
|
||||||
path = get_socket_path()
|
|
||||||
if not path:
|
|
||||||
return
|
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
sock.connect(path)
|
sock.connect(path)
|
||||||
buf = ""
|
buf = ""
|
||||||
@@ -43,5 +40,29 @@ def main():
|
|||||||
if line.startswith("configreloaded"):
|
if line.startswith("configreloaded"):
|
||||||
handle_reload()
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user