Skip to content

fix(manager): detect .bat and .cmd executables and strip extensions on Windows#126

Merged
ErikBjare merged 3 commits intoActivityWatch:masterfrom
TimeToBuildBob:dev/detect-bat-cmd-windows-exes
Mar 16, 2026
Merged

fix(manager): detect .bat and .cmd executables and strip extensions on Windows#126
ErikBjare merged 3 commits intoActivityWatch:masterfrom
TimeToBuildBob:dev/detect-bat-cmd-windows-exes

Conversation

@TimeToBuildBob
Copy link
Contributor

Closes/completes #81.

Changes

  1. is_executable() — adds .bat and .cmd as recognised executable extensions on Windows (original commit from fix: detect .bat and .cmd executables on Windows #81).
  2. _filename_to_name() — also strips .bat / .cmd extensions so discovered modules get the right names (aw-server not aw-server.cmd). Without this, autostart matching, module exclusion, and start-by-name lookups would all break. This was the remaining bug flagged by Greptile in fix: detect .bat and .cmd executables on Windows #81.

Why a new PR

The branch on the ActivityWatch org (dev/detect-bat-cmd-windows-exes) is Erik's and I don't have push access, so the fix is on my fork instead. Supersedes #81.

Testing

Manual verification that _filename_to_name now returns the correct name for all three Windows launcher extensions:

aw-server.exe  -> aw-server  ✓
aw-server.cmd  -> aw-server  ✓
aw-server.bat  -> aw-server  ✓
aw-server      -> aw-server  ✓  (non-Windows / no extension)

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR fixes Windows module discovery by recognizing .bat and .cmd executables in addition to .exe. Two functions are updated:

  • is_executable() now returns True for .bat and .cmd files on Windows, allowing these launchers to be discovered as modules.
  • _filename_to_name() now strips .bat and .cmd extensions (in addition to .exe) on Windows, so module names like aw-server are derived correctly instead of producing aw-server.cmd. Without this fix, autostart matching, module exclusion, and start-by-name lookups would all break for .bat/.cmd-based modules.

The new _filename_to_name implementation is also more robust than the old one: it uses endswith() + slicing instead of str.replace(), which avoids false positives from .exe appearing mid-filename. Minor whitespace and quote-style cleanups are included.

Confidence Score: 5/5

  • This PR is safe to merge — it makes a small, well-scoped fix with no risk of regression on non-Windows platforms.
  • The changes are minimal, logically correct, and platform-guarded behind platform.system() == "Windows" checks. Both is_executable and _filename_to_name are updated consistently. The new _filename_to_name is strictly more correct than the old str.replace approach. No new dependencies, no architectural changes, and the fix directly addresses the reported bug.
  • No files require special attention.

Important Files Changed

Filename Overview
aw_qt/manager.py Adds .bat and .cmd as recognized Windows executables in is_executable(), and updates _filename_to_name() to strip those extensions so module names are correct. Also includes minor whitespace/quote style fixes. Logic is sound and consistent across both discovery paths (bundled and system).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Discover modules in directory] --> B{Is file?}
    B -->|No| C[Skip or recurse into subdirectory]
    B -->|Yes| D{is_executable?}
    D -->|No| E[Log warning: not executable]
    D -->|Yes| F[_filename_to_name]
    F --> G{Windows?}
    G -->|Yes| H{Extension?}
    H -->|.exe| I[Strip .exe]
    H -->|.bat| J[Strip .bat]
    H -->|.cmd| K[Strip .cmd]
    H -->|Other| L[Return filename as-is]
    G -->|No| L
    I --> M[Create Module with clean name]
    J --> M
    K --> M
    L --> M
    M --> N[Add to modules list]
Loading

Last reviewed commit: db7c37e

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@ErikBjare ErikBjare merged commit ac043b0 into ActivityWatch:master Mar 16, 2026
3 checks passed
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