fix: persist context bar settings across restarts#67
Conversation
Flush pending debounced persistence writes before app close and route context bar setting updates through a dedicated hook so the latest settings survive shutdown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR implements context bar settings persistence with debounced writes. It adds a new hook to manage setting updates, introduces a debounced write system in the persistence API with a flush mechanism, updates the context bar popover component to use the hook, integrates flush-before-close logic into the app close flow, and provides comprehensive test coverage across all new functionality. Changes
Sequence DiagramssequenceDiagram
participant App as App/TauriApp
participant Hook as useContextBarSettings
participant PersistenceAPI as Persistence API
participant Store as Settings Store
App->>Hook: Mount component
Hook->>PersistenceAPI: read(CONTEXT_BAR_SETTINGS_KEY)
PersistenceAPI-->>Hook: Return persisted settings or defaults
Hook->>Store: Update store with loaded settings
Hook->>App: Mark isLoaded=true
Note over App,Store: Settings ready for UI
sequenceDiagram
participant User as User
participant UI as ContextBarSettingsPopover
participant Hook as useUpdateContextBarSetting
participant PersistenceAPI as Persistence API (Debounced)
participant Store as Settings Store
User->>UI: Toggle switch
UI->>Hook: Call updater(settingKey)
Hook->>Store: Toggle setting value
Hook->>PersistenceAPI: writeDebounced(KEY, settings)
Note over PersistenceAPI: Schedule debounce timer (if first call for KEY)
PersistenceAPI-->>Hook: Return promise
Hook-->>UI: Promise resolves
Note over PersistenceAPI: On debounce timer: flush writes, resolve all pending promises
sequenceDiagram
participant Window as Window Close Event
participant WorkspaceLayout as WorkspaceLayout
participant PersistenceAPI as Persistence API
participant WindowAPI as Window API
Window->>WorkspaceLayout: Close requested
WorkspaceLayout->>WorkspaceLayout: Check dirty files
alt No dirty files
WorkspaceLayout->>PersistenceAPI: flushPendingWrites()
PersistenceAPI-->>WorkspaceLayout: Flush completes (or fails)
else Has dirty files
WorkspaceLayout->>WorkspaceLayout: Prompt user (save/discard)
Note over WorkspaceLayout: After user chooses...
WorkspaceLayout->>PersistenceAPI: flushPendingWrites()
PersistenceAPI-->>WorkspaceLayout: Flush completes (or fails)
end
WorkspaceLayout->>WindowAPI: respondToClose('close')
Note over Window,WindowAPI: App closes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/TauriApp.test.tsx (1)
10-14: Partial mock may cause issues if otherpersistenceApimethods are called.The mock only provides
read, but ifTauriAppor any of its non-mocked children call otherpersistenceApimethods (likewriteDebouncedorflushPendingWrites), the test will fail with "undefined is not a function" errors.Consider extending the mock to include other commonly used methods, or verify that all code paths calling other methods are properly mocked out:
💡 Suggested mock expansion
vi.mock('@/lib/api', () => ({ persistenceApi: { - read: mockPersistenceRead + read: mockPersistenceRead, + writeDebounced: vi.fn(() => Promise.resolve({ success: true, data: undefined })), + flushPendingWrites: vi.fn(() => Promise.resolve({ success: true, data: undefined })) } }))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/renderer/TauriApp.test.tsx` around lines 10 - 14, The test mock for persistenceApi only defines read, which can cause failures if TauriApp or its children call other methods; update the vi.mock in TauriApp.test.tsx to provide stub implementations (e.g., vi.fn()) for other commonly used persistenceApi methods such as writeDebounced, flushPendingWrites, write, readAll/getAll (and any other methods used by components), or switch to a full module mock that delegates to the real module while overriding read; reference the mocked object name persistenceApi and the test file's vi.mock block when making the change.
🤖 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/renderer/TauriApp.test.tsx`:
- Around line 10-14: The test mock for persistenceApi only defines read, which
can cause failures if TauriApp or its children call other methods; update the
vi.mock in TauriApp.test.tsx to provide stub implementations (e.g., vi.fn()) for
other commonly used persistenceApi methods such as writeDebounced,
flushPendingWrites, write, readAll/getAll (and any other methods used by
components), or switch to a full module mock that delegates to the real module
while overriding read; reference the mocked object name persistenceApi and the
test file's vi.mock block when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 40818b09-0f06-4f3b-9bb9-37b650abfb79
📒 Files selected for processing (12)
src/renderer/App.test.tsxsrc/renderer/TauriApp.test.tsxsrc/renderer/components/ContextBarSettingsPopover.test.tsxsrc/renderer/components/ContextBarSettingsPopover.tsxsrc/renderer/hooks/use-context-bar-settings.test.tssrc/renderer/hooks/use-context-bar-settings.tssrc/renderer/layouts/WorkspaceLayout.close-persistence.test.tsxsrc/renderer/layouts/WorkspaceLayout.tsxsrc/renderer/lib/__tests__/api-bridge.test.tssrc/renderer/lib/__tests__/tauri-persistence-api.test.tssrc/renderer/lib/tauri-persistence-api.tssrc/shared/types/ipc.types.ts
Summary
flushPendingWriteson the shared persistence API contractTest plan
npm --prefix \"E:/open-source/PecutAPP/termul-fix-context-bar-settings-persistence\" test -- src/renderer/lib/__tests__/tauri-persistence-api.test.ts src/renderer/hooks/use-context-bar-settings.test.ts src/renderer/lib/__tests__/api-bridge.test.ts src/renderer/components/ContextBarSettingsPopover.test.tsx src/renderer/TauriApp.test.tsx src/renderer/layouts/WorkspaceLayout.close-persistence.test.tsx src/renderer/App.test.tsxnpm --prefix \"E:/open-source/PecutAPP/termul-fix-context-bar-settings-persistence\" run typecheck🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests