hermes-agent/apps/desktop/electron/updates-ipc.cjs
Brooklyn Nicholson c147270a1c refactor(desktop): extract auto-update IPC handlers from main.cjs into updates-ipc.cjs
Fourth main.cjs cluster peel. The four hermes:updates:* handlers (check, apply,
branch:get, branch:set) move verbatim into electron/updates-ipc.cjs behind a
registerUpdatesIpc({ ipcMain, checkUpdates, applyUpdates, readDesktopUpdateConfig,
writeDesktopUpdateConfig, DEFAULT_UPDATE_BRANCH }) registrar. The update engine
and on-disk update config stay in the main process and are injected.

Channel names unchanged → preload + renderer untouched. The interleaved
resolveHermesVersion/showAboutPanelFresh helpers + hermes:version handler are
shared with the menu and intentionally left in place. Adds
electron/updates-ipc.test.cjs (surface invariant + branch default fallback +
check-failure payload).
2026-06-30 13:29:38 -05:00

41 lines
1.2 KiB
JavaScript

'use strict'
// Auto-update IPC: check / apply / branch get+set. The update engine
// (checkUpdates/applyUpdates) and the on-disk update config live in the main
// process and are injected, so this module owns only the request wiring.
function registerUpdatesIpc({
applyUpdates,
checkUpdates,
DEFAULT_UPDATE_BRANCH,
ipcMain,
readDesktopUpdateConfig,
writeDesktopUpdateConfig
}) {
ipcMain.handle('hermes:updates:check', async () =>
checkUpdates().catch(error => ({
supported: true,
branch: readDesktopUpdateConfig().branch,
error: 'check-failed',
message: error?.message || String(error),
fetchedAt: Date.now()
}))
)
ipcMain.handle('hermes:updates:apply', async (_event, payload) =>
applyUpdates(payload || {}).catch(error => ({
ok: false,
error: 'apply-failed',
message: error?.message || String(error)
}))
)
ipcMain.handle('hermes:updates:branch:get', async () => readDesktopUpdateConfig())
ipcMain.handle('hermes:updates:branch:set', async (_event, name) => {
const branch = typeof name === 'string' && name.trim() ? name.trim() : DEFAULT_UPDATE_BRANCH
writeDesktopUpdateConfig({ branch })
return { branch }
})
}
module.exports = { registerUpdatesIpc }