Skip to content

The agent that grows with you

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

Brooklyn Nicholsona8d87ac1d9e0
diff --git a/apps/desktop/e2e/boot.spec.ts b/apps/desktop/e2e/boot.spec.ts
index 3a74fa4cc53..19f2d81fa45 100644
--- a/apps/desktop/e2e/boot.spec.ts
+++ b/apps/desktop/e2e/boot.spec.ts
@@ -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
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index c4746fc3134..d4e3fcf1654 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -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
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 1296d08ff9c..2d1ba597cec 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -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),