fix: refactored electron-main.js#473
Merged
Merged
Conversation
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Refactor of
src/frontend/src/electron/electron-main.js(the Electron mainprocess) in two passes. No behavior change — same IPC channels, same response
shapes, same lifecycle.
Before: 1 file, 1958 lines.
After:
electron-main.js1216 lines +ipc-handlers.js509 lines.What changed
Pass 1 — in-file deduplication
defineConfigField(key, getChannel, setChannel, opts)— replaces14 inline
ipcMain.handleblocks that all followed the sameread-config / mutate / write-config pattern (boolean flags, model directory,
transparent proxy, entity confidence).
backendRequest(method, path, body?)— replaces 4 hand-rollednet.requestPromise blocks (reload-model, get-model-info, transparent-proxynotify, entity-confidence notify).
notifyBackendBestEffort(path, body)for the "save succeeded so don'tsurface backend errors" pattern.
applyTrayIcon/resolveTrayIconInfo— the tray icon resolution(template-vs-color, darwin resize, tooltip) was duplicated between
createTray()and theautoUpdaterupdate-downloadedhandler.require("electron").shell.openExternal(...)calls —shellwas already imported at the top.getResourcesPath()— theif (darwin)branch and the fallbackreturned the exact same expression.
Pass 2 — module split
ipc-handlers.jsexportsregisterIpcHandlers({ ... }).ipcMain.handlechannels moved over, along with their helpers(
backendRequest,notifyBackendBestEffort,defineConfigField,VALID_PROVIDERS— none of these are used outside IPC code).readConfig,saveConfig,encryptApiKey,decryptApiKey,restartGoBinary,waitForBackend,getMainWindow) so thenew module never imports from
electron-main.js.getMainWindowis passedas an accessor (
() => mainWindow) sincemainWindowis reassigned acrossthe app lifecycle.
electron-main.jsno longer needsipcMainin itselectronrequire.Behavior note
One subtle shift worth flagging: the simple-field IPC handlers (e.g.
set-welcome-dismissed) now go throughreadConfig()/saveConfig()insteadof doing raw
fs.readFileSynconconfig.json. That means setting one ofthese flags also runs the legacy → multi-provider config migration if the user
is on a pre-migration config. The migration is idempotent and was already
triggered by every API-key handler, so this only changes when it runs for
users who never touched provider settings — not the resulting state.
Test plan
npm run electron:devboots, splash → main window appears, backendreaches
/health.backend, confirm provider config persists.
receives the updates (or that we still report success if it doesn't).
ca.crtexists and when it doesn't yet).Email / Quit) all work.
flags persist.
update-downloadedevent (or wait for one) and verify the trayicon swaps to the update variant.