Skip to content

📧✨ Beautiful email. For everyone.

feat: blend the title bar into the app on every platform (#36)

Paul Koeck737e9797978b
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index d17f9eb..eded2ca 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -7,11 +7,12 @@ import {
Tray,
Menu,
nativeImage,
+ nativeTheme,
powerMonitor,
} from 'electron'
import { join, resolve, sep } from 'node:path'
import { pathToFileURL, fileURLToPath } from 'node:url'
-import { ipcSchemas, type AppEvent } from '@inlark/core'
+import { ipcSchemas, type AppEvent, type Settings } from '@inlark/core'
import { JsonStore } from './storage'
import { MailService } from './service'
import { imapProviders } from './imap-accounts'
@@ -87,6 +88,22 @@ function trusted(event: Electron.IpcMainInvokeEvent): boolean {
return false
}
}
+// Inlark draws its own title bar and keeps the native window controls on it. These match
+// --sidebar and --secondary in packages/ui/src/styles.css so the controls blend in.
+const titleBarHeight = 36
+const titleBarColors = {
+ dark: { color: '#111112', symbolColor: '#b7b7bd' },
+ light: { color: '#f7f8fa', symbolColor: '#5d6068' },
+}
+const themeColors = () => titleBarColors[nativeTheme.shouldUseDarkColors ? 'dark' : 'light']
+function followTheme() {
+ if (!window) return
+ const colors = themeColors()
+ window.setBackgroundColor(colors.color)
+ // macOS styles its traffic lights from the window appearance, which follows themeSource.
+ if (process.platform !== 'darwin')
+ window.setTitleBarOverlay({ height: titleBarHeight, ...colors })
+}
function createWindow() {
rendererReady = false
window = new BrowserWindow({
@@ -96,9 +113,11 @@ function createWindow() {
minHeight: 620,
show: false,
icon: join(here, '../../resources/icon.png'),
- backgroundColor: '#121214',
+ backgroundColor: themeColors().color,
title: 'Inlark',
- autoHideMenuBar: true,
+ titleBarStyle: 'hidden',
+ // Also centers the macOS traffic lights in the title bar and reports its size to the page.
+ titleBarOverlay: { height: titleBarHeight, ...themeColors() },
webPreferences: {
preload: join(here, '../preload/index.cjs'),
contextIsolation: true,
@@ -212,6 +231,9 @@ else {
discover,
})
await service.init()
+ // Native surfaces such as the window controls and menus follow Inlark's theme setting.
+ nativeTheme.themeSource = service.settings.theme
+ nativeTheme.on('updated', followTheme)
const handlers: Record<keyof typeof ipcSchemas, (...args: any[]) => unknown> = {
ready: () => {
rendererReady = true
@@ -261,7 +283,12 @@ else {
: service.senderAvatar,
unsubscribe: service.unsubscribe,
openExternal: service.openExternal,
- settings: service.setSettings,
+ settings: async (settings: Settings) => {
+ const saved = await service.setSettings(settings)
+ nativeTheme.themeSource = saved.theme
+ followTheme()
+ return saved
+ },
diagnostics: service.diagnostics,
}
for (const [name, schema] of Object.entries(ipcSchemas))
diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsx
index ac395ad..3460bce 100644
--- a/apps/desktop/src/renderer/src/App.tsx
+++ b/apps/desktop/src/renderer/src/App.tsx
@@ -1458,7 +1458,8 @@ export function App() {
return (
<div
className={cn(
- 'app-shell flex h-full min-w-0 py-2 pr-2 pl-0 bg-sidebar [--row-height:64px] [--rail:224px]',
+ 'app-shell flex h-full min-w-0 pt-[max(8px,var(--titlebar-height))] pb-2 pr-2 pl-0 bg-sidebar',
+ '[--row-height:64px] [--rail:224px]',
'[&.sidebar-collapsed]:[--rail:64px] [&.density-compact]:[--row-height:44px]',
'max-[1100px]:[&:not(.sidebar-collapsed)]:[--rail:204px] max-[700px]:[&:not(.sidebar-collapsed)]:[--rail:188px]',
collapsed && 'sidebar-collapsed',
diff --git a/apps/desktop/src/renderer/src/Composer.tsx b/apps/desktop/src/renderer/src/Composer.tsx
index 1a4488d..50963b3 100644
--- a/apps/desktop/src/renderer/src/Composer.tsx
+++ b/apps/desktop/src/renderer/src/Composer.tsx
@@ -525,10 +525,11 @@ export function Composer({
}}
>
<Dialog.Portal>
- <Dialog.Backdrop className="compose-backdrop fixed inset-0 bg-[#0004] z-70 transition-[opacity] duration-160 ease-[ease] data-starting-style:opacity-0 data-ending-style:opacity-0" />
+ <Dialog.Backdrop className="compose-backdrop fixed inset-x-0 bottom-0 top-(--titlebar-height) bg-[#0004] z-70 transition-[opacity] duration-160 ease-[ease] data-starting-style:opacity-0 data-ending-style:opacity-0" />
<Dialog.Popup
className={cn(
- 'composer fixed right-6 bottom-6 w-[min(660px,_calc(100vw_-_48px))] h-[min(700px,_calc(100vh_-_48px))]',
+ 'composer fixed right-6 bottom-6 w-[min(660px,_calc(100vw_-_48px))]',
+ 'h-[min(700px,_calc(100vh_-_48px_-_var(--titlebar-height)))]',
'bg-surface border border-solid border-border-strong rounded-2xl shadow-popup z-71 flex flex-col overflow-hidden',
'transition-[opacity,transform] duration-160 ease-[ease] data-starting-style:opacity-0',
'data-starting-style:transform-[translateY(10px)_scale(0.99)] data-ending-style:opacity-0',
diff --git a/apps/desktop/src/renderer/src/Settings.tsx b/apps/desktop/src/renderer/src/Settings.tsx
index c4f8f09..a5656de 100644
--- a/apps/desktop/src/renderer/src/Settings.tsx
+++ b/apps/desktop/src/renderer/src/Settings.tsx
@@ -228,7 +228,7 @@ export function SettingsPanel({
)}
popupRef={modalRef}
>
- <div className="settings-layout flex min-h-0 h-[min(620px,_calc(100dvh_-_80px))] overflow-hidden rounded-[inherit]">
+ <div className="settings-layout flex min-h-0 h-[min(620px,_calc(100dvh_-_80px_-_var(--titlebar-height)))] overflow-hidden rounded-[inherit]">
<nav
className={cn(
'settings-nav w-50 shrink-0 bg-sidebar pt-12.5 pb-3 px-2.5 flex flex-col gap-[2px] border-r border-solid',
diff --git a/apps/desktop/src/renderer/src/main.tsx b/apps/desktop/src/renderer/src/main.tsx
index fb81429..80bb546 100644
--- a/apps/desktop/src/renderer/src/main.tsx
+++ b/apps/desktop/src/renderer/src/main.tsx
@@ -90,6 +90,11 @@ class ErrorBoundary extends React.Component<{ children: React.ReactNode }, { err
void restoreCache().finally(() =>
createRoot(document.getElementById('root')!).render(
<React.StrictMode>
+ {/* Drags the window like a native title bar, on every screen including the error page. */}
+ <div
+ aria-hidden
+ className="titlebar fixed inset-x-0 top-0 h-(--titlebar-height) bg-sidebar [app-region:drag]"
+ />
<ErrorBoundary>
<QueryClientProvider client={queryClient}>
<TooltipProvider delay={500}>
diff --git a/apps/desktop/src/renderer/src/styles.css b/apps/desktop/src/renderer/src/styles.css
index d44bf7f..ce03f6f 100644
--- a/apps/desktop/src/renderer/src/styles.css
+++ b/apps/desktop/src/renderer/src/styles.css
@@ -1,6 +1,17 @@
+:root {
+ /* The strip the native window controls sit on. It is 0 in a browser and in macOS fullscreen. */
+ --titlebar-height: env(titlebar-area-height, 0px);
+}
#root {
height: 100vh;
}
+/* The title bar takes every click inside it, even on popups above it, unless they opt out. */
+[role='dialog'],
+[role='alertdialog'],
+[role='menu'],
+[role='listbox'] {
+ app-region: no-drag;
+}
@layer components {
/* These elements are generated by the rich-text editor rather than React. */
.compose-editor p {
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index 4bdc5d5..8e828a5 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -88,12 +88,14 @@ export function Modal({
return (
<Dialog.Root open={open} onOpenChange={onOpenChange}>
<Dialog.Portal>
- <Dialog.Backdrop className="modal-backdrop fixed inset-0 bg-[#0505079c] backdrop-blur-[5px] transition-[opacity] duration-160 ease-[ease] z-100 data-starting-style:opacity-0 data-ending-style:opacity-0" />
+ {/* Dialogs stay below the desktop title bar so it keeps working as one. */}
+ <Dialog.Backdrop className="modal-backdrop fixed inset-x-0 bottom-0 top-[var(--titlebar-height,0px)] bg-[#0505079c] backdrop-blur-[5px] transition-[opacity] duration-160 ease-[ease] z-100 data-starting-style:opacity-0 data-ending-style:opacity-0" />
<Dialog.Popup
ref={popupRef}
className={cn(
- 'modal fixed top-[50%] left-[50%] transform-[translate(-50%,_-50%)] w-[min(560px,_calc(100vw_-_40px))]',
- 'max-h-[calc(100vh_-_70px)] overflow-y-auto bg-surface border border-solid border-border-strong rounded-2xl',
+ 'modal fixed top-[calc(50%_+_var(--titlebar-height,0px)_/_2)] left-[50%] transform-[translate(-50%,_-50%)]',
+ 'w-[min(560px,_calc(100vw_-_40px))] max-h-[calc(100vh_-_70px_-_var(--titlebar-height,0px))] overflow-y-auto',
+ 'bg-surface border border-solid border-border-strong rounded-2xl',
'shadow-popup p-5.75 z-101 max-w-[calc(100vw_-_40px)] transition-[opacity,transform] duration-160 ease-[ease]',
'data-starting-style:opacity-0 data-starting-style:transform-[translate(-50%,_-48%)_scale(0.98)]',
'data-ending-style:opacity-0 data-ending-style:transform-[translate(-50%,_-48%)_scale(0.98)]',