Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions src/preload/windows-titlebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ function installLayout(document: Document): void {
body.dsh-desktop-windows-titlebar-layout [data-slot="conversation.session.header"] > header {
padding-right: calc(var(${CAPTION_WIDTH_PROPERTY}, 140px) + 52px) !important;
}
body.dsh-desktop-windows-titlebar-layout button,
body.dsh-desktop-windows-titlebar-layout a,
body.dsh-desktop-windows-titlebar-layout input,
body.dsh-desktop-windows-titlebar-layout select,
body.dsh-desktop-windows-titlebar-layout textarea,
body.dsh-desktop-windows-titlebar-layout [role="button"],
body.dsh-desktop-windows-titlebar-layout [data-dsh-no-drag] {
-webkit-app-region: no-drag !important;
}
`
document.head.appendChild(style)
}
Expand All @@ -142,22 +151,22 @@ function trackSidebarLayout(document: Document): void {
const resizeObserver = new ResizeObserver(() => updateSidebarWidth())

const updateSidebarWidth = (): void => {
if (!observedSidebarColumn) return
const width = observedSidebarColumn.getBoundingClientRect().width
if (width > 0) {
document.documentElement.style.setProperty(SIDEBAR_WIDTH_PROPERTY, `${width}px`)
if (!observedSidebarColumn) {
document.documentElement.style.setProperty(SIDEBAR_WIDTH_PROPERTY, '0px')
return
}
const width = observedSidebarColumn.getBoundingClientRect().width
document.documentElement.style.setProperty(SIDEBAR_WIDTH_PROPERTY, `${Math.max(0, width)}px`)
}

const sync = (): void => {
const sidebarRoot = document.querySelector<HTMLElement>('[data-dsh-sidebar-root]')
const sidebarColumn = sidebarRoot?.parentElement ?? null
if (!sidebarColumn) return

if (sidebarColumn !== observedSidebarColumn) {
if (observedSidebarColumn) resizeObserver.unobserve(observedSidebarColumn)
observedSidebarColumn = sidebarColumn
resizeObserver.observe(sidebarColumn)
if (sidebarColumn) resizeObserver.observe(sidebarColumn)
}
updateSidebarWidth()
}
Expand Down Expand Up @@ -361,10 +370,10 @@ const titlebarStyles = `
content: "";
position: absolute;
top: 0;
left: 0;
right: 44px;
height: ${WINDOWS_TITLEBAR_HEIGHT}px;
left: var(${SIDEBAR_WIDTH_PROPERTY}, 280px);
pointer-events: auto;
pointer-events: none;
-webkit-app-region: drag;
}
.menuButton {
Expand Down
11 changes: 5 additions & 6 deletions test/windows-titlebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ describe('Windows titlebar menu', () => {
expect(preload).toContain('.safeArea::before')
expect(preload).toContain('height: ${WINDOWS_TITLEBAR_HEIGHT}px')
expect(preload).toContain('body.dsh-desktop-windows-titlebar-layout > #root')
expect(preload).toContain('-webkit-app-region: drag')
expect(preload).toContain('-webkit-app-region: no-drag')
expect(preload).toContain('env(titlebar-area-width')
expect(preload).toContain("const CAPTION_WIDTH_PROPERTY = '--dsh-desktop-windows-caption-width'")
expect(preload).toContain('[data-slot="conversation.session.header"] > header')
expect(preload).toContain('padding-right: calc(var(${CAPTION_WIDTH_PROPERTY}, 140px) + 52px) !important')
expect(preload).toContain('left: 0')
expect(preload).toContain('pointer-events: none')
expect(preload).toContain('body.dsh-desktop-windows-titlebar-layout button')
expect(preload).toContain('-webkit-app-region: no-drag !important')
expect(preload).toContain("document.documentElement.style.setProperty(SIDEBAR_WIDTH_PROPERTY, '0px')")
})

it('accepts only the fixed menu command allowlist', async () => {
Expand Down
Loading