Skip to content

Build your personal knowledge base with Trilium Notes

feat(desktop): draw the setup window's controls over the page

Elian Doran94f9a09dc4f0
diff --git a/apps/client/src/services/native_window.spec.ts b/apps/client/src/services/native_window.spec.ts
index 61a2be198e..ecfe9292e8 100644
--- a/apps/client/src/services/native_window.spec.ts
+++ b/apps/client/src/services/native_window.spec.ts
@@ -5,10 +5,8 @@ import { syncNativeWindowWithTheme } from "./native_window.js";
type Glob = NonNullable<typeof window.glob>;
-const optionsCtrl = vi.hoisted(() => ({ get: vi.fn(() => "false") }));
const themeCtrl = vi.hoisted(() => ({ getThemeStyle: vi.fn(() => "auto") }));
-vi.mock("./options.js", () => ({ default: optionsCtrl }));
vi.mock("./theme.js", () => ({ getThemeStyle: themeCtrl.getThemeStyle }));
/** The subset of the Electron window API this module drives, all spied. */
@@ -39,7 +37,6 @@ function setPlatform(platform: Glob["platform"]) {
beforeEach(() => {
vi.restoreAllMocks();
vi.clearAllMocks();
- optionsCtrl.get.mockReturnValue("false");
themeCtrl.getThemeStyle.mockReturnValue("auto");
win.getZoomFactor.mockReturnValue(1);
setPlatform("linux");
@@ -173,7 +170,7 @@ describe("syncNativeWindowWithTheme", () => {
});
it("leaves the title bar alone when the native one is visible, since setting the overlay then throws", () => {
- optionsCtrl.get.mockReturnValue("true");
+ window.glob.hasNativeTitleBar = true;
stubThemeVariables({
"--native-titlebar-background": "#111",
"--native-titlebar-foreground": "#eee"
diff --git a/apps/client/src/services/native_window.ts b/apps/client/src/services/native_window.ts
index d40e80a4f5..d062576377 100644
--- a/apps/client/src/services/native_window.ts
+++ b/apps/client/src/services/native_window.ts
@@ -1,6 +1,5 @@
import type { ElectronWindowApi } from "@triliumnext/commons";
-import options from "./options.js";
import { getThemeStyle } from "./theme.js";
/**
@@ -35,8 +34,9 @@ export function syncNativeWindowWithTheme() {
applyDarkOrLightMode(win);
applyTransparencyEffects(win, style);
- // The title bar overlay only exists when the native title bar is hidden; setting it otherwise throws.
- if (options.get("nativeTitleBarVisible") !== "true") {
+ // The title bar overlay only exists on a window created without the native title bar; setting it
+ // otherwise throws. `hasNativeTitleBar` is fixed at creation, unlike the option it comes from.
+ if (!window.glob.hasNativeTitleBar) {
applyTitleBarButtons(win, style);
}
}
diff --git a/apps/client/src/setup.css b/apps/client/src/setup.css
index d077324a3b..c53525af72 100644
--- a/apps/client/src/setup.css
+++ b/apps/client/src/setup.css
@@ -138,11 +138,10 @@ body.setup {
.page {
--page-padding-inline: 2em;
--page-padding-block: 2em;
- --page-padding-top: var(--page-padding-block);
display: flex;
flex-direction: column;
height: 100%;
- padding-top: calc(var(--page-padding-top) + var(--safe-area-inset-top, env(safe-area-inset-top)));
+ padding-top: calc(var(--page-padding-block) + env(titlebar-area-height, 0px) + var(--safe-area-inset-top, env(safe-area-inset-top)));
padding-bottom: calc(var(--page-padding-block) + var(--safe-area-inset-bottom, env(safe-area-inset-bottom)));
padding-left: calc(var(--page-padding-inline) + var(--safe-area-inset-left, env(safe-area-inset-left)));
padding-right: calc(var(--page-padding-inline) + var(--safe-area-inset-right, env(safe-area-inset-right)));
@@ -152,11 +151,6 @@ body.setup {
--page-padding-block: 1em;
}
- /* Clears the traffic lights, which overlay the page under the hidden title bar. */
- body.electron.platform-darwin & {
- --page-padding-top: 2em;
- }
-
>.back-button {
/* `.page` scrolls (not `.setup-container`), so sticky is required here, not
absolute, to stay in flow and follow the scroll. */
@@ -229,7 +223,7 @@ body.setup {
margin: 0;
border-radius: 0;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
- padding-top: calc(1em + var(--safe-area-inset-top, env(safe-area-inset-top)));
+ padding-top: calc(1em + env(titlebar-area-height, 0px) + var(--safe-area-inset-top, env(safe-area-inset-top)));
padding-inline-end: 2.5em;
user-select: text;
@@ -241,7 +235,7 @@ body.setup {
button {
position: absolute;
- top: 0.5em;
+ top: calc(0.5em + env(titlebar-area-height, 0px));
inset-inline-end: 0.5em;
}
}
@@ -368,14 +362,14 @@ body.setup.background-effects .setup-container {
background: transparent;
}
-/* macOS: draggable title bar region and traffic light buttons */
-body.setup.platform-darwin {
+/* The band the window controls are drawn in, which drags the window in place of the title bar. */
+body.setup.electron {
.drag-region {
position: absolute;
top: 0;
left: 0;
right: 0;
- height: 40px;
+ height: env(titlebar-area-height, 40px);
-webkit-app-region: drag;
z-index: 10;
}
diff --git a/apps/client/src/setup.tsx b/apps/client/src/setup.tsx
index e2874893d0..1bcadbd224 100644
--- a/apps/client/src/setup.tsx
+++ b/apps/client/src/setup.tsx
@@ -8,7 +8,9 @@ import { useTranslation } from "react-i18next";
import logo from "./assets/icon-color.svg?url";
import { getCurrentLanguage, initLocale, t } from "./services/i18n";
+import { syncNativeWindowWithTheme } from "./services/native_window";
import server from "./services/server";
+import { onEffectiveThemeStyleChange } from "./services/theme";
import { isElectron, isMobileApp } from "./services/utils";
import SetupBackupDatabase from "./setup_backup";
import ExistingData, {
@@ -47,6 +49,12 @@ async function main() {
}
render(<App />, bodyWrapper);
document.body.replaceChildren(bodyWrapper);
+
+ // Colors the window controls drawn over the page, and positions them, from the theme.
+ if (isElectron()) {
+ syncNativeWindowWithTheme();
+ onEffectiveThemeStyleChange(() => syncNativeWindowWithTheme());
+ }
}
type State = "unlock" | "backupDatabase" | "existingData" | "selectLanguage" | "firstOptions" | "createNewDocumentOptions" | "createNewDocumentWithDemo" | "createNewDocumentEmpty" | "restoreFromBackup" | "syncFromDesktop" | "syncFromServer" | "syncFromServerInProgress" | "syncFromDesktopInProgress" | "syncFailed";
diff --git a/apps/desktop/src/services/window.spec.ts b/apps/desktop/src/services/window.spec.ts
index ed2c06703c..ce82f824c3 100644
--- a/apps/desktop/src/services/window.spec.ts
+++ b/apps/desktop/src/services/window.spec.ts
@@ -528,6 +528,18 @@ describe("window service", () => {
expect(opts.vibrancy).toBe("under-window");
});
+ it("draws the window controls over the page on every platform", async () => {
+ for (const platform of [ "isLinux", "isWindows", "isMac" ] as const) {
+ state.isLinux = state.isWindows = state.isMac = false;
+ state[platform] = true;
+ await windowService.createSetupWindow();
+ const opts = state.windows[state.windows.length - 1].opts as Record<string, unknown>;
+ expect(opts.titleBarStyle).toBe(platform === "isMac" ? "hiddenInset" : "hidden");
+ expect(opts.titleBarOverlay).toBe(true);
+ expect(opts.frame).toBeUndefined();
+ }
+ });
+
it("names the window for what it is: getting started, or starting over", async () => {
// Asserted as the resolved English rather than as the key, which also proves both
// entries are really in the catalog the Electron main process reads.
diff --git a/apps/desktop/src/services/window.ts b/apps/desktop/src/services/window.ts
index 1bb6b848bb..0e46361ebf 100644
--- a/apps/desktop/src/services/window.ts
+++ b/apps/desktop/src/services/window.ts
@@ -406,7 +406,11 @@ async function createSetupWindow() {
icon: getIcon(),
// Background effects (Mica on Windows 11 22H2+, vibrancy on macOS)
...(coreUtils.isWindows() && supportsBackgroundMaterial && { backgroundMaterial: "mica" as const }),
- ...(coreUtils.isMac() && { transparent: true, visualEffectState: "active" as const, vibrancy: "under-window" as const, titleBarStyle: "hiddenInset" as const }),
+ ...(coreUtils.isMac() && { transparent: true, visualEffectState: "active" as const, vibrancy: "under-window" as const }),
+ // The window controls draw over the page, as in the main window with its default
+ // `nativeTitleBarVisible`; the page reserves `env(titlebar-area-height)` for them.
+ titleBarStyle: coreUtils.isMac() ? "hiddenInset" : "hidden",
+ titleBarOverlay: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,