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

[Feature] Add exclude_titles feature for enhanced window title exclusion #99

Merged
merged 7 commits into from
May 13, 2024

Conversation

0xErwin1
Copy link
Contributor

@0xErwin1 0xErwin1 commented Feb 4, 2024

This commit introduces the --exclude-titles argument to the aw-watcher-window module, allowing users to specify a list of window titles or regular expression patterns to exclude from tracking. This new feature is designed to complement the existing --exclude-title flag, providing enhanced flexibility for users who need to exclude multiple window titles without breaking compatibility with existing configurations.

Key Changes:

  • Added the --exclude-titles argument to the argparse configuration in config.py, enabling the specification of multiple exclusion patterns.
  • Updated the heartbeat_loop function in main.py to support both exclude_title and exclude_titles, with exclude_titles allowing for an array of titles to be excluded.
  • Utilized the re module for regex pattern matching against window titles, ensuring case-insensitive comparisons.

This enhancement ensures that users can now more precisely control which window titles are excluded from tracking, making the aw-watcher-window module more versatile and user-friendly.

This commit introduces the `--exclude-titles` argument to the aw-watcher-window module,
allowing users to specify a list of window titles or regular expression patterns to exclude from tracking.
This new feature is designed to complement the existing `--exclude-title` flag,
providing enhanced flexibility for users who need to exclude multiple window titles
without breaking compatibility with existing configurations.

Key Changes:
- Added the `--exclude-titles` argument to the argparse configuration in `config.py`, enabling the specification of multiple exclusion patterns.
- Updated the `heartbeat_loop` function in `main.py` to support both `exclude_title` and `exclude_titles`, with `exclude_titles` allowing for an array of titles to be excluded.
- Utilized the `re` module for regex pattern matching against window titles, ensuring case-insensitive comparisons.

This enhancement ensures that users can now more precisely control which window titles are excluded from tracking,
making the aw-watcher-window module more versatile and user-friendly.
@0xErwin1 0xErwin1 closed this Feb 6, 2024
@0xErwin1 0xErwin1 deleted the feature/exclude-titles branch February 6, 2024 09:53
@0xErwin1 0xErwin1 restored the feature/exclude-titles branch February 6, 2024 09:53
@0xErwin1 0xErwin1 reopened this Feb 6, 2024
@0xErwin1
Copy link
Contributor Author

0xErwin1 commented May 7, 2024

I have been using this feature since I opened this PR and have not had any problems so far

aw_watcher_window/main.py Outdated Show resolved Hide resolved
if exclude_titles:
for title in exclude_titles:
pattern = re.compile(re.escape(title), re.IGNORECASE)
if pattern.search(current_window["title"]):
Copy link
Member

@ErikBjare ErikBjare May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you are treating all strings as regexes? This might confuse some users given the help string "List of window titles or regular expression patterns".

aw_watcher_window/main.py Outdated Show resolved Hide resolved
@0xErwin1 0xErwin1 requested a review from ErikBjare May 7, 2024 10:17
aw_watcher_window/main.py Outdated Show resolved Hide resolved
@0xErwin1 0xErwin1 requested a review from ErikBjare May 7, 2024 12:03
@@ -92,10 +93,11 @@ def main():
poll_time=args.poll_time,
strategy=args.strategy,
exclude_title=args.exclude_title,
exclude_titles=[re.compile(re.escape(title), re.IGNORECASE) for title in args.exclude_titles]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you escaping this? If you are escaping, then it's not really matching a regex, as all regex-special characters (.[]()+*? etc) would be escaped and wouldn't work (iirc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because it is the way that worked for me in all cases, but it is perfectly possible to remove it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean "all cases"? This breaks regex functionality completely. Perhaps you used a bad regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not so much that they are bad regex, but that by putting part of a title it excludes it, but without escaping the characters it works the same.

@ErikBjare
Copy link
Member

@ellipsis-dev Can you review this, and the re.escape part specifically? Doesn't it neuter actual regexes?

ellipsis-dev bot added a commit that referenced this pull request May 8, 2024
…tles` feature for enhanced window title exclusion);
Copy link

ellipsis-dev bot commented May 8, 2024

@ErikBjare, I have addressed your comments in pull request #102

@ErikBjare
Copy link
Member

ErikBjare commented May 8, 2024

It seems Ellipsis wanted to put the compile in a try/except, which is probably a good idea (although it messed up the syntax).
But, unlike what it did in its PR, it should print a warning if regex fails to compile (maybe even exit(1)), not silently escape the pattern.

@0xErwin1 0xErwin1 requested a review from ErikBjare May 13, 2024 12:11
Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks :)

@ErikBjare ErikBjare merged commit 76c85c6 into ActivityWatch:master May 13, 2024
5 checks passed
@@ -30,6 +31,13 @@
except ProcessLookupError:
logger.info("Process {} already dead".format(pid))

def try_compile_title_regex(title):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants