📧✨ Beautiful email. For everyone.
feat: add a system title bar preference (#37)
Paul Koeckdd3d3a6e7c97
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.tsindex eded2ca..6279488 100644--- a/apps/desktop/src/main/index.ts+++ b/apps/desktop/src/main/index.ts@@ -41,6 +41,9 @@ let window: BrowserWindow | null = null,quitting = falselet unreadCount = 0,rendererReady = false+// Keep the current window's mode while a saved preference waits for the next restart.+let windowUsesSystemTitleBar = false+let restartQueued = falselet service: MailServiceconst updates = new UpdateManager((status) => send({ type: 'update', status }))const pendingEvents: AppEvent[] = []@@ -101,11 +104,12 @@ function followTheme() {const colors = themeColors()window.setBackgroundColor(colors.color)// macOS styles its traffic lights from the window appearance, which follows themeSource.- if (process.platform !== 'darwin')+ if (!windowUsesSystemTitleBar && process.platform !== 'darwin')window.setTitleBarOverlay({ height: titleBarHeight, ...colors })}function createWindow() {rendererReady = false+ windowUsesSystemTitleBar = service.settings.systemTitleBar === truewindow = new BrowserWindow({width: 1380,height: 900,@@ -115,9 +119,11 @@ function createWindow() {icon: join(here, '../../resources/icon.png'),backgroundColor: themeColors().color,title: 'Inlark',- titleBarStyle: 'hidden',+ titleBarStyle: windowUsesSystemTitleBar ? 'default' : 'hidden',// Also centers the macOS traffic lights in the title bar and reports its size to the page.- titleBarOverlay: { height: titleBarHeight, ...themeColors() },+ titleBarOverlay: windowUsesSystemTitleBar+ ? false+ : { height: titleBarHeight, ...themeColors() },webPreferences: {preload: join(here, '../preload/index.cjs'),contextIsolation: true,@@ -210,6 +216,8 @@ else {app.whenReady().then(async () => {+ // Remove the in-window menu entirely so Alt cannot reveal it in either title bar mode.+ if (process.platform !== 'darwin') Menu.setApplicationMenu(null)const rendererRoot = resolve(here, '../renderer')protocol.handle('inlark', (request) => {const url = new URL(request.url)@@ -289,6 +297,13 @@ else {followTheme()return saved},+ restart: async () => {+ if (restartQueued) return+ app.relaunch()+ restartQueued = true+ // Reply to the renderer before quitting through the normal cleanup and tray path.+ setImmediate(() => app.quit())+ },diagnostics: service.diagnostics,}for (const [name, schema] of Object.entries(ipcSchemas))diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.tsindex 755f4cd..8e96b0c 100644--- a/apps/desktop/src/preload/index.ts+++ b/apps/desktop/src/preload/index.ts@@ -45,6 +45,7 @@ const methods = ['unsubscribe','openExternal','settings',+ 'restart','diagnostics',] as const satisfies readonly (keyof DesktopMailAPI)[]// Fails to compile when an API method is missing from the allowlist above.diff --git a/apps/desktop/src/renderer/src/Settings.tsx b/apps/desktop/src/renderer/src/Settings.tsxindex a3d64f8..71c08e9 100644--- a/apps/desktop/src/renderer/src/Settings.tsx+++ b/apps/desktop/src/renderer/src/Settings.tsx@@ -174,6 +174,9 @@ export function SettingsPanel({[folders, setFolders] = useState<Account>(),[aliases, setAliases] = useState<Account>()const modalRef = useRef<HTMLDivElement>(null)+ const [restartPrompt, setRestartPrompt] = useState(false),+ [savingTitleBar, setSavingTitleBar] = useState(false),+ [restarting, setRestarting] = useState(false)/** Leaves setup and puts focus back where the account list starts. */const closeSetup = () => {setSetup(undefined)@@ -210,6 +213,14 @@ export function SettingsPanel({return false}}+ const changeTitleBar = async (systemTitleBar: boolean) => {+ setSavingTitleBar(true)+ try {+ if (await update({ systemTitleBar })) setRestartPrompt(true)+ } finally {+ setSavingTitleBar(false)+ }+ }return (<><Modal@@ -397,6 +408,24 @@ export function SettingsPanel({)}><h4>Desktop</h4>+ <div+ className={cn(+ 'setting-row flex items-center justify-between my-3.5 mx-0 gap-6 [&_strong]:font-normal [&_p]:text-muted',+ '[&_p]:my-[3px] [&_p]:mx-0 [&_input]:shrink-0 [&>.button]:shrink-0 [&_p]:text-[12px] [&_p]:leading-[1.6]',+ '[&_strong]:text-[13px] max-[700px]:gap-3.5',+ )}+ >+ <div>+ <strong>Use system title bar</strong>+ <p>Use your desktop’s window frame.</p>+ </div>+ <Switch+ aria-label="Use system title bar"+ checked={bootstrap.settings.systemTitleBar === true}+ disabled={savingTitleBar}+ onCheckedChange={(systemTitleBar) => void changeTitleBar(systemTitleBar)}+ />+ </div><divclassName={cn('setting-row flex items-center justify-between my-3.5 mx-0 gap-6 [&_strong]:font-normal [&_p]:text-muted',@@ -835,6 +864,35 @@ export function SettingsPanel({</div></div></Modal>+ <Modal+ open={restartPrompt}+ onOpenChange={(value) => {+ if (!restarting) setRestartPrompt(value)+ }}+ title="Restart Inlark to apply this change"+ description="Your title bar preference has been saved. Restart now to apply it, or cancel and it will apply the next time you open Inlark."+ >+ <div className="modal-actions flex justify-end gap-2 mt-6">+ <Button disabled={restarting} onClick={() => setRestartPrompt(false)}>+ Cancel+ </Button>+ <Button+ variant="primary"+ disabled={restarting}+ onClick={async () => {+ setRestarting(true)+ try {+ await api.restart()+ } catch (e) {+ setRestarting(false)+ notify(friendlyError(e), 'error')+ }+ }}+ >+ {restarting ? 'Restarting…' : 'Restart Inlark'}+ </Button>+ </div>+ </Modal><AliasesDialogkey={aliases?.id || 'aliases-closed'}account={aliases}diff --git a/apps/desktop/src/renderer/src/demo.ts b/apps/desktop/src/renderer/src/demo.tsindex 938002c..5cbe755 100644--- a/apps/desktop/src/renderer/src/demo.ts+++ b/apps/desktop/src/renderer/src/demo.ts@@ -1152,6 +1152,7 @@ export const demoAPI: DesktopMailAPI = {settings = valuereturn value},+ restart: async () => location.reload(),diagnostics: async () =>JSON.stringify({ mode: 'demo', message: 'Mail data is generated locally.' }, null, 2),ready: async () => {},diff --git a/packages/core/src/model.ts b/packages/core/src/model.tsindex bcce221..56237f6 100644--- a/packages/core/src/model.ts+++ b/packages/core/src/model.ts@@ -214,6 +214,8 @@ export interface Settings {remoteImages: booleannotifications: booleancloseToTray: boolean+ /** Use the system window frame instead of Inlark's title bar, after restarting. */+ systemTitleBar?: booleandefaultAccountId?: stringsignatures: Record<string, string>/** Identities whose signature is HTML code rather than plain text, keyed like `signatures`. */@@ -231,6 +233,7 @@ export const defaultSettings: Settings = {remoteImages: true,notifications: true,closeToTray: true,+ systemTitleBar: false,signatures: {},}export type MailAction =@@ -586,6 +589,7 @@ export interface DesktopMailAPI {): Promise<{ kind: 'done' | 'mailto' | 'browser'; url?: string }>openExternal(url: string): Promise<void>settings(settings: Settings): Promise<Settings>+ restart(): Promise<void>diagnostics(): Promise<string>onEvent(listener: (event: AppEvent) => void): () => void}diff --git a/packages/core/src/schemas.ts b/packages/core/src/schemas.tsindex 677f0eb..c8f98bd 100644--- a/packages/core/src/schemas.ts+++ b/packages/core/src/schemas.ts@@ -191,6 +191,7 @@ export const settingsSchema = z.object({remoteImages: z.boolean(),notifications: z.boolean(),closeToTray: z.boolean(),+ systemTitleBar: z.boolean().optional(),defaultAccountId: id.optional(),signatures: z.record(z.string(), z.string().max(100_000)),htmlSignatures: z.record(z.string(), z.boolean()).optional(),@@ -252,5 +253,6 @@ export const ipcSchemas = {unsubscribe: z.tuple([id, id]),openExternal: z.tuple([z.string().max(8192)]),settings: z.tuple([settingsSchema]),+ restart: z.tuple([]),diagnostics: z.tuple([]),} satisfies Record<Exclude<keyof DesktopMailAPI, 'onEvent'>, z.ZodType>diff --git a/tests/core.test.ts b/tests/core.test.tsindex bfe1abf..17d0b2f 100644--- a/tests/core.test.ts+++ b/tests/core.test.ts@@ -272,6 +272,12 @@ describe('signatures', () => {expect(identitySignature(defaultSettings, identity)).toEqual({ format: 'text', value: '' })})+ it('accepts settings saved before the system title bar preference existed', () => {+ const { systemTitleBar: _, ...legacySettings } = defaultSettings+ expect(settingsSchema.parse(legacySettings)).toEqual(legacySettings)+ expect(settingsSchema.parse(legacySettings).systemTitleBar).toBeUndefined()+ })+it('accepts settings saved before HTML signatures existed', () => {expect(settingsSchema.parse({ ...defaultSettings, signatures: { [key]: 'Paul' } })).toEqual({...defaultSettings,diff --git a/tests/service.test.ts b/tests/service.test.tsindex e90b7dc..97bbbc9 100644--- a/tests/service.test.ts+++ b/tests/service.test.ts@@ -113,6 +113,16 @@ afterEach(async () => {await rm(directory, { recursive: true, force: true })})describe('durable mail operations', () => {+ it('keeps the title bar preference across restarts in either mode', async () => {+ for (const systemTitleBar of [true, false]) {+ await service.setSettings({ ...service.settings, systemTitleBar })+ service.dispose()+ service = new MailService(new JsonStore(directory), () => {})+ await service.init()+ expect((await service.bootstrap()).settings.systemTitleBar).toBe(systemTitleBar)+ }+ })+it('archives without removing unrelated folder memberships', async () => {const result = await service.mutate({targets: [{ accountId: account.id, threadId: 'thread' }],