mirror of
https://github.com/pvrzz/directify.git
synced 2026-11-29 05:22:24 +00:00
Replace default window titlebar with a custom draggable overlay
Uses Windows' Window Controls Overlay (titleBarStyle: hidden + titleBarOverlay) so minimize/maximize/close stay real, natively-drawn buttons instead of custom ones, but recolored to match the active theme. The renderer supplies a transparent draggable strip in place of the default title/icon bar.
This commit is contained in:
@@ -46,4 +46,6 @@ export interface DirectifyIpcApi {
|
||||
|
||||
checkForUpdate(): Promise<UpdateCheckResult>;
|
||||
openExternal(url: string): Promise<void>;
|
||||
|
||||
setTitleBarOverlay(colors: { color: string; symbolColor: string }): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 (
|
||||
<MotionConfig reducedMotion={settings?.reduceMotion ? "always" : "user"}>
|
||||
<div style={{ display: "flex", flexDirection: "column", height: "100vh", overflow: "hidden" }}>
|
||||
<div
|
||||
style={
|
||||
{
|
||||
height: 40,
|
||||
flexShrink: 0,
|
||||
WebkitAppRegion: "drag",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
{updateInfo?.hasUpdate && updateInfo.latestVersion && updateInfo.releaseUrl && (
|
||||
<UpdateBanner
|
||||
latestVersion={updateInfo.latestVersion}
|
||||
|
||||
@@ -196,6 +196,8 @@ export function installMockDirectifyIfNeeded(): void {
|
||||
openExternal: async (url) => {
|
||||
window.open(url, "_blank");
|
||||
},
|
||||
|
||||
setTitleBarOverlay: async () => {},
|
||||
};
|
||||
|
||||
window.directify = mock;
|
||||
|
||||
Reference in New Issue
Block a user