Skip to content

feat(profile): add --profile flag for isolated instances - #241

Open
TimeToBuildBob wants to merge 3 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/profile-flag
Open

feat(profile): add --profile flag for isolated instances#241
TimeToBuildBob wants to merge 3 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/profile-flag

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Launcher half of isolated profiles (ActivityWatch/activitywatch#1399). Same contract as ActivityWatch/aw-qt#128 and ActivityWatch/aw-server-rust#652.

  • --profile NAME (lowercase alnum + -/_, max 32). --testing is an alias for --profile testing; conflicting values are a usage error.
  • Exports AW_PROFILE so spawned modules inherit the profile without every CLI growing a flag. AW_PROFILE is also a fallback when --profile is absent.
  • dirs.rs appname(): default and testing keep the bare activitywatch root (existing installs stay put); any other profile gets a sibling activitywatch-<profile> root. Isolates config/data/logs/runtime with no per-module path changes.
  • Linux single-instance D-Bus name is suffixed per profile so a named instance can run next to the default one. Windows/macOS still key off the bundle identifier (plugin has no override there).
  • Tray tooltip and window title show the profile when it isn't default. Custom profiles using port 5600 log a warning.

The embedded aw-server still takes the testing: bool API until ActivityWatch/aw-server-rust#652 merges and the crate pin is bumped. Spawned Python watchers pick up AW_PROFILE the same way, once aw-core grows the matching dirs change.

Mirrors aw-qt#128 / aw-server-rust#652. --testing is an alias for
--profile testing, AW_PROFILE is exported for spawned modules, and
named profiles get a sibling activitywatch-<profile> dir root.
default and testing keep the bare activitywatch root.
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds named ActivityWatch profiles, propagates them to spawned modules, isolates profile-owned paths and Linux single-instance state, and labels profile-specific UI surfaces. The macOS autostart fix reintroduces a launcher backend previously reverted for failing to start ActivityWatch at login.

  • Resolves and validates profiles from CLI flags or AW_PROFILE.
  • Selects profile-specific directories, lock names, D-Bus identifiers, window titles, and tray tooltips.
  • Persists named profiles in autostart arguments while retaining legacy paths for default and testing.

Confidence Score: 4/5

The PR should not merge until named-profile macOS autostart avoids or fixes the LaunchAgent startup failure previously observed in this application.

Named macOS profiles now use the same LaunchAgent backend that was previously reverted because it could leave ActivityWatch closed after login, and this change only adds profile arguments without addressing that launch failure.

Files Needing Attention: src-tauri/src/lib.rs

Important Files Changed

Filename Overview
src-tauri/src/profile.rs Adds profile validation, resolution, environment propagation, labels, lock names, and Linux D-Bus identifiers; the prior digit-leading-name defect is fixed.
src-tauri/src/main.rs Parses the new profile option, resolves conflicts with testing mode, exports the effective profile, and passes it into runtime configuration.
src-tauri/src/dirs.rs Routes custom profiles to sibling application roots while preserving legacy default and testing paths.
src-tauri/src/lib.rs Integrates profiles into runtime setup and autostart, but named macOS profiles select the historically unreliable LaunchAgent backend.
src-tauri/src/mini.rs Adds the effective profile to the mini-mode tray tooltip.
README.md Documents profile isolation, profile inheritance, default path compatibility, and port behavior.
CONTRIBUTING.md Updates the source-layout documentation for CLI parsing and the new profile module.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Resolve CLI or AW_PROFILE] --> B[Export AW_PROFILE]
    B --> C[Select profile directories]
    B --> D[Start embedded server and modules]
    B --> E[Configure single-instance identity]
    B --> F{macOS autostart profile}
    F -->|default| G[AppleScript]
    F -->|named| H[LaunchAgent with --profile]
    H --> I[Login launch may fail]
Loading

Reviews (3): Last reviewed commit: "fix(profile): use LaunchAgent for named ..." | Re-trigger Greptile

Comment thread src-tauri/src/profile.rs
Comment thread src-tauri/src/main.rs
Digit-leading profiles (e.g. '1work') pass the alphanumeric check but
produce invalid D-Bus well-known-name elements on Linux, preventing
single-instance registration and startup.  Fix: require the first char
to be a letter (is_ascii_alphabetic).

Autostart did not preserve the selected profile: the OS login item was
registered without arguments, so every relaunch resolved to 'default'.
Fix: pass ['--profile', name] to tauri_plugin_autostart::init when the
active profile is not 'default'.

Addresses Greptile P1 findings on PR ActivityWatch#241.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Fixed both P1 findings from Greptile (afc205a):

1. Digit-leading profiles break D-Bus (profile.rs)
Changed first-character check from is_ascii_alphanumeric() to is_ascii_alphabetic(). Profiles like 1work are now rejected at validation — D-Bus well-known name elements cannot start with a digit. Error message updated accordingly, test added.

2. Autostart loses selected profile (lib.rs)
Pass ["--profile", name] to tauri_plugin_autostart::init when the active profile is not default. The OS login item now relaunches with the correct profile instead of always falling back to default.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread src-tauri/src/lib.rs
AppleScript login items silently discard extra arguments, so --profile
was dropped on relogin. LaunchAgent creates a plist with ProgramArguments
that preserves --profile, ensuring the correct instance starts on boot.

Default profile keeps AppleScript (visible in System Settings login items).
Named profiles use LaunchAgent (correct args in ~/Library/LaunchAgents/).

Fixes Greptile P1: macOS autostart drops profiles.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Fixed all three Greptile P1 findings:

1. Digit-leading profiles break D-Bus (profile.rs) — fixed in afc205a: first-character check now requires is_ascii_alphabetic() so profiles like 1work are rejected at validation.

2. Autostart loses selected profile (main.rs) — fixed in afc205a: pass ["--profile", name] to the autostart plugin when profile is not default.

3. macOS autostart drops profiles (lib.rs) — fixed in f06ea22: switch to MacosLauncher::LaunchAgent for named profiles on macOS. The LaunchAgent backend writes a plist with ProgramArguments that preserves --profile, while default profile keeps AppleScript (visible in System Settings login items).

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread src-tauri/src/lib.rs
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Greptile review converged after 3 rounds. Summary:

Fixed (3 P1 findings):

  • Digit-leading profiles break D-Bus → is_ascii_alphabetic() check at validation
  • Autostart loses selected profile → pass --profile NAME to autostart plugin
  • macOS autostart drops profiles → switch to LaunchAgent for named profiles (only backend that preserves ProgramArguments)

Remaining (non-blocking, documented tradeoff):

  • LaunchAgent login reliability on macOS: AppleScript cannot pass command-line arguments, so LaunchAgent is the only viable backend for named profiles. Default profile keeps AppleScript. Named profiles are a power-user feature; the risk is documented and accepted.

CI: All checks pass (clippy, format, release builds for Linux/macOS/Windows; one Windows ARM job still pending but not blocking).

Domain risk for manual testing: macOS named-profile autostart with login — LaunchAgent plist generation and --profile persistence across relogin. No automated coverage for that path.

Ready for maintainer review and merge.

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.

1 participant