Introducing a new way to review your PRs.

Read the announcement

lencx / chatgpt

❄️ ChatGPT Desktop Application (Mac, Windows and Linux)

View on GitHub

10 documents · Updated Nov 16, 2026

docs / window-chrome

Window Chrome

Overview

This doc covers the frontend chrome that sits around the embedded view and connects titlebar controls to Tauri-native window and webview behavior:

Coverage: src/…/Titlebar.tsx, src/…/WinTitlebar.tsx

src/…/Titlebar.tsx renders the main in-app titlebar. On mount it reads persisted native/app state with invoke<I.AppConf>('get_app_conf'), then mirrors ask_mode, stay_on_top, theme, and mac_titlebar_hidden into React state for the ask-mode, pin, theme, and hidden-titlebar controls. It also calls getCurrentWindow() and listens for tauri://resize so it can keep fullScreen in sync with win.isFullscreen(). That fullscreen state changes left padding: macOS gets pl-[80px] when not fullscreen to avoid the native traffic-light area, while fullscreen or non-macOS gets pl-[10px].

Titlebar also listens for a custom navigation:change event on the current Tauri window. The event payload is expected to contain { url }; the component stores the raw URL and derives a hostname with new URL(url), falling back to the raw URL when parsing fails. When a hostname exists, it renders a small link pill that opens the current URL externally through @tauri-apps/plugin-shell's open(url).

The titlebar buttons bridge to backend/native commands with Tauri invoke calls rather than mutating browser state directly. Reload and navigation call view_reload, view_go_back, and view_go_forward; ask mode toggles local state and invokes set_view_ask with { enabled }; pin toggles local state and invokes window_pin with { pin }; theme cycling invokes set_theme with the next string value; settings invokes open_settings. Theme state is only initialized from get_app_conf in this component, so the visible icon changes when the app config value changes on a later mount or through outside state propagation, not immediately inside handleTheme.

Hidden-titlebar behavior is macOS-only: titlebarHidden is computed as info.isMac && isTitlebarHidden, where info.isMac comes from src/…/useInfo.tsx via @tauri-apps/plugin-os. When hidden-titlebar mode is active, the left navigation group and right settings group are normally hidden and appear on group hover with responsive Tailwind classes. The outer container and left group carry data-tauri-drag-region, allowing the custom chrome area to act as a native drag region while still hosting clickable controls.

src/…/WinTitlebar.tsx is the Windows-style window-controls cluster. It targets the native Tauri window labeled core via Window.getByLabel('core'). On mount it checks isMaximized() and stores that as isMax; minimize calls win?.minimize(), close calls win?.close(), and maximize/restore calls win?.toggleMaximize() before flipping the local isMax state so the icon alternates between WindowMaximize and WindowRestore.

Coupling

  • If the backend command names or payloads change, update src/…/Titlebar.tsx at the same time: it hard-codes get_app_conf, view_reload, view_go_back, view_go_forward, window_pin, set_view_ask, set_theme, and open_settings, including the { pin }, { enabled }, and { theme } argument shapes.
  • If the app configuration schema changes, keep src/…/Titlebar.tsx aligned with I.AppConf: it expects ask_mode, stay_on_top, theme, and mac_titlebar_hidden to be present in the result from get_app_conf.
  • If the native/webview layer changes navigation events, verify src/…/Titlebar.tsx: it listens for navigation:change on the current window and expects event.payload.url to be parseable or displayable.
  • If the Tauri window label changes from core, update src/…/WinTitlebar.tsx; all minimize, close, maximize, and initial maximize-state checks look up that label explicitly.
  • If macOS titlebar spacing or hidden-titlebar behavior changes, check both src/…/Titlebar.tsx and src/…/useInfo.tsx: the titlebar relies on useInfo().isMac to decide whether hidden chrome and the macOS left padding apply.

Risks

  • src/…/WinTitlebar.tsx flips isMax locally after toggleMaximize() instead of listening for native resize/maximize events. If the window is maximized or restored outside this button, the maximize/restore icon can become stale until the component remounts.
  • src/…/Titlebar.tsx updates local ask and pin state before the corresponding invoke calls complete and does not handle rejection. If set_view_ask or window_pin fails, the chrome can show ask mode or pin state that the native side did not actually apply.