refactor(electron): split main.ts into deep FileOperations/SettingsStore/Updater modules - #26
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
main.ts'sQuickTossAppmixed 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 processelectron/file-operations.ts—scanFolder/moveToTrash/getFileStats/fileExists/readFileAsBufferas plain, window-free async functions, with a sharedlogAndRethrowhelper codifying the error-handling policy (rethrow when there's no safe fallback, return a default when there is)electron/settings-store.ts— acreateSettingsStore(settingsPath)factory, taking the path as a parameter instead of computing it internally, so it's testable against a temp directory instead of the realuserDatafolderelectron/updater.ts— auto-updater orchestration, its file logger, andopenReleasePage, all window-free (takes anonStatuscallback instead of touchingBrowserWindow/webContentsdirectly)main.tskeeps only window lifecycle andselectFolder(the one handler needingmainWindow), wiring the extracted modules' functions directly into the IPC handlers objectDEFAULT_SETTINGSobject (previously defined twice, verbatim) into one shared constantCONTRIBUTING.md's project layout and test-coverage notes to matchTest plan
npm run typecheckpasses (all 3 configs)npm test— 39/39 tests pass (14 new:file-operations.test.tscoversscanFolder/getFileStats/fileExists/readFileAsBufferagainst real temp directories, no fs mocking;settings-store.test.tscovers the round-trip and corrupted-file fallback)npm run build— Vite + Electron compile cleanlynpx biome checkclean on changed filesmoveToTrashandupdater.tsdeliberately left untested —shell.trashItemand electron-updater's real update flow don't behave meaningfully outside a real Electron main process🤖 Generated with Claude Code