1111
1212from .lib import get_current_window
1313from .config import parse_args
14+ from .macos_permissions import background_ensure_permissions
15+
1416
1517logger = logging .getLogger (__name__ )
1618
1719# run with LOG_LEVEL=DEBUG
18- log_level = os .environ .get (' LOG_LEVEL' )
20+ log_level = os .environ .get (" LOG_LEVEL" )
1921if log_level :
2022 logger .setLevel (logging .__getattribute__ (log_level .upper ()))
2123
24+
2225def main ():
2326 args = parse_args ()
2427
25- if sys .platform .startswith ("linux" ) and ("DISPLAY" not in os .environ or not os .environ ["DISPLAY" ]):
28+ if sys .platform .startswith ("linux" ) and (
29+ "DISPLAY" not in os .environ or not os .environ ["DISPLAY" ]
30+ ):
2631 raise Exception ("DISPLAY environment variable not set" )
2732
28- setup_logging (name = "aw-watcher-window" , testing = args .testing , verbose = args .verbose ,
29- log_stderr = True , log_file = True )
33+ setup_logging (
34+ name = "aw-watcher-window" ,
35+ testing = args .testing ,
36+ verbose = args .verbose ,
37+ log_stderr = True ,
38+ log_file = True ,
39+ )
3040
3141 if sys .platform == "darwin" :
32- from . import macos
33- macos .background_ensure_permissions ()
42+ background_ensure_permissions ()
3443
3544 client = ActivityWatchClient ("aw-watcher-window" , testing = args .testing )
3645
@@ -43,7 +52,14 @@ def main():
4352
4453 sleep (1 ) # wait for server to start
4554 with client :
46- heartbeat_loop (client , bucket_id , poll_time = args .poll_time , strategy = args .strategy , exclude_title = args .exclude_title )
55+ heartbeat_loop (
56+ client ,
57+ bucket_id ,
58+ poll_time = args .poll_time ,
59+ strategy = args .strategy ,
60+ exclude_title = args .exclude_title ,
61+ )
62+
4763
4864def heartbeat_loop (client , bucket_id , poll_time , strategy , exclude_title = False ):
4965 while True :
@@ -55,23 +71,26 @@ def heartbeat_loop(client, bucket_id, poll_time, strategy, exclude_title=False):
5571 current_window = get_current_window (strategy )
5672 logger .debug (current_window )
5773 except Exception as e :
58- logger .error ("Exception thrown while trying to get active window: {}" .format (e ))
74+ logger .error (
75+ "Exception thrown while trying to get active window: {}" .format (e )
76+ )
5977 traceback .print_exc ()
6078 current_window = {"app" : "unknown" , "title" : "unknown" }
6179
6280 now = datetime .now (timezone .utc )
6381 if current_window is None :
64- logger .debug (' Unable to fetch window, trying again on next poll' )
82+ logger .debug (" Unable to fetch window, trying again on next poll" )
6583 else :
6684 if exclude_title :
67- current_window ["title" ] = "excluded"
85+ current_window ["title" ] = "excluded"
6886
6987 current_window_event = Event (timestamp = now , data = current_window )
7088
7189 # Set pulsetime to 1 second more than the poll_time
7290 # This since the loop takes more time than poll_time
7391 # due to sleep(poll_time).
74- client .heartbeat (bucket_id , current_window_event ,
75- pulsetime = poll_time + 1.0 , queued = True )
92+ client .heartbeat (
93+ bucket_id , current_window_event , pulsetime = poll_time + 1.0 , queued = True
94+ )
7695
7796 sleep (poll_time )
0 commit comments