From 3250fb6899a83dd490139dadd0348eef37d8d05c Mon Sep 17 00:00:00 2001 From: Denis Gladkiy Date: Mon, 20 Oct 2025 20:10:26 +0600 Subject: [PATCH] Fix: reduced theme blinking on desktop app start (windows). Signed-off-by: Denis Gladkiy --- desktop/src/ui/index.ejs | 17 ++++++++++++++++- desktop/src/ui/index.ts | 13 ++++++++----- desktop/src/ui/titleBarMenu.ts | 21 ++++++++++++++------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/desktop/src/ui/index.ejs b/desktop/src/ui/index.ejs index ae893ba49aa..5560107cc90 100644 --- a/desktop/src/ui/index.ejs +++ b/desktop/src/ui/index.ejs @@ -24,7 +24,12 @@ box-sizing: border-box; } + body { + background-color: var(--bg-body, #ffffff); + } + :root { + --bg-body: #ffffff; --bg-secondary: #f3f3f3; --bg-tertiary: #ffffff; --bg-hover: #e8e8e8; @@ -39,6 +44,7 @@ } [data-theme="theme-dark"] { + --bg-body: #1a1928; --bg-secondary: #323233; --bg-tertiary: #252526; --bg-hover: #2a2d2e; @@ -236,4 +242,13 @@ - \ No newline at end of file + + +<% if (typeof isWindows !== 'undefined' && isWindows) { %> + +<% } %> \ No newline at end of file diff --git a/desktop/src/ui/index.ts b/desktop/src/ui/index.ts index e5ec3d64548..40e5ba3b390 100644 --- a/desktop/src/ui/index.ts +++ b/desktop/src/ui/index.ts @@ -10,6 +10,7 @@ import { closePopup, createApp, getCurrentResolvedLocation, + Menu, navigate, parseLocation, pushRootBarProgressComponent, @@ -66,11 +67,13 @@ window.addEventListener('DOMContentLoaded', () => { } }) - void ipcMain.isOsUsingDarkTheme().then((isDarkTheme) => { - menuBar.setTheme(isDarkTheme ? ThemeVariant.Dark : ThemeVariant.Light) - }).catch(() => { - menuBar.setTheme(ThemeVariant.Light) // fallback - }) + if (menuBar.lastUsedThemeIsUnknown()) { + void ipcMain.isOsUsingDarkTheme().then((isDarkTheme) => { + menuBar.setTheme(isDarkTheme ? ThemeVariant.Dark : ThemeVariant.Light) + }).catch(() => { + menuBar.setTheme(ThemeVariant.Light) // fallback + }) + } }) } } diff --git a/desktop/src/ui/titleBarMenu.ts b/desktop/src/ui/titleBarMenu.ts index 6121d382247..ce8315d3b7c 100644 --- a/desktop/src/ui/titleBarMenu.ts +++ b/desktop/src/ui/titleBarMenu.ts @@ -16,7 +16,7 @@ import { IPCMainExposed, MenuBarAction } from './types' import { isMenuBarAction } from './typesUtils' import { TitleBarMenuState } from './titleBarMenuState' -import { ThemeVariant, type ThemeVariantType } from '@hcengineering/theme' +import { type ThemeVariantType } from '@hcengineering/theme' const ToggleMinimizeToTrayAction: MenuBarAction = 'toggle-minimize-to-tray' @@ -24,7 +24,7 @@ const LabelMinimizeToTrayEnabled = '☑ Minimize to tray' const LabelMinimizeToTrayDisabled = '☐ Minimize to tray' export async function setupTitleBarMenu (ipcMain: IPCMainExposed, root: HTMLElement): Promise { - const themeManager = new ThemeManager(ThemeVariant.Light) + const themeManager = new ThemeManager() const menuManager = new MenuBarManager(root, await ipcMain.isMinimizeToTrayEnabled()) const menuBar = menuManager.getView() @@ -62,12 +62,19 @@ export async function setupTitleBarMenu (ipcMain: IPCMainExposed, root: HTMLElem } export class MenuBar { + private static readonly lastUsedThemeKey = 'last-used-theme' + constructor (private readonly theme: ThemeManager) { } public setTheme (theme: ThemeVariantType): void { + localStorage.setItem(MenuBar.lastUsedThemeKey, theme) this.theme.setTheme(theme) } + + public lastUsedThemeIsUnknown (): boolean { + return localStorage.getItem(MenuBar.lastUsedThemeKey) == null + } } export function buildHulyApplicationMenu (minimizeToTrayEnabled: boolean): HTMLElement { @@ -114,14 +121,14 @@ export function buildHulyApplicationMenu (minimizeToTrayEnabled: boolean): HTMLE } class ThemeManager { - private readonly domThemeKey = 'data-theme' + private static readonly domThemeKey = 'data-theme' - constructor (theme: ThemeVariantType) { - this.setTheme(theme) + public setTheme (theme: ThemeVariantType): void { + ThemeManager.setTheme(theme) } - public setTheme (theme: ThemeVariantType): void { - document.body.setAttribute(this.domThemeKey, theme) + public static setTheme (theme: ThemeVariantType): void { + document.body.setAttribute(ThemeManager.domThemeKey, theme) } }