refactor: split main/index.ts monolith into IPC handler modules#214
Conversation
Extract 124 IPC handlers from single 3046-line file into 10 domain modules in apps/desktop/src/main/handlers/: | Module | Lines | Handlers | |---------------------|-------|---------------------------------------| | noteHandlers.ts | 429 | notes:*, tags:*, links:*, embeds:* | | notebookHandlers.ts | 311 | notebooks:* | | authSyncHandlers.ts | 583 | auth:*, sync:*, encryption:*, etc. | | pluginHandlers.ts | 410 | pluginConfig:*, plugins:* | | dataHandlers.ts | 207 | data:* (backup, export, import) | | gitHandlers.ts | 154 | git:* | | updateHandlers.ts | 132 | updates:* + auto-updater init | | logHandlers.ts | 53 | log:* | | aiKeyHandlers.ts | 36 | ai:saveKey/getKey/removeKey/hasKey | | types.ts | 62 | Shared dependency interfaces | index.ts reduced from 3046 → 887 lines (bootstrap + window management). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughRefactors the Electron main process IPC handlers from a monolithic implementation into modular handler registrations. Extracts handlers for AI keys, auth/sync, data management, git operations, logging, notes, notebooks, plugins, and updates into dedicated modules with dependency injection, reducing Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d315334290
ℹ️ 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".
| broadcastToWindows, | ||
| }); | ||
| registerShareHandlers({ apiClient }); | ||
| registerAiKeyHandlers({ aiKeyStorage }); |
There was a problem hiding this comment.
Register AI key IPC handlers during startup bootstrap
ai:*Key handlers are now only registered inside initAuthSync() after several awaited initialization steps, so renderer calls can hit “No handler registered” if that async setup is still in progress or if auth/sync init fails. In the previous layout these handlers were always registered and returned safe defaults when storage wasn’t ready, so this refactor introduces a runtime regression for AI settings flows in those startup/error paths.
Useful? React with 👍 / 👎.
…oliths (#215) ## Summary Splits the 4 remaining monolithic files into focused modules. | File | Before | After | Modules | |------|--------|-------|---------| | `preload/index.ts` | 1,227 | 161 | 14 API modules in `preload/api/` | | `App.tsx` | 1,010 | 643 | 4 hooks extracted | | `PluginsSection.tsx` | 1,043 | 11 (barrel) | PluginCard, BrowseTab, PluginInspector | | `syncService.ts` | 1,065 | 18 (barrel) | types, helpers, SyncService class | Combined with PR #214 (main/index.ts split), all 5 monoliths are resolved: - **main/index.ts**: 3,046 → 887 - **preload/index.ts**: 1,227 → 161 - **App.tsx**: 1,010 → 643 - **PluginsSection.tsx**: 1,043 → 11 - **syncService.ts**: 1,065 → 18 No behavior changes — purely structural. ## Test plan - [x] `pnpm typecheck` — 17/17 pass - [x] `pnpm test` — 16/16 pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
#217) ## Patch v0.12.1 Critical fixes since v0.12.0: ### Bug Fixes - **Fix "Object has been destroyed" crash on update** — safe broadcast helper with double isDestroyed check + try/catch (#213) - **Move single-instance lock before whenReady()** — prevents secondary instances from initializing DB/IPC (#216) ### Architecture Refactor - **main/index.ts**: 3,046 → 887 lines (10 IPC handler modules) (#214) - **preload/index.ts**: 1,227 → 161 lines (14 API modules) (#215) - **App.tsx**: 1,010 → 643 lines (4 hooks extracted) (#215) - **PluginsSection.tsx**: 1,043 → 11 lines (3 sub-components) (#215) - **syncService.ts**: 1,065 → 18 lines (types + helpers extracted) (#215) ### CI Improvements - Fix Linux build: expanded cache cleanup, removed corrupted fpm (#212) - Remove broken dart-actions/tweet action (#210) - Node.js 24 via FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 (#212) - Branch protection configured on develop + main (#216) ## Test plan - [x] `pnpm typecheck` — 17/17 pass - [x] `pnpm test` — 16/16 pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary
Splits the 3046-line monolithic
main/index.tsinto 10 focused handler modules.Before
index.ts: 3,046 lines, 124 IPC handlers, 18 domains mixed togetherAfter
index.ts: 887 lines (bootstrap + window management only)handlers/with clear domain boundariesFollows the existing pattern from
licenseHandlers.tsandshareHandlers.ts.No logic changes — purely structural.
Test plan
pnpm typecheck— 17/17 passpnpm test— 16/16 pass🤖 Generated with Claude Code
Summary by CodeRabbit