Skip to content

Commit 5002b32

Browse files
committed
Adding config option for macos strategy
1 parent 9bcafc2 commit 5002b32

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

aw_watcher_window/config.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
from configparser import ConfigParser
2+
import argparse
23

34
from aw_core.config import load_config as _load_config
45

5-
66
def load_config():
77
default_client_config = ConfigParser()
8-
default_client_config["aw-watcher-window"] = {
9-
"exclude_title": False,
10-
"poll_time": "1.0"
11-
}
12-
default_client_config["aw-watcher-window-testing"] = {
8+
default_client_config["aw-watcher-window"] = default_client_config["aw-watcher-window-testing"] = {
139
"exclude_title": False,
14-
"poll_time": "1.0"
10+
"poll_time": "1.0",
11+
"macos_strategy": "jxa"
1512
}
1613

1714
# TODO: Handle so aw-watcher-window testing gets loaded instead of testing is on
1815
return _load_config("aw-watcher-window", default_client_config)["aw-watcher-window"]
16+
17+
def parse_args():
18+
config = load_config()
19+
20+
default_poll_time = config.getfloat("poll_time")
21+
default_exclude_title = config.getboolean("exclude_title")
22+
default_macos_strategy = config.get("macos_strategy")
23+
24+
parser = argparse.ArgumentParser("A cross platform window watcher for Activitywatch.\nSupported on: Linux (X11), macOS and Windows.")
25+
parser.add_argument("--testing", dest="testing", action="store_true")
26+
parser.add_argument("--exclude-title", dest="exclude_title", action="store_true", default=default_exclude_title)
27+
parser.add_argument("--verbose", dest="verbose", action="store_true")
28+
parser.add_argument("--poll-time", dest="poll_time", type=float, default=default_poll_time)
29+
parser.add_argument("--macos-strategy", dest="macos_strategy", default=default_macos_strategy, choices=["jxa", "applescript"])
30+
return parser.parse_args()

aw_watcher_window/main.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
import logging
32
import traceback
43
import sys
@@ -11,24 +10,19 @@
1110
from aw_client import ActivityWatchClient
1211

1312
from .lib import get_current_window
14-
from .config import load_config
13+
from .config import parse_args
1514

1615
logger = logging.getLogger(__name__)
1716

1817
# enable this line for easier debugging
1918
# logger.setLevel(logging.DEBUG)
2019

2120
def 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.\nSupported 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

Comments
 (0)