1- import argparse
21import logging
32import traceback
43import sys
1110from aw_client import ActivityWatchClient
1211
1312from .lib import get_current_window
14- from .config import load_config
13+ from .config import parse_args
1514
1615logger = logging .getLogger (__name__ )
1716
1817# enable this line for easier debugging
1918# logger.setLevel(logging.DEBUG)
2019
2120def main ():
22- # Read settings from config
23- config = load_config ()
24- args = parse_args (
25- default_poll_time = config .getfloat ("poll_time" ),
26- default_exclude_title = config .getboolean ("exclude_title" ),
27- )
28-
2921 if sys .platform .startswith ("linux" ) and ("DISPLAY" not in os .environ or not os .environ ["DISPLAY" ]):
3022 raise Exception ("DISPLAY environment variable not set" )
3123
24+ args = parse_args ()
25+
3226 setup_logging (name = "aw-watcher-window" , testing = args .testing , verbose = args .verbose ,
3327 log_stderr = True , log_file = True )
3428
@@ -47,27 +41,17 @@ def main():
4741
4842 sleep (1 ) # wait for server to start
4943 with client :
50- heartbeat_loop (client , bucket_id , poll_time = args .poll_time , exclude_title = args .exclude_title )
51-
52-
53- def parse_args (default_poll_time : float , default_exclude_title : bool ):
54- """config contains defaults loaded from the config file"""
55- parser = argparse .ArgumentParser ("A cross platform window watcher for Activitywatch.\n Supported on: Linux (X11), macOS and Windows." )
56- parser .add_argument ("--testing" , dest = "testing" , action = "store_true" )
57- parser .add_argument ("--exclude-title" , dest = "exclude_title" , action = "store_true" , default = default_exclude_title )
58- parser .add_argument ("--verbose" , dest = "verbose" , action = "store_true" )
59- parser .add_argument ("--poll-time" , dest = "poll_time" , type = float , default = default_poll_time )
60- return parser .parse_args ()
61-
44+ heartbeat_loop (client , bucket_id ,
45+ poll_time = args .poll_time , exclude_title = args .exclude_title , macos_strategy = args .macos_strategy )
6246
63- def heartbeat_loop (client , bucket_id , poll_time , exclude_title = False ):
47+ def heartbeat_loop (client , bucket_id , poll_time , macos_strategy , exclude_title = False ):
6448 while True :
6549 if os .getppid () == 1 :
6650 logger .info ("window-watcher stopped because parent process died" )
6751 break
6852
6953 try :
70- current_window = get_current_window ()
54+ current_window = get_current_window (macos_strategy = macos_strategy )
7155 logger .debug (current_window )
7256 except Exception as e :
7357 logger .error ("Exception thrown while trying to get active window: {}" .format (e ))
0 commit comments