The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve Windows backing after material changes (#141702)
Gille0b10b9f8155a
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 1eac74c94cd..d6433c1c1d4 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -579,7 +579,7 @@ import { installSystemCaTrust } from './system-ca'import { registerTerminalIpc } from './terminal-ipc'import { nativeOverlayWidth as computeNativeOverlayWidth, titleBarOverlayOptions } from './titlebar-overlay-width'import {- backgroundMaterialFor,+ applyWindowsBackdrop,defaultTranslucencyState,glassActive,glassSupportedOn,@@ -1582,21 +1582,16 @@ function applyWindowTranslucency(win, changed = { backing: true, material: true,// Backing swap + material are scoped to registered chat windows (see// translucencyBackedWindows above).if (translucencyBackedWindows.has(win)) {- if (changed.backing && typeof win.setBackgroundColor === 'function') {- win.setBackgroundColor(glassActive(translucencyState) ? '#00000000' : getWindowBackgroundColor())- }-- if (changed.material) {- // Glass frost level = the platform material. Animate the macOS hop so- // a deliberate frost switch feels continuous — which only works if we- // don't re-issue it on unrelated updates. Windows has no equivalent- // animation option; setBackgroundMaterial is instantaneous.- if (IS_MAC && typeof win.setVibrancy === 'function') {- win.setVibrancy(vibrancyForTranslucency(translucencyState), { animationDuration: 150 })+ if (IS_WINDOWS && GLASS_SUPPORTED) {+ applyWindowsBackdrop(win, translucencyState, changed, getWindowBackgroundColor())+ } else {+ if (changed.backing && typeof win.setBackgroundColor === 'function') {+ win.setBackgroundColor(glassActive(translucencyState) ? '#00000000' : getWindowBackgroundColor())}- if (IS_WINDOWS && GLASS_SUPPORTED && typeof win.setBackgroundMaterial === 'function') {- win.setBackgroundMaterial(backgroundMaterialFor(translucencyState))+ // Animate deliberate macOS frost changes, not unrelated tint updates.+ if (changed.material && IS_MAC && typeof win.setVibrancy === 'function') {+ win.setVibrancy(vibrancyForTranslucency(translucencyState), { animationDuration: 150 })}}}diff --git a/apps/desktop/electron/translucency.ts b/apps/desktop/electron/translucency.tsindex c46466e769e..2035392cb44 100644--- a/apps/desktop/electron/translucency.ts+++ b/apps/desktop/electron/translucency.ts@@ -11,6 +11,8 @@* then fail to bundle.*/+import type { BrowserWindow } from 'electron'+import {backgroundMaterialFor,glassActive,@@ -19,6 +21,26 @@ import {type WindowsBackgroundMaterial} from '../../shared/src/translucency'+/**+ * Electron 40.10.2's material setter also replaces the backing colour: white+ * for 'none', transparent for glass. Restore our backing after every material+ * write, even when the glass-active state did not change.+ */+export function applyWindowsBackdrop(+ win: Pick<BrowserWindow, 'setBackgroundColor' | 'setBackgroundMaterial'>,+ state: TranslucencyState,+ changed: { backing: boolean; material: boolean },+ themedColor: string+): void {+ if (changed.material) {+ win.setBackgroundMaterial(backgroundMaterialFor(state))+ }++ if (changed.backing || changed.material) {+ win.setBackgroundColor(glassActive(state) ? '#00000000' : themedColor)+ }+}+export {backgroundMaterialFor,clampIntensity,@@ -81,8 +103,8 @@ export function windowBackingOptions(state: TranslucencyState, themedColor: stri/*** Return the native Windows backdrop only when glass is actually active.- * Electron treats even the `none` backdrop as a translucent-window opt-in,- * which disables native maximize and resize commands on Windows.+ * Opaque windows keep their constructor backing. Live material resets go+ * through applyWindowsBackdrop so Electron cannot replace the theme colour.*/export function windowBackgroundMaterialOptions(state: TranslucencyState,diff --git a/apps/desktop/electron/windows-backdrop.test.ts b/apps/desktop/electron/windows-backdrop.test.tsnew file mode 100644index 00000000000..1cb54e1205b--- /dev/null+++ b/apps/desktop/electron/windows-backdrop.test.ts@@ -0,0 +1,78 @@+import { describe, expect, it } from 'vitest'++import { applyWindowsBackdrop, type TranslucencyState, type WindowsBackgroundMaterial } from './translucency'++const glass = (intensity: number): TranslucencyState => ({+ mode: 'glass',+ intensity,+ fade: 0,+ material: 'under-window',+ scope: 'sidebar'+})++function electronWindow() {+ let background = '#initial'+ let materialWrites = 0+ let colourWrites = 0++ const win = {+ setBackgroundColor(colour: string) {+ background = colour+ colourWrites+++ },+ setBackgroundMaterial(material: WindowsBackgroundMaterial) {+ materialWrites+++ // Electron 40.10.2 BrowserWindow::SetBackgroundMaterial also sets the+ // backing: white for 'none', transparent for an active material.+ win.setBackgroundColor(material === 'none' ? '#FFFFFFFF' : '#00000000')+ }+ }++ return { win, background: () => background, writes: () => ({ materialWrites, colourWrites }) }+}++describe('Windows backdrop updates', () => {+ it.each([+ { state: glass(0), backing: true, themedColor: '#111111' },+ { state: glass(0), backing: false, themedColor: '#f7f7f7' },+ { state: { ...glass(60), mode: 'clear' as const }, backing: false, themedColor: '#242424' }+ ])('keeps $themedColor after clearing the material (backing=$backing)', ({ state, backing, themedColor }) => {+ const window = electronWindow()++ applyWindowsBackdrop(window.win, state, { backing, material: true }, themedColor)++ expect(window.background()).toBe(themedColor)+ expect(window.writes().materialWrites).toBe(1)+ })++ it('keeps active glass transparent when changing its material', () => {+ const window = electronWindow()++ applyWindowsBackdrop(+ window.win,+ { ...glass(60), material: 'popover' },+ { backing: false, material: true },+ '#111111'+ )++ expect(window.background()).toBe('#00000000')+ })++ it('can update only the backing without touching the material', () => {+ const window = electronWindow()++ applyWindowsBackdrop(window.win, glass(0), { backing: true, material: false }, '#222222')++ expect(window.background()).toBe('#222222')+ expect(window.writes().materialWrites).toBe(0)+ })++ it('does not write native state for tint-only or opacity-only changes', () => {+ const window = electronWindow()++ applyWindowsBackdrop(window.win, glass(60), { backing: false, material: false }, '#111111')++ expect(window.background()).toBe('#initial')+ expect(window.writes()).toEqual({ materialWrites: 0, colourWrites: 0 })+ })+})