Skip to content

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

Merged
ErikBjare merged 3 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/profile-flag
Aug 31, 2026
Merged

feat(profile): add --profile flag for isolated instances#241
ErikBjare merged 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

The PR adds validated named profiles and propagates the selected profile through process environment, storage paths, single-instance handling, autostart registration, and desktop labels.

  • Adds --profile and AW_PROFILE resolution, including compatibility with --testing.
  • Isolates configuration, data, logs, runtime state, and Linux single-instance identity for custom profiles.
  • Preserves named-profile arguments in autostart registration and displays the active profile in window and tray labels.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src-tauri/src/profile.rs Adds profile validation, resolution, environment propagation, single-instance identifiers, and profile-aware labels; the prior digit-leading D-Bus issue is fixed.
src-tauri/src/main.rs Resolves and exports the effective profile before storing CLI state and entering the shared runtime.
src-tauri/src/lib.rs Integrates profiles into startup, autostart, Linux single-instance handling, lock-file signaling, logging, and desktop labels.
src-tauri/src/dirs.rs Selects profile-specific platform directory roots while preserving legacy roots for default and testing profiles.
src-tauri/src/mini.rs Adds the active profile to the mini-mode tray tooltip.
README.md Documents named-profile isolation, profile inheritance, port behavior, and the environment-variable fallback.
CONTRIBUTING.md Updates the source-layout documentation for CLI handling and the new profile module.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CLI --profile or AW_PROFILE] --> B[Validate and resolve profile]
    B --> C[Export AW_PROFILE]
    C --> D[Select profile directories]
    C --> E[Spawn modules]
    C --> F[Configure single-instance identity]
    C --> G[Configure autostart arguments]
    C --> H[Label window and tray]
Loading

Reviews (4): 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.

@ErikBjare

Copy link
Copy Markdown
Member

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@ErikBjare
ErikBjare merged commit 03cb62b into ActivityWatch:master Aug 31, 2026
8 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