Repository navigation
fix(tray): persist module start/stop to [autostart] modules - #285
Conversation
|
@greptileai review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 623b849bbd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
🤖 AI code reviewThis PR adds a new config_edit module that edits [autostart] modules in the user's config.toml in place using toml_edit, so tray toggles of modules persist across restarts. It also routes aw-notify clicks through the settings flag rather than the modules list, makes all config writes atomic via a new write_atomic function (temp file + rename with symlink resolution), and refactors handle_system_click to return an Option<bool> so unknown modules are ignored and module changes are persisted. GUI and mini mode now share a single handle_module_menu_click entry point. Safe to merge — no P0/P1 findingsConfidence 5/5
✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads. 1 advisory finding (summary-only, not scored)These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.
This is a How this was verified: static preflight: fix-commit + touched-files scan (rule 7) Files changed (6) — the diff as I read it
Previous review passes
Reviewed Maintainer commands
|
* test: isolate platform dirs in all tests, not just XDG on Linux The xdg_tmp fixture only sets XDG_*_HOME, which platformdirs ignores on macOS and Windows. There, test_profile_config.py wrote its fixture files into the real ActivityWatch config dirs (aw-qt.toml, aw-server.toml, aw-server-rust/config.toml, ...), overwriting the user's config. An autouse fixture now points platformdirs' user dirs into tmp_path on every platform, laid out like the XDG dirs so existing tests are unchanged. * feat(tray): persist module start/stop to autostart_modules A module started or stopped from the tray now stays that way after a restart: the click adds the module to, or removes it from, autostart_modules in aw-qt.toml. Mirrors ActivityWatch/aw-tauri#285. - Only explicit menu clicks persist. Crash auto-restarts, the restart dialog and shutdown call Module.start/stop directly and never write. - aw-server and aw-server-rust are never written, so stopping the server from the tray can't leave the next start without one. - With --autostart-modules the run isn't using the configured list, so toggles only change what is running. - The file is re-read right before each write and edited in place with tomlkit (comments and layout kept), in the same file and section AwQtSettings reads for the profile. A file that fails to parse is left untouched and the failure logged. Writes are atomic and follow symlinks. - Enable appends, disable removes; order is kept and no duplicates are added. A section without the key (the commented-out first-run file) gets the effective default list with the change applied. * fix(tray): address review: UTF-8 I/O, shadowed system copies, slot safety - Read and write aw-qt.toml as UTF-8 with newline="" (keeps line endings); an undecodable file is logged and left untouched. - Don't persist a click on a system module that a bundled copy of the same name shadows: autostart_modules holds names, and autostart runs the bundled copy. Manager.resolve() is the shared lookup. - Catch any error from persisting so it can't escape the Qt slot. - Skip the symlink test where symlinks can't be created (Windows).
623b849 to
df4b4ba
Compare
|
@greptileai review @TimeToBuildBob review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df4b4ba6fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@greptileai review @TimeToBuildBob review |
|
@greptileai review @TimeToBuildBob review |
Starting or stopping a module from the tray (GUI and mini mode) now adds it to or removes it from `[autostart] modules` in config.toml, so the choice survives a restart. Previously a tray toggle only lasted for the session, and removed watchers came back on the next launch. The file is re-read and edited in place with toml_edit, so comments and hand edits are preserved; a malformed file is left untouched. Removing an entry with inline args moves them to `[module_args]`. Writes share the autostart PERSIST_LOCK. Tray clicks on undiscovered modules are ignored.
- Edit `[[autostart.modules]]` tables as well as inline `modules = [...]` arrays; an emptied array of tables is written back as `modules = []`. - Keep comments on and around entries exactly once when adding or removing, with or without a trailing comma, and in single-line arrays. - When removing an entry with inline args, its args replace any existing `[module_args]` value (they were the ones in effect). - aw-notify clicks in the Modules menu (GUI and mini) now go through the `settings.aw-notify.enabled` flag like the "Enable notifications" toggle, and are never written to `[autostart]`. At launch aw-notify follows the flag alone: started when it is on (even if unlisted), skipped when off. - Write the config atomically (temp file + rename, keeping permissions and writing through symlinks), for tray edits, the autostart toggle and write_formatted_config. - Move the config-editing code into config_edit.rs.
…ling config symlinks When a module is listed more than once, removing it saves the last entry's args (the effective ones, per configured_modules_args) to [module_args], not the first's, for both list forms. write_atomic resolves symlinks with read_link instead of canonicalize, so a config.toml that links to a not-yet-created file keeps the link and gets its target created on first run.
… args case Keep the manager state lock held while saving a Modules-menu toggle, so saves can never be reordered relative to the toggles that caused them. Add a test for a module listed twice where only the earlier entry has args: removal saves those args over the [module_args] value.
d39dd4b to
c9af666
Compare
Addresses a user report with two halves:
1. Tray toggles now persist (fixed here)
handle_system_clickonly changed the running state, so a tray toggle lasted for the session and the module came back on the next launch. Now, in both the GUI and mini mode, a tray start or stop adds the module to, or removes it from,[autostart] modulesinconfig.toml(newsrc-tauri/src/config_edit.rs).toml_edit. Comments, layout and hand edits made while the app runs are kept. Comments on and around entries stay exactly once when adding or removing, with or without a trailing comma.modules = [...](names and{ name, args }) and[[autostart.modules]]tables.[module_args], replacing any existing value there, since the inline args were the ones in effect. A later manual start still uses them.write_formatted_config. Writes shareautostart::PERSIST_LOCK.aw-notify
aw-notify's autostart is governed by the shared
settings.aw-notify.enabledopt-in flag (ActivityWatch/activitywatch#1435: single source of truth, managers start it if and only if it is set). So a Modules-menu click on aw-notify now goes through the same path as the "Enable notifications" toggle: write the flag, then start or stop it. It is never written to[autostart]. At launch aw-notify now follows the flag alone: it is started when the flag is on, even if unlisted, and skipped when it is off, even if listed. Previously it also had to be listed, so the dedicated toggle didn't survive a restart either.2. Hand-edited removals reverting to defaults (root cause; not changed here)
This isn't caused by the config path or the per-profile path. Default and testing profiles still use the legacy
activitywatch/aw-tauri/config.tomlroot, and the defaults are only written when the file is missing. The cause is the parse-failure fallback inget_config()(src-tauri/src/lib.rs:603-615on master):UserConfig::default()for the whole session, which on macOS/Windows (and on Linux without aw-awatcher) is["aw-watcher-afk", "aw-watcher-window"](lib.rs:535, 568).AutostartConfig.moduleshas no#[serde(default)](lib.rs:482), so the most natural ways to "remove" the watchers trigger that fallback. I checked withtoml::from_str::<UserConfig>:modules = [\n]modules = [\n "aw-awatcher",\n](trailing comma)modulesline deleted or commented outmissing field modules, so defaults are used[ , ])[autostart]section deletedmissing field autostart, so defaults are usedFollow-up fix (separate PR): add
#[serde(default)]onAutostartConfig.modules(and onautostartitself) so a missing list means "start nothing". On a real syntax error, don't autostart the default watchers: keep the defaults for port and paths but start no modules, and say so in the tray or notification instead of a one-off dialog.With this PR, users no longer need to hand-edit the file to disable watchers. Also, the tray never writes over a malformed file.
Tests
config_edit::tests: one-per-line, single-line and array-of-tables edits; comments before, inside and after entries (with and without a trailing comma); inline args winning over[module_args]; a malformed config left alone;write_atomic(replace, create, no temp leftovers, symlink write-through). All of these use scratch dirs under the system temp dir and never the real config dir.manager::tests:autostart_names_follow_notify_opt_inandtray_click_on_unknown_module_is_ignored.cargo fmt --check,cargo clippy --all-targets -D warningsandcargo test --lib(60 tests) pass locally.