Skip to content

Commit faef975

Browse files
update theme handlers to set color scheme options properly
1 parent 75cafbc commit faef975

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

packages/app-desktop/src/api.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,8 @@ export interface DarkwriteElectronAPI {
110110
load: () => Promise<Theme[]>;
111111
};
112112
getClientInfo: () => Promise<DarkwriteDesktopClientInfo>;
113+
setTitlebarSymbolColor: (
114+
symbolColor: string,
115+
themeMode: "light" | "dark" | "system" = "system",
116+
) => Promise<void>;
113117
}

packages/app-desktop/src/components/theme-handler.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useTheme } from "@renderer/hooks/query";
33
import { DarkwriteDefault } from "@renderer/lib/themes/darkwrite-default";
44
import { hexToHslVariable, setGlobalStyle } from "@renderer/lib/utils";
55
import { useEffect } from "react";
6+
import { hsl } from "color-convert";
67

78
export function ThemeHandler() {
89
const fonts = useSettingsStore((s) => s.settings.fonts);
@@ -42,6 +43,18 @@ export function ThemeHandler() {
4243
setGlobalStyle("--border", theme.border);
4344
setGlobalStyle("--ring", theme.focusRing);
4445
setGlobalStyle("--star", theme.star);
46+
if (window.api != null && window.api.setTitlebarSymbolColor != null) {
47+
const fgHSLStr = theme.foreground.replace("%", "").split(" ");
48+
if (fgHSLStr.length !== 3) return;
49+
const fgHSL: [number, number, number] = [
50+
parseFloat(fgHSLStr[0]),
51+
parseFloat(fgHSLStr[1]),
52+
parseFloat(fgHSLStr[2]),
53+
];
54+
const fgHEX = hsl.hex(fgHSL);
55+
console.log(fgHEX);
56+
window.api.setTitlebarSymbolColor(`#${fgHEX}`, theme.mode);
57+
}
4558
}, [fonts, theme, accentColor]);
4659
return <></>;
4760
}

packages/app-desktop/src/electron/channels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export enum ChannelNames {
2626
RESTORE_BACKUP = "restore-user-data",
2727
IMPORT_THEME = "import-theme",
2828
LOAD_THEMES = "load-themes",
29+
SET_TITLEBAR_SYMBOL_COLOR = "set-titlebar-symbol-color",
2930
}

packages/app-desktop/src/electron/ipc.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
NotePartial,
66
UserSettings,
77
} from "@darkwrite/common";
8-
import { app, ipcMain } from "electron";
8+
import { app, BrowserWindow, ipcMain, nativeTheme } from "electron";
99
import { readFile, writeFile } from "fs/promises";
1010
import { openFile, saveFile } from "./api/dialog";
1111
import {
@@ -173,3 +173,17 @@ ipcMain.handle(ChannelNames.RESTORE_BACKUP, async (_event, archive: string) => {
173173

174174
ipcMain.handle(ChannelNames.IMPORT_THEME, () => ThemeAPI.import());
175175
ipcMain.handle(ChannelNames.LOAD_THEMES, () => ThemeAPI.load());
176+
ipcMain.handle(
177+
ChannelNames.SET_TITLEBAR_SYMBOL_COLOR,
178+
(
179+
_event,
180+
symbolColor: string,
181+
themeMode: "light" | "dark" | "system" = "system",
182+
) => {
183+
const windows = BrowserWindow.getAllWindows();
184+
windows.forEach((window) => {
185+
window.setTitleBarOverlay({ symbolColor });
186+
});
187+
nativeTheme.themeSource = themeMode;
188+
},
189+
);

packages/app-desktop/src/electron/preload/preload.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ const darkwriteAPI: DarkwriteElectronAPI = {
6161
import: () => ipcRenderer.invoke(ChannelNames.IMPORT_THEME),
6262
load: () => ipcRenderer.invoke(ChannelNames.LOAD_THEMES),
6363
},
64+
setTitlebarSymbolColor: (
65+
symbolColor: string,
66+
themeMode: "light" | "dark" | "system" = "system",
67+
) =>
68+
ipcRenderer.invoke(
69+
ChannelNames.SET_TITLEBAR_SYMBOL_COLOR,
70+
symbolColor,
71+
themeMode,
72+
),
6473
};
6574

6675
contextBridge.exposeInMainWorld("api", darkwriteAPI);

0 commit comments

Comments
 (0)