|
1 | | -from configparser import ConfigParser |
2 | 1 | import argparse |
3 | 2 |
|
4 | | -from aw_core.config import load_config as _load_config |
| 3 | +from aw_core.config import load_config_toml |
| 4 | + |
| 5 | + |
| 6 | +default_config = """ |
| 7 | +[aw-watcher-window] |
| 8 | +exclude_title = false |
| 9 | +poll_time = 1.0 |
| 10 | +strategy_macos = "jxa" |
| 11 | +""".strip() |
| 12 | + |
5 | 13 |
|
6 | 14 | def load_config(): |
7 | | - default_client_config = ConfigParser() |
8 | | - default_client_config["aw-watcher-window"] = default_client_config["aw-watcher-window-testing"] = { |
9 | | - "exclude_title": False, |
10 | | - "poll_time": "1.0", |
11 | | - "strategy_macos": "jxa" |
12 | | - } |
| 15 | + return load_config_toml("aw-watcher-window", default_config)["aw-watcher-window"] |
13 | 16 |
|
14 | | - # TODO: Handle so aw-watcher-window testing gets loaded instead of testing is on |
15 | | - return _load_config("aw-watcher-window", default_client_config)["aw-watcher-window"] |
16 | 17 |
|
17 | 18 | def parse_args(): |
18 | 19 | config = load_config() |
19 | 20 |
|
20 | | - default_poll_time = config.getfloat("poll_time") |
21 | | - default_exclude_title = config.getboolean("exclude_title") |
22 | | - default_strategy_macos = config.get("strategy_macos") |
| 21 | + default_poll_time = config["poll_time"] |
| 22 | + default_exclude_title = config["exclude_title"] |
| 23 | + default_strategy_macos = config["strategy_macos"] |
23 | 24 |
|
24 | | - parser = argparse.ArgumentParser("A cross platform window watcher for Activitywatch.\nSupported on: Linux (X11), macOS and Windows.") |
| 25 | + parser = argparse.ArgumentParser( |
| 26 | + "A cross platform window watcher for Activitywatch.\nSupported on: Linux (X11), macOS and Windows." |
| 27 | + ) |
25 | 28 | 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) |
| 29 | + parser.add_argument( |
| 30 | + "--exclude-title", |
| 31 | + dest="exclude_title", |
| 32 | + action="store_true", |
| 33 | + default=default_exclude_title, |
| 34 | + ) |
27 | 35 | 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("--strategy", dest="strategy", default=default_strategy_macos, choices=["jxa", "applescript"], help="(macOS only) strategy to use for retrieving the active window") |
| 36 | + parser.add_argument( |
| 37 | + "--poll-time", dest="poll_time", type=float, default=default_poll_time |
| 38 | + ) |
| 39 | + parser.add_argument( |
| 40 | + "--strategy", |
| 41 | + dest="strategy", |
| 42 | + default=default_strategy_macos, |
| 43 | + choices=["jxa", "applescript"], |
| 44 | + help="(macOS only) strategy to use for retrieving the active window", |
| 45 | + ) |
30 | 46 | parsed_args = parser.parse_args() |
31 | 47 | return parsed_args |
0 commit comments