Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "gen/schemas/desktop-schema.json",
"identifier": "shell",
"description": "Lets the hosted app use the shell's IPC: window dragging for the custom tab strip (core:default covers the double-click zoom but not start_dragging, which data-tauri-drag-region invokes on mousedown, so that one is granted explicitly), closing the window when Cmd+W lands outside a canvas tab (close), opening external links in the system browser (opener), and receiving the doop:// link that carries a sign-in finished in the system browser back into the app (deep-link, plus the core event it arrives on). Remote IPC is scoped to the production origin; self-hosters overriding DOOP_APP_URL must add their origin here. A server picked in the app gets this same capability for its own origin at runtime (src/server.rs). In dev the devUrl origin counts as local, so no entry is needed for it.",
"description": "Lets the hosted app use the shell's IPC: window dragging for the custom tab strip (core:default covers the double-click zoom but not start_dragging, which data-tauri-drag-region invokes on mousedown, so that one is granted explicitly), closing the window when Cmd+W lands outside a canvas tab (close), the Windows caption buttons the page draws once it swaps out the native frame (set-decorations, minimize, toggle-maximize; src/lib/windowFrame.ts), opening external links in the system browser (opener), and receiving the doop:// link that carries a sign-in finished in the system browser back into the app (deep-link, plus the core event it arrives on). Remote IPC is scoped to the production origin; self-hosters overriding DOOP_APP_URL must add their origin here. A server picked in the app gets this same capability for its own origin at runtime (src/server.rs). In dev the devUrl origin counts as local, so no entry is needed for it.",
"windows": ["main"],
"remote": {
"urls": ["https://doop.design", "https://www.doop.design"]
Expand All @@ -10,6 +10,9 @@
"core:default",
"core:window:allow-start-dragging",
"core:window:allow-close",
"core:window:allow-set-decorations",
"core:window:allow-minimize",
"core:window:allow-toggle-maximize",
"deep-link:default",
{
"identifier": "opener:allow-open-url",
Expand Down
14 changes: 14 additions & 0 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
// only marks the page as desktop; opening links in the system browser goes
// through the opener plugin, granted in capabilities/default.json.
//
// Windows opens with the native frame, and the page drops it itself
// (set_decorations, granted in capabilities/default.json) and draws the
// caption buttons at the end of the tab strip (src/lib/windowFrame.ts). The
// page rather than the shell decides because the two ship apart: a server
// running an older app never drops the frame, so the window always keeps a
// way to be closed.
//
// Because tabs live in the page, the macOS menu is built here rather than
// taken from Tauri's default: that one binds Cmd+W to "Close Window", which
// on a single-window app closes the whole app. Ours binds Cmd+W to "Close
Expand Down Expand Up @@ -492,6 +499,13 @@ fn main() {
.on_page_load(move |window, payload| {
if payload.event() == PageLoadEvent::Started {
updates::page_loading(window.app_handle());
// Windows: the page drops the native frame once it
// has loaded (src/lib/windowFrame.ts). Give it back
// on every full load, so a page that never takes
// over (the webview's error page after a failed
// reload, an older app) still has a way to close.
#[cfg(windows)]
let _ = window.set_decorations(true);
}
#[cfg(all(chromium, target_os = "macos"))]
if migrating {
Expand Down
14 changes: 10 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { adminApi } from './lib/api'
import { Button } from './components/ui/button'
import { AuthScreen } from './components/ui/screen'
import { DesktopTabs, ShellDragBar } from './components/DesktopTabs'
import { WindowControls } from './components/WindowControls'
import { setTabsUser } from './lib/desktop'
import { isDesktopShell } from './lib/shell'
import { SIGNUP_PARAM, parseSignupMethod } from '../shared/firstCanvas'
Expand Down Expand Up @@ -166,16 +167,15 @@ export function App() {
player stays behind sign-in. */
if (!session && canvasId && !path.includes('/proto') && !signInRequired && !guestAuth)
return (
<>
<ShellDragBar />
<ShellDragBar>
<CanvasPage
canvasId={canvasId}
key={canvasId}
guest
onSignUp={() => setGuestAuth('signup')}
onSignIn={() => setGuestAuth('signin')}
/>
</>
</ShellDragBar>
)

/* signed out: every path lands on the sign-in form. The marketing site is
Expand Down Expand Up @@ -258,8 +258,13 @@ export function App() {
function ImpersonationBanner({ name }: { name: string }) {
const t = useT()
const [leaving, setLeaving] = useState(false)
/* the banner is the top of the window while it shows, so on Windows it is
also the drag handle and carries the caption buttons (windowFrame.ts) */
return (
<div className="fixed inset-x-0 top-0 z-[900] flex min-h-14 items-center justify-between gap-2 border-b border-accent-ink px-2.5 py-[7px] text-[11.5px] leading-tight text-accent-ink backdrop-blur-[6px] [background:repeating-linear-gradient(-45deg,rgba(208,52,31,0.16)_0_10px,rgba(208,52,31,0.08)_10px_20px)] sm:h-10 sm:min-h-0 sm:justify-center sm:gap-4 sm:text-[13px]">
<div
data-tauri-drag-region
className="fixed inset-x-0 top-0 z-[900] flex min-h-14 items-center justify-between gap-2 border-b border-accent-ink px-2.5 py-[7px] text-[11.5px] leading-tight text-accent-ink backdrop-blur-[6px] [background:repeating-linear-gradient(-45deg,rgba(208,52,31,0.16)_0_10px,rgba(208,52,31,0.08)_10px_20px)] sm:h-10 sm:min-h-0 sm:justify-center sm:gap-4 sm:text-[13px]"
>
<span>
{t('auth.viewingAsBefore')} <strong>{name}</strong> {t('auth.viewingAsAfter')}
</span>
Expand All @@ -279,6 +284,7 @@ function ImpersonationBanner({ name }: { name: string }) {
>
{leaving ? t('auth.leaving') : t('auth.stopViewing')}
</Button>
<WindowControls className="absolute inset-y-0 right-0" />
Comment thread
davidabou marked this conversation as resolved.
Resolved
</div>
)
}
39 changes: 35 additions & 4 deletions src/components/DesktopTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react'
import type { ReactNode } from 'react'
import { api } from '../lib/api'
import { posthog } from '../lib/posthog'
import { navigate } from '../App'
Expand All @@ -24,6 +25,8 @@ import {
} from '../lib/desktop'
import { chordHint } from '../lib/actions/chords'
import { hasInsetTrafficLights, isDesktopShell } from '../lib/shell'
import { useWindowFrame } from '../lib/windowFrame'
import { WindowControls } from './WindowControls'
import type { CanvasTab } from '../lib/desktop'
import { useT } from '../lib/i18n'

Expand All @@ -33,6 +36,8 @@ import { useT } from '../lib/i18n'
* floating over this strip) — so the strip doubles as the window's drag
* handle via data-tauri-drag-region, which Tauri only honours on the exact
* element carrying the attribute, leaving the tabs themselves clickable.
* On Windows the page replaces the native frame too (src/lib/windowFrame.ts)
* and the strip ends in the caption buttons.
*/
export function DesktopTabs({ path }: { path: string }) {
const t = useT()
Expand Down Expand Up @@ -119,6 +124,7 @@ export function DesktopTabs({ path }: { path: string }) {
>
+
</button>
<WindowControls className="-mr-2 ml-auto" />
</div>
)
}
Expand Down Expand Up @@ -159,8 +165,33 @@ function TabContextMenu({ tab, path }: { tab: CanvasTab; path: string }) {
}

/** Invisible drag handle for shell screens without the tab strip (signed
* out): the overlay title bar has no native drag area of its own. */
export function ShellDragBar() {
if (!hasInsetTrafficLights()) return null
return <div data-tauri-drag-region className="fixed inset-x-0 top-0 z-[950] h-6" />
* out): the overlay title bar has no native drag area of its own. On
* Windows, once the page owns the frame, it also carries the caption
* buttons — these screens would otherwise have no way to close the window.
* A fixed-position screen passed as `children` (the guest canvas, whose
* toolbar sits 14px from the top) is moved below that bar through the
* --app-inset contract (App.tsx) instead of having its toolbar covered. */
export function ShellDragBar({ children }: { children?: ReactNode }) {
const customFrame = useWindowFrame((s) => s.custom)
if (customFrame)
return (
<>
<div
data-tauri-drag-region
className={cn(
'fixed inset-x-0 top-0 z-[950] flex h-8 justify-end',
children && 'border-b border-line bg-paper-deep',
)}
>
<WindowControls />
</div>
{children && <div className="[--app-inset:32px]">{children}</div>}
</>
)
return (
<>
{hasInsetTrafficLights() && <div data-tauri-drag-region className="fixed inset-x-0 top-0 z-[950] h-6" />}
{children}
</>
)
}
70 changes: 70 additions & 0 deletions src/components/WindowControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { ReactNode } from 'react'
import { cn } from '@/lib/utils'
import { Pressable } from './ui/pressable'
import { useT } from '../lib/i18n'
import { closeWindow, minimizeWindow, toggleMaximizeWindow, useWindowFrame } from '../lib/windowFrame'

/**
* Minimize / maximize / close for the Windows shell once the page has
* replaced the native frame (src/lib/windowFrame.ts); renders nothing
* anywhere else. Sized and drawn like the Windows 11 caption buttons —
* 46px wide, full bar height, 10px hairline glyphs — so the window still
* reads as a Windows window.
*/
export function WindowControls({ className }: { className?: string }) {
const t = useT()
const custom = useWindowFrame((s) => s.custom)
const maximized = useWindowFrame((s) => s.maximized)
if (!custom) return null
return (
<div className={cn('flex flex-none self-stretch', className)}>
<CaptionButton label={t('shell.windowMinimize')} onClick={minimizeWindow}>
<path d="M0 5.5h10" />
</CaptionButton>
<CaptionButton
label={t(maximized ? 'shell.windowRestore' : 'shell.windowMaximize')}
onClick={toggleMaximizeWindow}
>
{maximized ? <path d="M.5 2.5h7v7h-7zM2.5 2.5v-2h7v7h-2" /> : <path d="M.5.5h9v9h-9z" />}
</CaptionButton>
<CaptionButton
label={t('shell.windowClose')}
onClick={closeWindow}
/* red on hover is how Windows marks Close; the failure red stands in
for the system's so it follows the theme */
className="hover:bg-destructive hover:text-white active:bg-destructive/90"
>
<path d="M0 0l10 10M10 0L0 10" />
</CaptionButton>
</div>
)
}

function CaptionButton({
label,
onClick,
className,
children,
}: {
label: string
onClick: () => void
className?: string
children: ReactNode
}) {
return (
<Pressable
layout="inline"
aria-label={label}
title={label}
onClick={onClick}
className={cn(
'w-[46px] cursor-default justify-center text-ink-soft transition-colors hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.1]',
className,
)}
>
<svg viewBox="0 0 10 10" className="size-2.5" fill="none" stroke="currentColor" strokeWidth={1} aria-hidden>
{children}
</svg>
</Pressable>
)
}
6 changes: 5 additions & 1 deletion src/lib/desktop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Doop in the desktop shell (desktop/src-tauri). The shell is one webview
with an overlay title bar; canvases open Figma-style in a tab strip the
with an overlay title bar (on Windows, a frame the page draws:
windowFrame.ts); canvases open Figma-style in a tab strip the
web app draws itself (src/components/DesktopTabs.tsx). Tabs are ordinary
in-page navigations — this module only keeps the strip's state and the
shell-specific plumbing. In a plain browser every entry point returns
Expand All @@ -19,6 +20,7 @@ import {
rememberPendingSignIn,
} from './desktopAuth'
import { isDesktopShell } from './shell'
import { initWindowFrame } from './windowFrame'
import { codexSetupTarget } from './codexConnection'
import { forgetPendingConnect, isPendingConnect, parseDesktopConnectLink } from './desktopConnect'
import { safeRelativeTarget } from './safeTarget'
Expand Down Expand Up @@ -334,6 +336,8 @@ export function openExternal(url: string): boolean {
* browser instead. Runs once from main.tsx; no-op outside the shell. */
export function initDesktopShell() {
if (!isDesktopShell()) return
/* Windows: the page's caption buttons take over from the native frame */
initWindowFrame().catch(console.error)
Comment thread
davidabou marked this conversation as resolved.
Resolved
/* Cmd+W: on macOS the shell's menu owns the shortcut (main.rs) and relays
it as an event — the page never sees the keystroke. Windows has no menu
bar, so Ctrl+W arrives as a plain keydown. Both close the active tab. */
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/en/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const shell = {
website: 'Doop website',
appearance: 'Appearance',
logOut: 'Log out',
windowMinimize: 'Minimize',
windowMaximize: 'Maximize',
windowRestore: 'Restore',
windowClose: 'Close',
updateTitle: 'Update available',
updateBody: 'Doop {version} is ready. Restart to apply the update.',
updateAgentNote: 'Restarting stops an agent run in progress.',
Expand Down
4 changes: 4 additions & 0 deletions src/lib/i18n/pt-BR/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const shell: Catalog['shell'] = {
website: 'Site do Doop',
appearance: 'Aparência',
logOut: 'Sair',
windowMinimize: 'Minimizar',
windowMaximize: 'Maximizar',
windowRestore: 'Restaurar',
windowClose: 'Fechar',
updateTitle: 'Atualização disponível',
updateBody: 'O Doop {version} está pronto. Reinicie para aplicar a atualização.',
updateAgentNote: 'Reiniciar interrompe uma execução de agente em andamento.',
Expand Down
6 changes: 3 additions & 3 deletions src/lib/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function shellVersionAtLeast(major: number, minor: number, patch: number): boole

/** The overlay title bar (traffic lights floating over the page) arrived
* with shell 0.1.2; older shells keep a native title bar and need no inset.
* Only macOS has an overlay title bar: Windows shells keep the native frame,
* so the page must not reserve room for traffic lights or act as the
* window's drag handle there. */
* Only macOS has traffic lights: Windows shells open with the native frame,
* which the page may swap for caption buttons of its own on the right
* (src/lib/windowFrame.ts), so no room is reserved on the left there. */
export function hasInsetTrafficLights(): boolean {
return desktopPlatform() === 'macos' && shellVersionAtLeast(0, 1, 2)
}
78 changes: 78 additions & 0 deletions src/lib/windowFrame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* The window frame on Windows. macOS shells overlay the title bar from the
start (desktop/src-tauri/src/main.rs); Windows shells open with the native
frame and the page swaps it for its own: the tab strip (and, on screens
without it, ShellDragBar) carries minimize / maximize / close
(src/components/WindowControls.tsx).

The page drops the frame rather than the shell, because shell and app ship
apart: a shell older than the `set_decorations` grant refuses the call and
keeps its native frame, and a server running an app older than this module
never asks — so no combination leaves a window without a way to close it.
Detected by the call succeeding rather than by version, like the other
shell capabilities. */

import { create } from 'zustand'
import { desktopPlatform } from './shell'

type AppWindow = {
setDecorations: (decorations: boolean) => Promise<void>
isMaximized: () => Promise<boolean>
onResized: (handler: () => void) => Promise<() => void>
minimize: () => Promise<void>
toggleMaximize: () => Promise<void>
close: () => Promise<void>
}

type FrameBridge = {
__TAURI__?: { window?: { getCurrentWindow?: () => AppWindow } }
}

type FrameState = {
/** The page draws the window controls: the native frame is gone. */
custom: boolean
/** Shows Restore instead of Maximize. */
maximized: boolean
}

export const useWindowFrame = create<FrameState>(() => ({ custom: false, maximized: false }))

function appWindow(): AppWindow | null {
return (globalThis as FrameBridge).__TAURI__?.window?.getCurrentWindow?.() ?? null
}

/** Swap the native frame for the page's own. Runs once from
* initDesktopShell; a no-op off Windows and outside the shell. */
export async function initWindowFrame(): Promise<void> {
if (desktopPlatform() !== 'windows') return
const win = appWindow()
if (!win) return
try {
await win.setDecorations(false)
Comment thread
davidabou marked this conversation as resolved.
Resolved
} catch {
/* a shell without the grant: its native frame stays, and so must
the page's hands off the controls */
return
}
const syncMaximized = () =>
win
.isMaximized()
.then((maximized) => useWindowFrame.setState({ maximized }))
.catch(console.error)
useWindowFrame.setState({ custom: true })
await syncMaximized()
/* Win+Up, Aero snap and the drag region's double-click maximize without
going through the controls */
await win.onResized(() => void syncMaximized())
}

export function minimizeWindow() {
appWindow()?.minimize().catch(console.error)
}

export function toggleMaximizeWindow() {
appWindow()?.toggleMaximize().catch(console.error)
}

export function closeWindow() {
appWindow()?.close().catch(console.error)
}
Loading
Loading