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
2 changes: 1 addition & 1 deletion apps/desktop/scripts/smoke-window.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ async function smokeTraceWindows(window, projectId) {
await evaluate(`document.querySelector(${JSON.stringify(editor)}).focus()`);
await window.webContents.insertText(' and continued afterward');
await waitFor(async () => (await draft())?.includes('continued afterward'), 'Assistant composer stopped accepting input');
if (openedChat) await evaluate("document.querySelector('.cw-chat-button').click()");
if (openedChat) await evaluate("document.querySelector('.cw-assistant-collapse').click()");
}

async function waitFor(check, message, attempts = 150) {
Expand Down
20 changes: 12 additions & 8 deletions src/canvas/desktop-chrome.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/* Desktop chrome shares the existing project toolbar; the canvas stays opaque. */
html[data-desktop-platform="darwin"],
html[data-desktop-platform="darwin"] body,
html[data-desktop-platform="darwin"] #root,
html[data-desktop-platform="darwin"] .cw-workspace {
html[data-desktop-platform="darwin"] #root {
background: transparent;
}
html[data-desktop-chrome] {
--desktop-toolbar-height: 48px;
--od-workspace-background: #0d0d0d;
}
html[data-desktop-chrome][data-theme="light"] {
--od-workspace-background: #f7f8fa;
}
html[data-desktop-chrome][data-desktop-platform="darwin"] .cw-workspace {
background: linear-gradient(to right, transparent var(--od-sidebar-width), var(--od-workspace-background) var(--od-sidebar-width));
}
html[data-desktop-chrome] .cw-workspace .cw-canvas-region {
top: var(--desktop-toolbar-height);
left: calc(var(--od-sidebar-width) + var(--chat-left-inset));
}
html[data-desktop-chrome] .cw-workspace .react-flow {
background: #0d0d0d;
}
html[data-desktop-chrome][data-theme="light"] .cw-workspace .react-flow {
background: #f7f8fa;
background: var(--od-workspace-background);
}
html[data-desktop-chrome] .cw-workspace .cw-topbar {
height: var(--desktop-toolbar-height);
Expand Down Expand Up @@ -214,8 +217,6 @@ html[data-desktop-chrome][data-theme="light"] .od-project-sidebar nav button[ari
html[data-desktop-chrome][data-desktop-fullscreen] .od-caption-actions { left: 12px; }
html[data-desktop-chrome][data-desktop-fullscreen] [data-desktop-sidebar="open"] .od-caption-actions { left: 196px; }
html[data-desktop-chrome][data-desktop-fullscreen] .cw-workspace[data-desktop-sidebar="closed"] .cw-topbar { padding-left: 92px; }
html[data-desktop-chrome] .cw-workspace[data-workspace-mode="agent"] .cw-topbar { padding-left: 16px; }
html[data-desktop-platform="darwin"]:not([data-desktop-fullscreen]) .cw-workspace[data-workspace-mode="agent"] .cw-topbar { padding-left: 92px; }
@media (prefers-reduced-motion: reduce) {
.od-project-sidebar, .od-caption-actions,
html[data-desktop-chrome] .cw-workspace .cw-topbar { transition: none; }
Expand All @@ -231,6 +232,9 @@ html[data-desktop-chrome] .cw-workspace[data-workspace-mode="agent"] .cw-assista
top: var(--desktop-toolbar-height);
left: var(--od-sidebar-width);
}
html[data-desktop-chrome] .cw-chat-button[aria-expanded="true"] {
display: none;
}
html[data-desktop-chrome] .cw-workspace[data-narrow="true"][data-workspace-mode="canvas"] .cw-assistant-panel {
bottom: 62px;
}
Expand Down
7 changes: 3 additions & 4 deletions src/canvas/workspace/WorkspaceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ export function WorkspaceView({ rt, editingState, editSession }: {
}, [doc.id, doc.nodes]);

const desktop = !!window.opendirectorDesktop;
const showDesktopNavigation = desktop && workspaceMode === "canvas";
const [desktopSidebarOpen, setDesktopSidebarOpen] = useState(() => {
try { return desktop && localStorage.getItem("opendirector.desktop.sidebar.v1") === "open"; }
catch { return false; }
Expand Down Expand Up @@ -639,7 +638,7 @@ export function WorkspaceView({ rt, editingState, editSession }: {
ref={root}
data-testid="canvas-workspace"
data-edit-mode={readOnly ? "preview" : "edit"}
data-desktop-sidebar={showDesktopNavigation && desktopSidebarOpen ? "open" : "closed"}
data-desktop-sidebar={desktop && desktopSidebarOpen ? "open" : "closed"}
data-edge-motion={pageVisible && canvasVisible}
data-assistant-open={assistantVisible}
data-chat-dock={workspaceMode === "canvas" && !assistantLayout.mobile ? assistantLayout.side : undefined}
Expand Down Expand Up @@ -825,7 +824,7 @@ export function WorkspaceView({ rt, editingState, editSession }: {
{editSession.error && <span role="alert">{editSession.error}</span>}
</> : <span className="cw-save-status" title={saveStatusText}>
<i className={saveStatus.state === "saved" ? "saved" : ""} />
{showDesktopNavigation && desktopSidebarOpen ? saveStatusText : switchingStatus || saveStatusText}
{desktop && desktopSidebarOpen ? saveStatusText : switchingStatus || saveStatusText}
</span>}
{saveStatus.state === "failed" && (
<div className="cw-save-conflict-actions">
Expand Down Expand Up @@ -938,7 +937,7 @@ export function WorkspaceView({ rt, editingState, editSession }: {
{!editing && modeSwitch}
</div>
</header>
{showDesktopNavigation && <DesktopSidebar open={desktopSidebarOpen} currentId={doc.id}
{desktop && <DesktopSidebar open={desktopSidebarOpen} currentId={doc.id}
switchingStatus={switchingStatus}
disabled={!ready || switching || projectRenaming}
onToggle={() => setDesktopSidebarOpen(value => !value)}
Expand Down
49 changes: 41 additions & 8 deletions tests/browser/workspace_modes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -801,24 +801,45 @@ try {
await page.setViewportSize({ width: 1720, height: 900 });
await page.addInitScript(() => {
window.opendirectorDesktop = { registerSession() {}, setLocale() {}, setExporting() {} };
localStorage.setItem("opendirector.desktop.sidebar.v1", "open");
const markDesktop = () => { document.documentElement.dataset.desktopChrome = ""; };
const markDesktop = () => {
document.documentElement.dataset.desktopChrome = "";
document.documentElement.dataset.desktopPlatform = "darwin";
};
if (document.documentElement) markDesktop();
else window.addEventListener("DOMContentLoaded", markDesktop, { once: true });
});
await page.reload();
await page.locator('.cw-workspace[data-desktop-sidebar="open"][aria-busy="false"]').waitFor();
await page.locator('.cw-workspace[data-desktop-sidebar="closed"][aria-busy="false"]').waitFor();
const sidebarPanel = page.locator(".od-project-sidebar");
const captionActions = page.locator(".od-caption-actions");
const sidebarToggle = captionActions.getByRole("button", { name: "Toggle project sidebar", exact: true });
const projectTitle = page.locator(".cw-topbar .cw-project-title");
await sidebarToggle.click();
const sidebar = await until(() => sidebarPanel.boundingBox(),
box => box && Math.abs(box.x) <= 1, "opening the desktop sidebar places it against the window edge");
const canvasTitle = await projectTitle.boundingBox();
await selectMode("agent");
assert.equal(await page.locator(".od-desktop-navigation").count(), 0);
const fullChat = await assistant.boundingBox();
assert.ok(Math.abs(fullChat.x) <= 1 && Math.abs(fullChat.width - page.viewportSize().width) <= 1);
assert.equal(await sidebarToggle.getAttribute("aria-expanded"), "true");
assert.ok(Math.abs((await projectTitle.boundingBox()).x - canvasTitle.x) <= 1);
const chatWithSidebar = await assistant.boundingBox();
assert.ok(Math.abs(chatWithSidebar.x - (sidebar.x + sidebar.width)) <= 1);
await assertLayout("agent");
await page.reload();
await page.locator('.cw-workspace[data-workspace-mode="agent"][aria-busy="false"]').waitFor();
assert.equal(await page.locator(".od-project-sidebar").count(), 0);
assert.equal(await sidebarToggle.getAttribute("aria-expanded"), "true");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 reload() 会再次执行上面的 addInitScript,把侧栏直接设成 open;即使真实的保存逻辑坏了,这里也会绿。能否让 init script 只装 bridge,用按钮打开侧栏后再 reload?这样能测到真实偏好是否被保存。

await sidebarToggle.click();
await until(async () => {
const actions = await captionActions.boundingBox();
const title = await projectTitle.boundingBox();
return title.x - (actions.x + actions.width);
}, gap => gap >= 8, "the closed desktop sidebar leaves room for the caption actions");
await captionActions.getByRole("button", { name: "New project", exact: true }).waitFor();
await until(() => assistant.boundingBox(),
chat => Math.abs(chat.x) <= 1 && Math.abs(chat.width - page.viewportSize().width) <= 1,
"closing the desktop sidebar expands the conversation");
await sidebarToggle.click();
await selectMode("canvas");
await page.locator('.cw-workspace[data-desktop-sidebar="open"]').waitFor();
const sidebar = await page.locator(".od-project-sidebar").boundingBox();
const dockRightButton = assistant.getByRole("button", { name: "Dock chat to the right", exact: true });
assert.equal(await dockRightButton.innerText(), "");
await dockRightButton.hover();
Expand All @@ -829,6 +850,18 @@ try {
const desktopChat = await assistant.boundingBox();
assert.ok(Math.abs(desktopCanvas.x - (sidebar.x + sidebar.width)) <= 1);
assert.ok(desktopCanvas.x + desktopCanvas.width <= desktopChat.x + 1);
assert.ok(await workspace.evaluate(element => {
const { backgroundColor, backgroundImage } = getComputedStyle(element);
return backgroundColor !== "rgba(0, 0, 0, 0)" || backgroundImage !== "none";
}), "the dock gutter does not expose the macOS window backdrop");
const desktopChatButton = page.locator(".cw-chat-button");
assert.equal(await desktopChatButton.isVisible(), false, "only the panel shows a collapse control");
await assistant.locator(".cw-assistant-collapse").click();
await desktopChatButton.waitFor();
assert.equal(await desktopChatButton.getAttribute("aria-expanded"), "false");
await desktopChatButton.click();
await assistant.waitFor();
assert.equal(await desktopChatButton.isVisible(), false);
assert.deepEqual(errors, []);
console.log("PASS workspace modes: bilingual right default and saved docks, edge previews and release, keyboard, direct nodes and upload, shared draft and uninterrupted running tasks");
} catch (error) {
Expand Down
Loading