fix(desktop): keep the preload bridge alive under the sandbox

Deciding whether the OS can back glass needs os.release(), but every
Hermes window runs its preload with sandbox: true, where require is a
polyfill limited to electron, events, timers and url. The node:os import
threw before contextBridge ran, so window.hermesDesktop was never defined
and the app booted straight into "Desktop IPC bridge is unavailable".

Main already computes both verdicts, so preload asks for them over a
synchronous channel instead. No reply degrades to no glass, which is an
ordinary opaque window rather than a page thinned over nothing.
This commit is contained in:
Brooklyn Nicholson
2026-08-19 02:52:20 -05:00
parent 8a918bdc64
commit a8d87ac1d9
3 changed files with 40 additions and 4 deletions
+19
View File
@@ -50,6 +50,25 @@ test.describe('dev-mode boot with mock backend', () => {
})
})
// A preload that throws never reaches contextBridge, so the renderer boots
// into "Desktop IPC bridge is unavailable" and every test below it dies on a
// 120s never-became-ready timeout instead. Checking the bridge by name makes
// that failure legible. The sandbox lets preload require only electron,
// events, timers and url — adding any other node builtin lands here.
test('the preload bridge reaches the renderer', async () => {
const bridge = await fixture!.page.evaluate(() => {
const desktop = (window as unknown as { hermesDesktop?: Record<string, unknown> }).hermesDesktop
return {
present: typeof desktop,
glassSupported: typeof desktop?.glassSupported,
translucencySupported: typeof desktop?.translucencySupported
}
})
expect(bridge).toEqual({ present: 'object', glassSupported: 'boolean', translucencySupported: 'boolean' })
})
test('backend boots and app becomes ready', async () => {
// This is the big one — wait for the full boot chain to complete:
// electron starts → hermes serve is spawned → WS connects → config
+11
View File
@@ -306,6 +306,7 @@ import {
glassActive,
glassSupportedOn,
normalizeState as normalizeTranslucency,
translucencySupportedOn,
vibrancyFor as vibrancyForTranslucency,
windowBackingOptions,
windowOpacityFor
@@ -402,6 +403,9 @@ const DARWIN_MAJOR = IS_MAC ? Number.parseInt(os.release(), 10) || 0 : 0
// Glass: macOS vibrancy, or Windows 11 22H2+ system backdrop. Computed once
// so the renderer, the persisted default, and every chat window agree.
const GLASS_SUPPORTED = glassSupportedOn(process.platform, os.release())
// Clear rides setOpacity, a documented no-op on Linux, so neither mode works
// there and Settings drops the row entirely.
const TRANSLUCENCY_SUPPORTED = translucencySupportedOn(process.platform)
const APP_ROOT = app.getAppPath()
// Device-local preference: block F12 from opening DevTools.
@@ -14106,6 +14110,13 @@ app.on('before-quit', () => {
}
})
// Answered synchronously so preload can publish the verdict before the
// renderer's first script — see the note there on why it cannot decide this
// itself. Registered at module scope, which runs long before any window.
ipcMain.on('hermes:translucency:support', event => {
event.returnValue = { glass: GLASS_SUPPORTED, translucency: TRANSLUCENCY_SUPPORTED }
})
ipcMain.on('hermes:translucency', (_event, payload) => {
const next = normalizeTranslucency(payload, GLASS_SUPPORTED)
const previous = translucencyState
+10 -4
View File
@@ -1,11 +1,17 @@
import { contextBridge, ipcRenderer, webFrame, webUtils } from 'electron'
import os from 'node:os'
import { glassSupportedOn, translucencySupportedOn } from '../../shared/src/translucency'
// Which translucency the OS can back. Asked synchronously because the renderer
// needs it before its first paint, and answered by main because deciding it
// needs `os.release()` — a sandboxed preload may only require electron, events,
// timers and url, so importing node:os here throws before contextBridge runs
// and takes the ENTIRE bridge down with it (window.hermesDesktop undefined =>
// "Desktop IPC bridge is unavailable"). No reply means no glass, which degrades
// to an ordinary opaque window rather than a page thinned over nothing.
const translucencySupport = ipcRenderer.sendSync('hermes:translucency:support')
contextBridge.exposeInMainWorld('hermesDesktop', {
glassSupported: glassSupportedOn(process.platform, os.release()),
translucencySupported: translucencySupportedOn(process.platform),
glassSupported: translucencySupport?.glass === true,
translucencySupported: translucencySupport?.translucency === true,
getConnection: profile => ipcRenderer.invoke('hermes:connection', profile),
// Registry-scoped backend resolution: { connectionId, profile } → descriptor.
getConnectionFor: payload => ipcRenderer.invoke('hermes:connection:for', payload),