🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(desktop): refresh macOS vibrancy when the system theme changes (#21276)
Arvin Xu1eac81642cdc
diff --git a/apps/desktop/src/main/core/browser/WindowThemeManager.ts b/apps/desktop/src/main/core/browser/WindowThemeManager.tsindex e0328fd36fa..eea25bc0712 100644--- a/apps/desktop/src/main/core/browser/WindowThemeManager.ts+++ b/apps/desktop/src/main/core/browser/WindowThemeManager.ts@@ -177,6 +177,18 @@ export class WindowThemeManager {return this.resolveIsDarkMode() ? BACKGROUND_DARK : BACKGROUND_LIGHT;}+ /**+ * Electron does not re-evaluate the macOS NSVisualEffectView when the theme changes at+ * runtime, so the vibrancy keeps the previous appearance (dark sidebar over a light UI)+ * until the window is recreated. Toggling it forces AppKit to rebuild the effect view.+ */+ private refreshMacVibrancy(): void {+ if (!this.browserWindow) return;++ this.browserWindow.setVibrancy(null);+ this.browserWindow.setVibrancy(MACOS_VIBRANCY);+ }+private applyMacFullscreenChrome(isFullScreen: boolean): void {if (!this.browserWindow) return;@@ -217,8 +229,14 @@ export class WindowThemeManager {this.applyWindowsVisualEffects(isDarkMode);} else if (isLinux) {this.applyLinuxVisualEffects();- } else if (isMac && this.browserWindow.isFullScreen()) {- this.applyMacFullscreenChrome(true);+ } else if (isMac) {+ // macOS keeps the native vibrancy (and the traffic-light/title bar area) on the+ // appearance it was created with, so it has to be rebuilt on every theme change.+ if (this.browserWindow.isFullScreen()) {+ this.applyMacFullscreenChrome(true);+ } else {+ this.refreshMacVibrancy();+ }}} catch (error) {logger.error(`[${this.identifier}] Failed to apply visual effects:`, error);diff --git a/apps/desktop/src/main/core/browser/__tests__/WindowThemeManager.mac.test.ts b/apps/desktop/src/main/core/browser/__tests__/WindowThemeManager.mac.test.tsnew file mode 100644index 00000000000..8f7bd26ee2c--- /dev/null+++ b/apps/desktop/src/main/core/browser/__tests__/WindowThemeManager.mac.test.ts@@ -0,0 +1,93 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { WindowThemeManager } from '../WindowThemeManager';++const { mockNativeTheme, mockBrowserWindow } = vi.hoisted(() => ({+ mockBrowserWindow: {+ isDestroyed: vi.fn(),+ isFullScreen: vi.fn(),+ setBackgroundColor: vi.fn(),+ setVibrancy: vi.fn(),+ },+ mockNativeTheme: {+ off: vi.fn(),+ on: vi.fn(),+ shouldUseDarkColors: false,+ themeSource: 'system' as string,+ },+}));++vi.mock('electron', () => ({+ nativeTheme: mockNativeTheme,+}));++vi.mock('@/const/dir', () => ({+ buildDir: '/mock/build',+}));++vi.mock('@/const/env', () => ({+ isDev: false,+ isLinux: false,+ isMac: true,+ isMacTahoe: false,+ isWindows: false,+}));++vi.mock('@lobechat/desktop-bridge', () => ({+ TITLE_BAR_HEIGHT: 38,+}));++vi.mock('../../../const/theme', () => ({+ BACKGROUND_DARK: '#1a1a1a',+ BACKGROUND_LIGHT: '#ffffff',+ SYMBOL_COLOR_DARK: '#ffffff',+ SYMBOL_COLOR_LIGHT: '#000000',+ THEME_CHANGE_DELAY: 0,+}));++describe('WindowThemeManager (macOS)', () => {+ let manager: WindowThemeManager;++ beforeEach(() => {+ vi.clearAllMocks();+ vi.useFakeTimers();++ mockNativeTheme.shouldUseDarkColors = false;+ mockNativeTheme.themeSource = 'system';+ mockBrowserWindow.isDestroyed.mockReturnValue(false);+ mockBrowserWindow.isFullScreen.mockReturnValue(false);++ manager = new WindowThemeManager('test-window');+ });++ afterEach(() => {+ manager.cleanup();+ vi.useRealTimers();+ });++ it('rebuilds the vibrancy when the theme changes in windowed mode', () => {+ manager.attach(mockBrowserWindow as any);+ mockBrowserWindow.setVibrancy.mockClear();++ manager.handleAppThemeChange();+ vi.runAllTimers();++ expect(mockBrowserWindow.setVibrancy).toHaveBeenNthCalledWith(1, null);+ expect(mockBrowserWindow.setVibrancy).toHaveBeenNthCalledWith(2, 'sidebar');+ });++ it('keeps an opaque background instead of vibrancy in fullscreen', () => {+ mockNativeTheme.shouldUseDarkColors = true;+ mockBrowserWindow.isFullScreen.mockReturnValue(true);++ manager.attach(mockBrowserWindow as any);+ mockBrowserWindow.setVibrancy.mockClear();++ manager.handleAppThemeChange();+ vi.runAllTimers();++ expect(mockBrowserWindow.setBackgroundColor).toHaveBeenLastCalledWith('#1a1a1a');+ expect(mockBrowserWindow.setVibrancy).toHaveBeenCalledWith(null);+ expect(mockBrowserWindow.setVibrancy).not.toHaveBeenCalledWith('sidebar');+ });+});