diff --git a/apps/desktop/src/ipc-types.ts b/apps/desktop/src/ipc-types.ts index 123fee5..6933d78 100644 --- a/apps/desktop/src/ipc-types.ts +++ b/apps/desktop/src/ipc-types.ts @@ -46,4 +46,6 @@ export interface DirectifyIpcApi { checkForUpdate(): Promise; openExternal(url: string): Promise; + + setTitleBarOverlay(colors: { color: string; symbolColor: string }): Promise; } diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts index 74c2318..ff0cbba 100644 --- a/apps/desktop/src/main/index.ts +++ b/apps/desktop/src/main/index.ts @@ -27,6 +27,8 @@ import { checkForUpdate } from "./updates.js"; const ALLOWED_EXTERNAL_HOSTS = ["github.com", "www.github.com"]; +let mainWindow: BrowserWindow | null = null; + function requireInstallDir(): string { const { osuInstallDir } = loadSettings(); if (!osuInstallDir) throw new Error("osu! install directory is not configured yet."); @@ -109,6 +111,10 @@ function registerIpcHandlers(): void { await writeFile(path, writeCollectionDb(db)); }); + ipcMain.handle("window:setTitleBarOverlay", (_e, colors: { color: string; symbolColor: string }) => { + mainWindow?.setTitleBarOverlay({ ...colors, height: 40 }); + }); + ipcMain.handle("app:checkForUpdate", () => checkForUpdate(app.getVersion())); ipcMain.handle("app:openExternal", (_e, url: string) => { const host = new URL(url).hostname; @@ -131,6 +137,16 @@ function createWindow(): void { height: 800, backgroundColor: "#171a1c", icon: resolveIconPath(), + // Hides the default titlebar/menu chrome but keeps real, natively-drawn + // minimize/maximize/close buttons (Windows' Window Controls Overlay) — + // the renderer supplies its own draggable title strip and re-colors the + // overlay to match the active theme via window:setTitleBarOverlay. + titleBarStyle: "hidden", + titleBarOverlay: { + color: "#171a1c", + symbolColor: "#f4f2f7", + height: 40, + }, webPreferences: { preload: join(__dirname, "../preload/index.js"), contextIsolation: true, @@ -138,6 +154,10 @@ function createWindow(): void { sandbox: true, }, }); + mainWindow = win; + win.on("closed", () => { + if (mainWindow === win) mainWindow = null; + }); if (process.env.ELECTRON_RENDERER_URL) { win.loadURL(process.env.ELECTRON_RENDERER_URL); diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts index 66c3445..d0d0feb 100644 --- a/apps/desktop/src/preload/index.ts +++ b/apps/desktop/src/preload/index.ts @@ -26,6 +26,8 @@ const api: DirectifyIpcApi = { checkForUpdate: () => ipcRenderer.invoke("app:checkForUpdate"), openExternal: (url) => ipcRenderer.invoke("app:openExternal", url), + + setTitleBarOverlay: (colors) => ipcRenderer.invoke("window:setTitleBarOverlay", colors), }; contextBridge.exposeInMainWorld("directify", api); diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsx index 65ef8dc..0481340 100644 --- a/apps/desktop/src/renderer/src/App.tsx +++ b/apps/desktop/src/renderer/src/App.tsx @@ -59,14 +59,23 @@ export function App() { if (!settings) return; const root = document.documentElement; + function applyTheme(resolved: "dark" | "light") { + root.dataset.theme = resolved; + window.directify.setTitleBarOverlay( + resolved === "dark" + ? { color: "#171a1c", symbolColor: "#f4f2f7" } + : { color: "#f4f5f6", symbolColor: "#171a1c" } + ); + } + if (settings.theme === "system") { const media = window.matchMedia("(prefers-color-scheme: dark)"); - const apply = () => (root.dataset.theme = media.matches ? "dark" : "light"); + const apply = () => applyTheme(media.matches ? "dark" : "light"); apply(); media.addEventListener("change", apply); return () => media.removeEventListener("change", apply); } - root.dataset.theme = settings.theme; + applyTheme(settings.theme); }, [settings?.theme]); useEffect(() => { @@ -89,6 +98,15 @@ export function App() { return (
+
{updateInfo?.hasUpdate && updateInfo.latestVersion && updateInfo.releaseUrl && ( { window.open(url, "_blank"); }, + + setTitleBarOverlay: async () => {}, }; window.directify = mock;