Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event_duration as a config parameter #50

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aw_watcher_window/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ def load_config():
default_client_config = ConfigParser()
default_client_config["aw-watcher-window"] = {
"exclude_title": False,
"poll_time": "1.0"
"poll_time": "1.0",
"event_duration": "0.0",
}
default_client_config["aw-watcher-window-testing"] = {
"exclude_title": False,
"poll_time": "1.0"
"poll_time": "1.0",
"event_duration": "0.0",
}

# TODO: Handle so aw-watcher-window testing gets loaded instead of testing is on
Expand Down
11 changes: 7 additions & 4 deletions aw_watcher_window/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def main():
config = load_config()
args = parse_args(
default_poll_time=config.getfloat("poll_time"),
default_event_duration=config.getfloat("event_duration"),
default_exclude_title=config.getboolean("exclude_title"),
)

Expand All @@ -39,26 +40,28 @@ def main():
bucket_id = "{}_{}".format(client.client_name, client.client_hostname)
event_type = "currentwindow"


client.create_bucket(bucket_id, event_type, queued=True)

logger.info("aw-watcher-window started")

sleep(1) # wait for server to start
with client:
heartbeat_loop(client, bucket_id, poll_time=args.poll_time, exclude_title=args.exclude_title)
heartbeat_loop(client, bucket_id, poll_time=args.poll_time, event_duration=args.event_duration, exclude_title=args.exclude_title)


def parse_args(default_poll_time: float, default_exclude_title: bool):
def parse_args(default_poll_time: float, default_event_duration: float, default_exclude_title: bool):
"""config contains defaults loaded from the config file"""
parser = argparse.ArgumentParser("A cross platform window watcher for Activitywatch.\nSupported on: Linux (X11), macOS and Windows.")
parser.add_argument("--testing", dest="testing", action="store_true")
parser.add_argument("--exclude-title", dest="exclude_title", action="store_true", default=default_exclude_title)
parser.add_argument("--verbose", dest="verbose", action="store_true")
parser.add_argument("--poll-time", dest="poll_time", type=float, default=default_poll_time)
parser.add_argument("--event-duration", dest="event_duration", type=float, default=default_event_duration)
return parser.parse_args()


def heartbeat_loop(client, bucket_id, poll_time, exclude_title=False):
def heartbeat_loop(client, bucket_id, poll_time, event_duration, exclude_title=False):
while True:
if os.getppid() == 1:
logger.info("window-watcher stopped because parent process died")
Expand All @@ -81,7 +84,7 @@ def heartbeat_loop(client, bucket_id, poll_time, exclude_title=False):
"app": current_window["appname"],
"title": current_window["title"] if not exclude_title else "excluded"
}
current_window_event = Event(timestamp=now, data=data)
current_window_event = Event(timestamp=now, data=data, duration=event_duration)

# Set pulsetime to 1 second more than the poll_time
# This since the loop takes more time than poll_time
Expand Down