diff --git a/set-initial-kanshi-state b/set-initial-kanshi-state index 6f549cc..2416a44 100755 --- a/set-initial-kanshi-state +++ b/set-initial-kanshi-state @@ -21,7 +21,7 @@ fi get_current_profile() { local profile - profile="$(kanshictl status | jq -er '.current_profile')" + profile="${$(kanshictl status):17}" (( $? )) && return 1 : ${(P)1::="${profile}"} } diff --git a/usbguard-notify.py b/usbguard-notify.py index 750ed8a..93b93ed 100755 --- a/usbguard-notify.py +++ b/usbguard-notify.py @@ -4,6 +4,7 @@ import shutil import re import threading from subprocess import Popen, run, DEVNULL, PIPE +import sys USBGUARD_EXEC_NAME = shutil.which("usbguard") DUNSTIFY_EXEC_NAME = shutil.which("dunstify") @@ -12,14 +13,16 @@ open_notifications = {} def parse_event_type_and_id(stream): line = stream.readline() + if not line: + return None, True if not line.startswith("[device] "): - return None + return None, False event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line) if len(event_type) == 0: - return None + return None, False event_id = re.findall("(?<=id=)[0-9]+", line) if len(event_id) == 0: - return None + return None, False return event_type[0], int(event_id[0]) @@ -101,9 +104,15 @@ with Popen( bufsize=0, ) as usbguard_proc: new_devices = set() - usbguard_proc.stdout.readline() # get rid of initial connection message + first_line = ( + usbguard_proc.stdout.readline() + ) # get rid of initial connection message + if not first_line: + sys.exit() while True: - event_type_result = parse_event_type_and_id(usbguard_proc.stdout) + event_type_result, eof = parse_event_type_and_id(usbguard_proc.stdout) + if eof: + sys.exit() if event_type_result is None: continue event_type, dev_id = event_type_result