Skip to content

fix: Windows autostart self-healing and call-order safety#26

Closed
shiqkuangsan wants to merge 3 commits intomainfrom
claude/issue-25-20260324-0557
Closed

fix: Windows autostart self-healing and call-order safety#26
shiqkuangsan wants to merge 3 commits intomainfrom
claude/issue-25-20260324-0557

Conversation

@shiqkuangsan
Copy link
Copy Markdown
Owner

@shiqkuangsan shiqkuangsan commented Mar 24, 2026

Fixes #25

Changes:

  • Rust: On Windows startup, re-call enable() if DB has auto_start=true to repair registry entries deleted after first boot
  • TypeScript: For auto_start, call platform plugin first; only write DB/UI on success
  • TypeScript: After enable(), verify with isEnabled() and warn if verification fails
  • Tests: add isEnabled mock, assert DB not updated when plugin fails

Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Windows: performs conditional autostart self-healing during startup when the autostart setting is enabled.
    • Autostart changes are now verified with the platform before being saved; failures prevent persisting the preference and emit a warning.
  • Tests

    • Added and strengthened tests for enable/disable flows, verification failures, recovery, and negative cases for autostart handling.

- Rust (lib.rs): On Windows startup, if DB has auto_start=true, re-call
  autostart_manager().enable() to repair registry entries that are silently
  deleted after first boot (plugins-workspace#771)
- TypeScript (settings-store.ts): For auto_start, call the platform plugin
  first; only write to DB and update UI on success. This prevents the toggle
  from showing "enabled" when system registration actually failed.
- TypeScript (settings-store.ts): After enable(), verify with isEnabled()
  and warn to console if verification fails (e.g. path-spaces issue on Windows)
- Tests: add isEnabled mock, assert DB not updated when plugin fails

Co-authored-by: shiqkuangsan <shiqkuangsan@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recopy Ready Ready Preview, Comment Mar 24, 2026 6:27am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bfe3d5b4-0839-412f-b382-50c113402c53

📥 Commits

Reviewing files that changed from the base of the PR and between aa08d03 and b8f0302.

📒 Files selected for processing (1)
  • src-tauri/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src-tauri/src/lib.rs

📝 Walkthrough

Walkthrough

On Windows, startup now reads the DB auto_start setting and, if "true", calls the autostart plugin to re-register the registry entry before continuing initialization. The settings store now calls the autostart plugin first, verifies the result, and only persists DB/UI state on successful plugin completion; tests were updated.

Changes

Cohort / File(s) Summary
Backend Setup Logic
src-tauri/src/lib.rs
Added Windows-only startup self-healing: after DB init, read auto_start and call app.handle().autostart_manager().enable() when "true", logging success or warning on error. Runs before preview-state and platform/tray/clipboard init.
Settings Store Core Logic
src/stores/settings-store.ts
updateSetting treats auto_start specially: call plugin enable/disable first, verify isAutostartEnabled() after enable, and only invoke backend set_setting and update Zustand on plugin success. Plugin failures prevent DB/UI changes and emit warnings.
Test Coverage & Mocks
src/stores/__tests__/settings-store.test.ts
Extended autostart plugin mock with isEnabled() resolving true; updated default test settings; added/strengthened tests for enabling/disabling auto_start and a negative test where plugin-autostart.enable rejects to ensure no DB persistence or UI state flip on failure.

Sequence Diagram(s)

sequenceDiagram
    participant App as App Startup
    participant DB as Database
    participant Plugin as Autostart Plugin
    participant Registry as Windows Registry

    App->>DB: query `auto_start`
    alt DB == "true"
        DB-->>App: "true"
        App->>Plugin: enable()
        Plugin->>Registry: write/re-register entry
        Registry-->>Plugin: success
        Plugin-->>App: success
        App->>Plugin: isEnabled()
        Plugin->>Registry: verify entry
        Registry-->>Plugin: present
        Plugin-->>App: true
        App->>App: continue initialization
    else
        DB-->>App: "false" or null
        App->>App: skip autostart repair
    end
Loading
sequenceDiagram
    participant User as User
    participant UI as Settings UI
    participant Store as Settings Store
    participant Plugin as Autostart Plugin
    participant Backend as Backend (invoke)
    participant DB as Database

    User->>UI: toggle autostart -> true
    UI->>Store: updateSetting("auto_start","true")
    Store->>Plugin: enable()
    alt Plugin success
        Plugin-->>Store: resolved
        Store->>Plugin: isEnabled()
        Plugin-->>Store: true
        Store->>Backend: invoke("set_setting", {key:"auto_start", value:"true"})
        Backend->>DB: persist
        DB-->>Backend: ok
        Backend-->>Store: success
        Store->>UI: update state -> "true"
    else Plugin fails
        Plugin-->>Store: rejected
        Store->>UI: keep previous state
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰
I hop through startup, fixing registry seams,
I call the plugin first and guard the dreams,
Verify the entry, persist when true,
If it fails, I keep the old view,
A tiny rabbit mends autostart beams ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: Windows autostart self-healing on startup and call-order safety in settings persistence.
Linked Issues check ✅ Passed All objectives from issue #25 are met: startup self-healing on Windows (Rust), call-order fix with plugin-first approach (TypeScript), isEnabled() verification with warning, and test coverage for plugin failure scenarios.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing issue #25: Rust autostart initialization, TypeScript plugin call ordering, and test updates for autostart behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-25-20260324-0557

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/stores/__tests__/settings-store.test.ts (1)

33-46: Test DEFAULT_SETTINGS is missing show_tray_icon.

The DEFAULT_SETTINGS constant in this test file is missing the show_tray_icon property that exists in the actual Settings interface and DEFAULT_SETTINGS in settings-store.ts. While this may not break current tests, it could cause issues if future tests rely on a complete default settings object.

🔧 Suggested fix
 const DEFAULT_SETTINGS: Settings = {
   shortcut: "CommandOrControl+Shift+V",
   auto_start: "false",
   theme: "system",
   language: "system",
   retention_policy: "unlimited",
   retention_days: "0",
   retention_count: "0",
   max_item_size_mb: "10",
   close_on_blur: "true",
   update_check_interval: "weekly",
   panel_position: "bottom",
   flat_mode_tb: "false",
+  show_tray_icon: "true",
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/stores/__tests__/settings-store.test.ts` around lines 33 - 46, The test's
DEFAULT_SETTINGS object is missing the show_tray_icon property from the Settings
interface; update the DEFAULT_SETTINGS constant in
src/stores/__tests__/settings-store.test.ts to include show_tray_icon with the
same default value/type used in the real DEFAULT_SETTINGS in settings-store.ts
so the test object fully matches the Settings shape (refer to DEFAULT_SETTINGS
and Settings to locate the exact property name and expected default).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/stores/__tests__/settings-store.test.ts`:
- Around line 33-46: The test's DEFAULT_SETTINGS object is missing the
show_tray_icon property from the Settings interface; update the DEFAULT_SETTINGS
constant in src/stores/__tests__/settings-store.test.ts to include
show_tray_icon with the same default value/type used in the real
DEFAULT_SETTINGS in settings-store.ts so the test object fully matches the
Settings shape (refer to DEFAULT_SETTINGS and Settings to locate the exact
property name and expected default).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 553582d9-2162-42ff-a235-2e2d8ca42a3c

📥 Commits

Reviewing files that changed from the base of the PR and between f8a9399 and 7d89681.

📒 Files selected for processing (3)
  • src-tauri/src/lib.rs
  • src/stores/__tests__/settings-store.test.ts
  • src/stores/settings-store.ts

@shiqkuangsan
Copy link
Copy Markdown
Owner Author

@claude fix

@claude
Copy link
Copy Markdown

claude bot commented Mar 24, 2026

Claude finished @shiqkuangsan's task in 33s —— View job


Fix applied

  • Read relevant files
  • Add missing show_tray_icon to test DEFAULT_SETTINGS
  • Commit and push

Added show_tray_icon: "true" to DEFAULT_SETTINGS in src/stores/__tests__/settings-store.test.ts:46 to match the actual Settings interface in settings-store.ts.

Co-authored-by: shiqkuangsan <shiqkuangsan@users.noreply.github.com>
@shiqkuangsan
Copy link
Copy Markdown
Owner Author

@claude

CI failed. logs:

Run cargo check --target x86_64-pc-windows-msvc
Updating crates.io index
Compiling recopy v1.5.0 (D:\a\Recopy\Recopy\src-tauri)
warning: unused import: tauri_plugin_autostart::ManagerExt
--> src\lib.rs:102:21
|
102 | use tauri_plugin_autostart::ManagerExt;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] (part of #[warn(unused)]) on by default

error[E0599]: no method named autostart_manager found for mutable reference &mut tauri::App in the current scope
--> src\lib.rs:112:35
|
112 | match app.autostart_manager().enable() {
| ^^^^^^^^^^^^^^^^^ method not found in &mut tauri::App

For more information about this error, try rustc --explain E0599.
warning: recopy (lib) generated 1 warning
error: could not compile recopy (lib) due to 1 previous error; 1 warning emitted
Error: Process completed with exit code 1.

fix

@claude
Copy link
Copy Markdown

claude bot commented Mar 24, 2026

Claude finished @shiqkuangsan's task in 54s —— View job


Fix applied

  • Analyze CI error
  • Fix autostart_manager call — ManagerExt is implemented on AppHandle, not &mut App
  • Commit and push

Root cause: app.autostart_manager() was called on &mut tauri::App, but the ManagerExt trait is only implemented for AppHandle. Changed to app.handle().autostart_manager().enable() at src-tauri/src/lib.rs:112.

ManagerExt trait is implemented on AppHandle, not &mut App.

Co-authored-by: shiqkuangsan <shiqkuangsan@users.noreply.github.com>
@shiqkuangsan
Copy link
Copy Markdown
Owner Author

Closed — this PR has a compilation error on Windows:

error[E0599]: no method named `autostart_manager` found for reference `&AppHandle`
  --> src\lib.rs:112

The correct method is autolaunch() (from tauri_plugin_autostart::ManagerExt trait), not autostart_manager(). See plugin source: the trait defines fn autolaunch(&self) -> State<'_, AutoLaunchManager> with a TODO comment to rename it in v3.

Superseded by #27.

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.

fix: Windows autostart not working — registry self-healing on startup

1 participant