Skip to content

fix(autostart): Windows self-healing and plugin-first call order#27

Merged
shiqkuangsan merged 2 commits intomainfrom
fix/windows-autostart-healing
Mar 24, 2026
Merged

fix(autostart): Windows self-healing and plugin-first call order#27
shiqkuangsan merged 2 commits intomainfrom
fix/windows-autostart-healing

Conversation

@shiqkuangsan
Copy link
Copy Markdown
Owner

@shiqkuangsan shiqkuangsan commented Mar 24, 2026

Summary

  • Rust: On Windows startup, re-call enable() if DB has auto_start=true to repair registry entries silently deleted after first boot (upstream plugins-workspace#771)
  • TypeScript: For auto_start, call platform plugin first; only write DB/UI on success — prevents false "enabled" state
  • TypeScript: After enable(), verify with isEnabled() and warn if verification fails
  • Tests: Add isEnabled mock, assert DB not updated when plugin fails, verify UI state consistency

Test plan

  • npx tsc --noEmit passes
  • npx vitest run — 270 tests pass (1 new)
  • cargo test — 38 tests pass
  • Windows manual test: toggle autostart, reboot, verify app launches

Fixes #25

Summary by CodeRabbit

  • Bug Fixes

    • Added automatic self-healing for autostart settings during Windows startup, ensuring database state matches actual system configuration.
    • Autostart setting now validates actual plugin state after enabling to prevent configuration misalignment.
  • New Features

    • Platform-specific HUD rendering: macOS displays normally while non-macOS systems show frosted-glass background effect.

…acOS

Windows lacks macOS hudWindow effect, leaving the HUD fully transparent.
Add platform-conditional rendering: macOS keeps native frosted glass,
Windows gets self-drawn bg-black/50-60 + backdrop-blur-xl fallback.

Closes: https://gitee.com/shiqkuangsan/Recopy/issues/IG02HT
- Rust setup(): re-register autostart on Windows if DB says enabled,
  compensating for registry entries lost after reboot (upstream bug)
- settings-store: call enable()/disable() BEFORE persisting to DB,
  so plugin failure prevents stale UI state
- settings-store: verify with isEnabled() after enable, warn on mismatch
- Add test for plugin failure preventing DB write

Closes #25
@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:39am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This PR addresses Windows autostart failures by implementing startup self-healing (re-enabling autostart on app launch), reordering plugin operations to precede database persistence, and applying OS-specific UI styling adjustments for non-macOS platforms.

Changes

Cohort / File(s) Summary
Windows Startup Self-Healing
src-tauri/src/lib.rs
Added Windows-only autostart recovery during app setup: reads auto_start database setting and calls app.autolaunch().enable() if set to "true", with success/error logging.
Settings Store Refactoring
src/stores/settings-store.ts
Reordered auto_start control flow to invoke plugin operations before persisting to database; added isAutostartEnabled() verification after enable and explicit error handling without fallback persistence.
Test Coverage Expansion
src/stores/__tests__/settings-store.test.ts
Extended autostart mocks with isEnabled(), updated existing tests to verify plugin invocation order and state consistency, and added new test case for plugin failure scenarios.
Cross-Platform UI Styling
src/App.tsx
Added OS detection to conditionally apply frosted-glass styling and text colors to HUD container on non-macOS platforms; macOS rendering remains unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant App as App Startup
    participant DB as Database
    participant Plugin as Autostart Plugin
    participant Log as Logger

    App->>DB: Query auto_start setting
    DB-->>App: Returns "true" or "false"
    
    alt auto_start = "true"
        App->>Plugin: Call enable()
        Plugin-->>App: Success/Error
        
        alt Enable succeeded
            App->>Log: Log info message
        else Enable failed
            App->>Log: Log warn message
        end
    else auto_start = "false"
        Note over App: No action taken
    end
Loading
sequenceDiagram
    participant UI as Settings UI
    participant Store as Zustand Store
    participant Plugin as Autostart Plugin
    participant DB as Database

    UI->>Store: updateSetting("auto_start", value)
    
    alt auto_start = "true"
        Store->>Plugin: Call enableAutostart()
        Plugin-->>Store: Success/Error
        
        alt Enable succeeded
            Store->>Plugin: Call isAutostartEnabled()
            Plugin-->>Store: Enabled state
            
            alt State matches
                Store->>DB: invoke("set_setting", {key, value})
                DB-->>Store: Persisted
                Store->>Store: Update local state
            else State mismatch
                Store->>Store: console.warn()
                Note over Store: State persisted but system mismatch
            end
        else Enable failed
            Store->>Store: console.error()
            Note over Store: Return without persistence
        end
    else auto_start = "false"
        Store->>Plugin: Call disableAutostart()
        Plugin-->>Store: Success/Error
        
        alt Disable succeeded
            Store->>DB: invoke("set_setting", {key, value})
            DB-->>Store: Persisted
            Store->>Store: Update local state
        else Disable failed
            Store->>Store: console.error()
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A Hoppy Fix
Windows lost its startup dance,
So we grant the app a second chance—
On every boot, a healing spell,
Plugin first, then database's bell!
No more vanished registry tears,
Just autostart through the years! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main changes: Windows self-healing for autostart and correcting the plugin call order.
Linked Issues check ✅ Passed All coding requirements from issue #25 are met: startup self-healing on Windows, plugin-first call order in settings-store, isEnabled() verification with warnings, and test coverage for plugin failure scenarios.
Out of Scope Changes check ✅ Passed The HUD platform-specific styling change in src/App.tsx is a minor cosmetic fix for Windows appearance and aligns with addressing the autostart issue scope.

✏️ 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 fix/windows-autostart-healing

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 (2)
src/App.tsx (1)

244-244: Consider hoisting platform() call outside the component or memoizing it.

platform() is synchronous and returns a constant value that never changes during the app's lifetime. Calling it on every render is wasteful, albeit cheap. Consider moving it outside the component:

♻️ Suggested refactor
+const isMac = platform() === "macos";
+
 function HudApp() {
   const { t } = useTranslation();
   const loadSettings = useSettingsStore((s) => s.loadSettings);
-  const isMac = platform() === "macos";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/App.tsx` at line 244, The call to platform() is being invoked on every
render to compute const isMac = platform() === "macos"; — hoist this call
outside the React component (e.g., compute a top-level const PLATFORM =
platform(); const isMac = PLATFORM === "macos";) or memoize it with useMemo if
it must stay inside the component; update references to use the new top-level
PLATFORM/isMac variable so platform() is not executed on each render and
behavior remains identical.
src/stores/__tests__/settings-store.test.ts (1)

33-46: Consider adding show_tray_icon to test DEFAULT_SETTINGS for consistency.

The test's DEFAULT_SETTINGS is missing the show_tray_icon property that exists in the actual store defaults (line 41 in settings-store.ts). While this doesn't break tests due to beforeEach state reset, keeping them in sync improves maintainability.

🔧 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
DEFAULT_SETTINGS object used in the test is missing the show_tray_icon property
present in the real store defaults; update the test's DEFAULT_SETTINGS constant
to include show_tray_icon with the same default value used in settings-store.ts
so the test defaults mirror the store (locate DEFAULT_SETTINGS in
src/stores/__tests__/settings-store.test.ts and add the show_tray_icon key/value
to match the store).
🤖 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/App.tsx`:
- Line 244: The call to platform() is being invoked on every render to compute
const isMac = platform() === "macos"; — hoist this call outside the React
component (e.g., compute a top-level const PLATFORM = platform(); const isMac =
PLATFORM === "macos";) or memoize it with useMemo if it must stay inside the
component; update references to use the new top-level PLATFORM/isMac variable so
platform() is not executed on each render and behavior remains identical.

In `@src/stores/__tests__/settings-store.test.ts`:
- Around line 33-46: The DEFAULT_SETTINGS object used in the test is missing the
show_tray_icon property present in the real store defaults; update the test's
DEFAULT_SETTINGS constant to include show_tray_icon with the same default value
used in settings-store.ts so the test defaults mirror the store (locate
DEFAULT_SETTINGS in src/stores/__tests__/settings-store.test.ts and add the
show_tray_icon key/value to match the store).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6fdcb16e-e8c0-4fd9-87e9-c06a5050c742

📥 Commits

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

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

@shiqkuangsan shiqkuangsan merged commit 55d7f9c into main Mar 24, 2026
10 checks passed
@shiqkuangsan shiqkuangsan deleted the fix/windows-autostart-healing branch March 24, 2026 06:54
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