Skip to content

refactor(electron): split main.ts into deep FileOperations/SettingsStore/Updater modules - #26

Merged
killerwolf merged 1 commit into
mainfrom
claude/deepen-electron-backend
Sep 2, 2026
Merged

refactor(electron): split main.ts into deep FileOperations/SettingsStore/Updater modules#26
killerwolf merged 1 commit into
mainfrom
claude/deepen-electron-backend

Conversation

@killerwolf

Copy link
Copy Markdown
Owner

Summary

  • main.ts's QuickTossApp mixed five concerns — window lifecycle, IPC handler logic, folder-scan logic, settings persistence, and auto-updater orchestration — none of it unit-testable without a real Electron process
  • Extract three deep modules:
    • electron/file-operations.tsscanFolder/moveToTrash/getFileStats/fileExists/readFileAsBuffer as plain, window-free async functions, with a shared logAndRethrow helper codifying the error-handling policy (rethrow when there's no safe fallback, return a default when there is)
    • electron/settings-store.ts — a createSettingsStore(settingsPath) factory, taking the path as a parameter instead of computing it internally, so it's testable against a temp directory instead of the real userData folder
    • electron/updater.ts — auto-updater orchestration, its file logger, and openReleasePage, all window-free (takes an onStatus callback instead of touching BrowserWindow/webContents directly)
  • main.ts keeps only window lifecycle and selectFolder (the one handler needing mainWindow), wiring the extracted modules' functions directly into the IPC handlers object
  • Collapses a duplicated DEFAULT_SETTINGS object (previously defined twice, verbatim) into one shared constant
  • Updates CONTRIBUTING.md's project layout and test-coverage notes to match

Test plan

  • npm run typecheck passes (all 3 configs)
  • npm test — 39/39 tests pass (14 new: file-operations.test.ts covers scanFolder/getFileStats/fileExists/readFileAsBuffer against real temp directories, no fs mocking; settings-store.test.ts covers the round-trip and corrupted-file fallback)
  • npm run build — Vite + Electron compile cleanly
  • npx biome check clean on changed files
  • Reviewed against CONTRIBUTING.md standards and the original design (two-axis review); moveToTrash and updater.ts deliberately left untested — shell.trashItem and electron-updater's real update flow don't behave meaningfully outside a real Electron main process

🤖 Generated with Claude Code

…ore/Updater modules

main.ts's QuickTossApp mixed five concerns — window lifecycle, IPC handler
logic, folder-scan business logic, settings persistence, and auto-updater
orchestration — none of it unit-testable without an Electron process.

Extract three modules:
- file-operations.ts: scanFolder/moveToTrash/getFileStats/fileExists/
  readFileAsBuffer as plain, window-free async functions
- settings-store.ts: createSettingsStore(settingsPath) factory, taking the
  path as a parameter instead of computing it from app.getPath("userData")
  internally, so it's testable against a temp directory
- updater.ts: auto-updater orchestration, its file logger, and
  openReleasePage, all window-free — it takes an onStatus callback instead
  of touching BrowserWindow/webContents directly

main.ts keeps only window lifecycle and selectFolder (the one handler that
needs mainWindow), and wires the extracted modules' functions directly into
the IPC handlers object.

Adds real tests for file-operations.ts and settings-store.ts against temp
directories (no fs mocking, matching file-types.test.ts's style).
moveToTrash and updater.ts are left untested — shell.trashItem and
electron-updater's real update flow don't behave meaningfully outside a
real Electron main process.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@killerwolf
killerwolf merged commit 1091d16 into main Sep 2, 2026
2 checks passed
@killerwolf
killerwolf deleted the claude/deepen-electron-backend branch September 2, 2026 14:07
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.

1 participant