Remove dead code, dead types and a redundant dependency - #223
Open
Pixnop wants to merge 8 commits into
Open
Conversation
The renderer runs in a secure context in both builds: packaged it loads app://renderer/index.html with the app scheme registered secure, and in dev it loads ELECTRON_RENDERER_URL on localhost, which is potentially trustworthy. crypto.randomUUID is available in both, so the uuid dependency bought nothing.
The file only re-exported the account parsers from the domain, and its own comment said it existed to keep a familiar import path. The four importers now point at @domain/account/credentials directly.
DownloadableModScreenshotType had no reference anywhere, and neither did the logofilename, logofile, trailervideourl, issuetrackerurl, wikiurl, tuype, lasmodified and screenshots fields on DownloadableModType. They described parts of the ModDB payload the launcher never looks at.
None of them held state or called a React API, so each was one indirection over a module function or the preload bridge. Call sites now import what the hook returned. useOpenExternalLink was the one exception worth naming: it wrapped the shared useExternalLinks hook, so its call sites now use that hook directly and keep the same useCallback-stable identity.
workerManager was passing an options object whose two values were exactly the pool's fallbacks, so the same numbers were written twice. The constants and the reasoning behind them now live next to the defaults in workerPool, and the call site just creates the pool. Tests still pass their own options.
INSTALLATION_NAME_MIN_LENGTH and INSTALLATION_NAME_MAX_LENGTH were exported and never imported, while the field, its hint text and both error messages spelled out 5 and 50 by hand. All three renderer sites now use the constants, so the input, the hint and the domain check cannot drift apart.
Only "progress" and "end" were ever passed. "all", "start" and "none" had no caller anywhere in the renderer, so the union now holds the two live modes. With those gone the success toast shows in both, which made showsSuccess a constant, so it is gone too; showsStart and showsError keep gating exactly what they gated before. The gating tests were passing the retired modes as filler and now pass a live one.
The renderer's initial reducer state listed the same fields as the main process default config, so adding a field meant remembering two places. The host-free part is now one domain constant that both spread, leaving each side with only what it alone can answer: the schema version and the three folder paths. Settling compressionLevel along the way. It read 4 in the config normalizer and in the compress IPC handler, and 6 in the add and edit forms and in the compression module. 6 is what users actually get: the add form proposes 6 and always sends a value, so every Installation made in the launcher carries 6, and the backup adapter always passes a level through, so the handler default never fires. The 4 only ever reached an Installation stored before the setting existed, which then compressed at a level the form never showed. One constant, set to 6.
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.
Eight small removals, one commit each, from a pass over the tree looking for things that exist without earning it.
The uuid dependency is gone: all six call sites used v4, and Node's own crypto.randomUUID does the same job in main and in the renderer, which is a secure context under both the packaged app protocol and the dev server. src/ipc/accountTypes.ts was a re-export shim whose own comment admitted it survived only as a familiar import path; its four importers now point at the domain type directly. Nine dead type names went out of global.d.ts, each grepped across src and tests first.
Seven hooks did nothing but forward a call, holding no state and touching no React API, so the call sites now use the underlying function. One of the seven did wrap a useCallback, and it went too because the four call sites keep the identical stable identity by calling that hook themselves. The worker pool was being handed two options that matched its own defaults, so the constants moved to the defaults and the call site is bare. Two name-length constants were exported from the domain and imported by nobody while three screens hardcoded the same numbers.
One item from the list was refused. modsFolder was said to have a single caller; it has two, and inlining it would duplicate the mods folder name between the domain and the renderer, which is the exact thing its own comment says it exists to prevent.
The last item found a real inconsistency rather than duplication. The default compression level read 4 in the config manager and the paths handler, and 6 in both forms and the compression worker. 6 is what every user actually has: the add form proposes 6 and always sends a value, and the backup adapter always passes a level, so the 4 was unreachable except for an installation stored before the field existed, which the normalizer quietly set to a level no screen ever offered. There is now one constant at 6, shared by both sides, and the test that pinned 4 pins the constant instead, so it fails against the old code.
Net on source: 36 files, 173 added and 268 removed.