Add macOS native titlebar support

This commit is contained in:
Yuri Karamian
2026-02-13 01:30:10 +01:00
parent 6dfea864f3
commit ea323e508b
3 changed files with 33 additions and 2 deletions
+16
View File
@@ -0,0 +1,16 @@
{
"app": {
"windows": [
{
"label": "main",
"decorations": true,
"titleBarStyle": "Overlay",
"hiddenTitle": true,
"trafficLightPosition": {
"x": 12,
"y": 10
}
}
]
}
}
+8 -1
View File
@@ -28,6 +28,7 @@
} from '$lib/stores/app'; } from '$lib/stores/app';
const appWindow = getCurrentWindow(); const appWindow = getCurrentWindow();
const isMac = navigator.platform.startsWith('Mac');
import { loadVaultState, saveVaultState, readNote } from '$lib/api'; import { loadVaultState, saveVaultState, readNote } from '$lib/api';
import { debounce } from '$lib/utils/debounce'; import { debounce } from '$lib/utils/debounce';
import type { VaultState, FileEvent } from '$lib/types'; import type { VaultState, FileEvent } from '$lib/types';
@@ -211,7 +212,7 @@
<div class="app-shell"> <div class="app-shell">
{#if $focusMode} {#if $focusMode}
<!-- svelte-ignore a11y_no_static_element_interactions --> <!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="focus-topbar" onmousedown={(e) => { if (!(e.target as HTMLElement).closest('button')) appWindow.startDragging(); }}> <div class="focus-topbar" class:macos={isMac} onmousedown={(e) => { if (!(e.target as HTMLElement).closest('button')) appWindow.startDragging(); }}>
<span class="focus-title">{$activeNote?.meta.title || 'Untitled'}</span> <span class="focus-title">{$activeNote?.meta.title || 'Untitled'}</span>
<div class="focus-controls"> <div class="focus-controls">
<button class="focus-btn focus-active" onclick={() => ($focusMode = false)} title="Exit focus mode (Escape)"> <button class="focus-btn focus-active" onclick={() => ($focusMode = false)} title="Exit focus mode (Escape)">
@@ -219,6 +220,7 @@
<path d="M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"/> <path d="M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"/>
</svg> </svg>
</button> </button>
{#if !isMac}
<button class="focus-btn" onmousedown={(e) => e.stopPropagation()} onclick={() => appWindow.minimize()} title="Minimize"> <button class="focus-btn" onmousedown={(e) => e.stopPropagation()} onclick={() => appWindow.minimize()} title="Minimize">
<svg width="10" height="10" viewBox="0 0 10 10"><line x1="1" y1="5" x2="9" y2="5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg> <svg width="10" height="10" viewBox="0 0 10 10"><line x1="1" y1="5" x2="9" y2="5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>
</button> </button>
@@ -228,6 +230,7 @@
<button class="focus-btn focus-close" onmousedown={(e) => e.stopPropagation()} onclick={() => appWindow.close()} title="Close"> <button class="focus-btn focus-close" onmousedown={(e) => e.stopPropagation()} onclick={() => appWindow.close()} title="Close">
<svg width="10" height="10" viewBox="0 0 10 10"><line x1="1.5" y1="1.5" x2="8.5" y2="8.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/><line x1="8.5" y1="1.5" x2="1.5" y2="8.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg> <svg width="10" height="10" viewBox="0 0 10 10"><line x1="1.5" y1="1.5" x2="8.5" y2="8.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/><line x1="8.5" y1="1.5" x2="1.5" y2="8.5" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>
</button> </button>
{/if}
</div> </div>
</div> </div>
{:else} {:else}
@@ -349,4 +352,8 @@
background: #e81123; background: #e81123;
color: white; color: white;
} }
.focus-topbar.macos {
padding-left: 78px;
}
</style> </style>
+9 -1
View File
@@ -7,6 +7,7 @@
} = $props(); } = $props();
const appWindow = getCurrentWindow(); const appWindow = getCurrentWindow();
const isMac = navigator.platform.startsWith('Mac');
let maximized = $state(false); let maximized = $state(false);
async function checkMaximized() { async function checkMaximized() {
@@ -59,7 +60,7 @@
</script> </script>
<!-- svelte-ignore a11y_no_static_element_interactions --> <!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="titlebar" onmousedown={handleMouseDown}> <div class="titlebar" class:macos={isMac} onmousedown={handleMouseDown}>
<div class="titlebar-brand"> <div class="titlebar-brand">
<svg width="18" height="18" viewBox="0 0 48 48" fill="none"> <svg width="18" height="18" viewBox="0 0 48 48" fill="none">
<rect width="48" height="48" rx="12" fill="var(--accent)" /> <rect width="48" height="48" rx="12" fill="var(--accent)" />
@@ -96,6 +97,7 @@
New Note New Note
</button> </button>
</div> </div>
{#if !isMac}
<div class="titlebar-controls"> <div class="titlebar-controls">
<button class="titlebar-btn" onclick={minimize} title="Minimize"> <button class="titlebar-btn" onclick={minimize} title="Minimize">
<svg width="10" height="10" viewBox="0 0 10 10"> <svg width="10" height="10" viewBox="0 0 10 10">
@@ -121,6 +123,7 @@
</svg> </svg>
</button> </button>
</div> </div>
{/if}
</div> </div>
<style> <style>
@@ -252,4 +255,9 @@
background: #e81123; background: #e81123;
color: white; color: white;
} }
/* macOS: add left padding for native traffic light buttons */
.titlebar.macos .titlebar-brand {
padding-left: 78px;
}
</style> </style>