Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion desktop/src/ui/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +44,7 @@
}

[data-theme="theme-dark"] {
--bg-body: #1a1928;
--bg-secondary: #323233;
--bg-tertiary: #252526;
--bg-hover: #2a2d2e;
Expand Down Expand Up @@ -236,4 +242,13 @@

</body>

</html>
</html>

<% if (typeof isWindows !== 'undefined' && isWindows) { %>
<script>
const lastUsedTheme = localStorage.getItem('last-used-theme')
if (lastUsedTheme != null) {
document.body.setAttribute('data-theme', lastUsedTheme)
}
</script>
<% } %>
13 changes: 8 additions & 5 deletions desktop/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
closePopup,
createApp,
getCurrentResolvedLocation,
Menu,
navigate,
parseLocation,
pushRootBarProgressComponent,
Expand Down Expand Up @@ -82,11 +83,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
})
}
})
}
}
Expand Down
21 changes: 14 additions & 7 deletions desktop/src/ui/titleBarMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
const ToggleAutoLaunchAction: MenuBarAction = 'toggle-auto-launch'
Expand All @@ -28,7 +28,7 @@ const LabelAutoLaunchEnabled = '☑ Launch at Login'
const LabelAutoLaunchDisabled = '☐ Launch at Login'

export async function setupTitleBarMenu (ipcMain: IPCMainExposed, root: HTMLElement): Promise<MenuBar> {
const themeManager = new ThemeManager(ThemeVariant.Light)
const themeManager = new ThemeManager()
const minimizeToTrayEnabled = await ipcMain.isMinimizeToTrayEnabled()
const isAutoLaunchEnabled = await ipcMain.isAutoLaunchEnabled()
const menuManager = new MenuBarManager(root, minimizeToTrayEnabled, isAutoLaunchEnabled)
Expand Down Expand Up @@ -75,12 +75,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, autoLaunchEnabled: boolean): HTMLElement {
Expand Down Expand Up @@ -130,14 +137,14 @@ export function buildHulyApplicationMenu (minimizeToTrayEnabled: boolean, autoLa
}

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)
}
}

Expand Down
Loading