fix: updated UI to macosx conventions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { app, ipcMain, dialog, shell } from 'electron';
|
||||
import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron';
|
||||
import * as path from 'path';
|
||||
import * as fsPromises from 'fs/promises';
|
||||
import { eq } from 'drizzle-orm';
|
||||
@@ -697,6 +697,20 @@ export function registerIpcHandlers(): void {
|
||||
return projectEngine.getDefaultProjectBaseDir(projectId);
|
||||
});
|
||||
|
||||
safeHandle('app:getTitleBarMetrics', async (event) => {
|
||||
const ownerWindow = BrowserWindow.fromWebContents(event.sender);
|
||||
const buttonPosition = ownerWindow?.getWindowButtonPosition?.();
|
||||
if (!buttonPosition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const estimatedClusterWidth = Math.max(52, Math.round(buttonPosition.y * 4));
|
||||
const trailingPadding = Math.max(8, Math.round(buttonPosition.y * 0.6));
|
||||
const macosLeftInset = Math.max(0, Math.round(buttonPosition.x + estimatedClusterWidth + trailingPadding));
|
||||
|
||||
return { macosLeftInset };
|
||||
});
|
||||
|
||||
safeHandle('app:showItemInFolder', async (_, itemPath: string) => {
|
||||
return shell.showItemInFolder(itemPath);
|
||||
});
|
||||
|
||||
@@ -137,6 +137,7 @@ export const electronAPI: ElectronAPI = {
|
||||
// App
|
||||
app: {
|
||||
getDataPaths: () => ipcRenderer.invoke('app:getDataPaths'),
|
||||
getTitleBarMetrics: () => ipcRenderer.invoke('app:getTitleBarMetrics'),
|
||||
openFolder: (folderPath: string) => ipcRenderer.invoke('app:openFolder', folderPath),
|
||||
showItemInFolder: (itemPath: string) => ipcRenderer.invoke('app:showItemInFolder', itemPath),
|
||||
selectFolder: (title?: string) => ipcRenderer.invoke('app:selectFolder', title),
|
||||
|
||||
@@ -505,6 +505,7 @@ export interface ElectronAPI {
|
||||
};
|
||||
app: {
|
||||
getDataPaths: () => Promise<{ database: string; posts: string; media: string }>;
|
||||
getTitleBarMetrics: () => Promise<{ macosLeftInset: number } | null>;
|
||||
openFolder: (folderPath: string) => Promise<string>;
|
||||
showItemInFolder: (itemPath: string) => Promise<void>;
|
||||
selectFolder: (title?: string) => Promise<string | null>;
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.window-titlebar.is-mac .window-titlebar-menu-bar {
|
||||
margin-left: max(var(--bds-titlebar-macos-left-inset, 78px), calc(6px + var(--bds-titlebar-overlay-left, 0px)));
|
||||
}
|
||||
|
||||
.window-titlebar-menu-button {
|
||||
height: 24px;
|
||||
border: none;
|
||||
|
||||
@@ -133,6 +133,83 @@ export const WindowTitleBar: React.FC = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMac) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rootStyle = document.documentElement.style;
|
||||
let isDisposed = false;
|
||||
let resolutionQuery: MediaQueryList | null = null;
|
||||
|
||||
const syncMacInset = async () => {
|
||||
const metrics = await window.electronAPI?.app?.getTitleBarMetrics?.();
|
||||
if (isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (metrics && Number.isFinite(metrics.macosLeftInset)) {
|
||||
rootStyle.setProperty('--bds-titlebar-macos-left-inset', `${Math.max(0, Math.round(metrics.macosLeftInset))}px`);
|
||||
}
|
||||
};
|
||||
|
||||
const bindResolutionListener = () => {
|
||||
if (typeof window.matchMedia !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resolutionQuery && typeof resolutionQuery.removeEventListener === 'function') {
|
||||
resolutionQuery.removeEventListener('change', onResolutionChange);
|
||||
}
|
||||
|
||||
resolutionQuery = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
||||
if (typeof resolutionQuery.addEventListener === 'function') {
|
||||
resolutionQuery.addEventListener('change', onResolutionChange);
|
||||
}
|
||||
};
|
||||
|
||||
const onResolutionChange = () => {
|
||||
void syncMacInset();
|
||||
bindResolutionListener();
|
||||
};
|
||||
|
||||
const onResize = () => {
|
||||
void syncMacInset();
|
||||
};
|
||||
|
||||
const onVisibilityChange = () => {
|
||||
if (!document.hidden) {
|
||||
void syncMacInset();
|
||||
}
|
||||
};
|
||||
|
||||
const canListenToWindowEvents = typeof window.addEventListener === 'function';
|
||||
const canListenToDocumentEvents = typeof document.addEventListener === 'function';
|
||||
|
||||
void syncMacInset();
|
||||
bindResolutionListener();
|
||||
if (canListenToWindowEvents) {
|
||||
window.addEventListener('resize', onResize);
|
||||
}
|
||||
if (canListenToDocumentEvents) {
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
}
|
||||
|
||||
return () => {
|
||||
isDisposed = true;
|
||||
if (canListenToWindowEvents && typeof window.removeEventListener === 'function') {
|
||||
window.removeEventListener('resize', onResize);
|
||||
}
|
||||
if (canListenToDocumentEvents && typeof document.removeEventListener === 'function') {
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
}
|
||||
|
||||
if (resolutionQuery && typeof resolutionQuery.removeEventListener === 'function') {
|
||||
resolutionQuery.removeEventListener('change', onResolutionChange);
|
||||
}
|
||||
};
|
||||
}, [isMac]);
|
||||
|
||||
useEffect(() => {
|
||||
const updateTitle = () => {
|
||||
setWindowTitle(document.title || 'Blogging Desktop Server');
|
||||
@@ -383,7 +460,7 @@ export const WindowTitleBar: React.FC = () => {
|
||||
const activeMenu = openMenu ? visibleMenuGroups.find(group => group.label === openMenu.label) : null;
|
||||
|
||||
return (
|
||||
<div className="window-titlebar" data-testid="window-titlebar" ref={menuRootRef}>
|
||||
<div className={`window-titlebar${isMac ? ' is-mac' : ''}`} data-testid="window-titlebar" ref={menuRootRef}>
|
||||
<div className="window-titlebar-menu-bar" data-testid="window-titlebar-menu-bar">
|
||||
{visibleMenuGroups.map(group => (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user