hermes-agent/apps/desktop/electron/gateway-stop-before-update.ts
ethernet 00a9dbc60b fix(desktop): eslint import order + padding after the origin/main merge
The merge landed main's `minimize-to-tray` and `hud-modifier-types` modules next to
ours, leaving two `perfectionist/sort-imports` errors — the only blocking failures in
the `JS & TS checks` job (`apps/desktop :: check:lint`):

  electron/main.ts:321      ./minimize-to-tray before ./native-auth-decisions
  src/global.d.ts:6         ../electron/hud-modifier-types before ../electron/machine-profile

Resolved with the workspace's own `npm run fix` (eslint --fix + prettier), which also
pads the `padding-line-between-statements` warnings it can. Lint is 0 errors after.
2026-09-21 17:50:44 -04:00

59 lines
1.8 KiB
TypeScript

/** Windows uninstall delegates fleet draining to the CLI before deleting files. */
import { execFileSync, type ExecFileSyncOptionsWithStringEncoding } from 'node:child_process'
import fs from 'node:fs'
export interface StopGatewayBeforeUpdateDeps {
/** Defaults to process.platform === 'win32'; injectable for tests. */
isWindows?: boolean
/** Defaults to fs.existsSync; injectable for tests. */
existsSync?: (p: string) => boolean
/** Defaults to execFileSync from node:child_process; injectable for tests. */
execFileSync?: (command: string, args: string[], options: ExecFileSyncOptionsWithStringEncoding) => Buffer | string
/** Observability hook for tests. */
spy?: (command: string, args: string[]) => void
}
export const GATEWAY_STOP_TIMEOUT_MS = 20_000
/** Best-effort all-profile drain for uninstall. The deletion lock gate follows. */
export function stopGatewayBeforeUpdate(
hermesCliPath: string,
hermesHome: string,
deps: StopGatewayBeforeUpdateDeps = {}
): boolean {
return runGatewayLifecycleCommand(hermesCliPath, ['gateway', 'stop', '--all'], deps)
}
function runGatewayLifecycleCommand(hermesCliPath: string, args: string[], deps: StopGatewayBeforeUpdateDeps): boolean {
const isWindows = deps.isWindows ?? process.platform === 'win32'
if (!isWindows) {
return false
}
const existsSync = deps.existsSync ?? fs.existsSync
const exec = deps.execFileSync ?? execFileSync
if (deps.spy) {
deps.spy(hermesCliPath, args)
}
if (!existsSync(hermesCliPath)) {
return false
}
try {
exec(hermesCliPath, args, {
timeout: GATEWAY_STOP_TIMEOUT_MS,
windowsHide: true,
stdio: 'ignore',
encoding: 'utf8'
})
return true
} catch {
// Best-effort (see header comment).
return false
}
}