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
51 changes: 42 additions & 9 deletions docs/architecture/web-pandar-print-host.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Web print host: send a sliced plate to Pandar
# Web print host: Pandar Cloud sign-in, Devices tab and sending a sliced plate

## Source boundary

Expand All @@ -22,8 +22,13 @@ Plate sliced file (`libslic3r`, the rewrite boundary):

Print host UI (GUI, ported only as browser behaviour):

- `PhysicalPrinterDialog` (`src/slic3r/GUI/PhysicalPrinterDialog.cpp`) stores a host type, the
host address (`print_host`) and the API key (`printhost_apikey`).
- `GUI_App::request_login` and `ShowUserLogin` (`src/slic3r/GUI/GUI_App.cpp:5135`, `:5363`) open the
cloud sign-in WebView. `GUI_App::request_user_logout` (`:5448`) forgets the account and its
devices (`DeviceManager::clean_user_info`).
- `MainFrame` adds the Device tab (`m_monitor_page`, `MonitorPanel`, `_L("Device")`,
`tab_monitor_active`; `src/slic3r/GUI/MainFrame.cpp:1606-1608`). `MainFrame::show_device`
(`:1661-1745`) inserts it after Preview and takes it away again. `StatusPanel` shows each
printer's temperatures and print progress.
- `PrintHostSendDialog` (`src/slic3r/GUI/PrintHostDialogs.cpp`) confirms the upload name and the
post-upload action (upload, or upload and print).

Expand All @@ -38,10 +43,25 @@ Print host UI (GUI, ported only as browser behaviour):
plate 1 of a saved single-plate 3MF (the bytes `saveProjectWithProfiles` returns) with archive capture
and returns the `min_save` `.gcode.3mf`. Slicing and packaging stay in Rust.
- Web app:
- "Physical printer" settings (host type `Pandar`, Hub URL, tenant ID, tenant API token), kept in
browser `localStorage` like the rest of the app config.
- "Print plate" side button: opens the physical printer settings when none are set, then the send
dialog. The dialog lists the tenant's printers (`GET /api/v1/tenants/{tenant}/printers`) and
- A "Cloud" menu next to "File" signs in to a Pandar Hub. The sign-in dialog asks only for the Hub
URL and remembers the last one. A popup opens `{hub}/web-sign-in` with `redirect_url` (the
app's `cloud-callback.html`), a PKCE S256 `code_challenge` and a random `state`. The Hub sends
the popup back to `cloud-callback.html` with a one-use ticket. That page posts
`{ ticket, state }` on the `ares.cloud` BroadcastChannel: the app's
`Cross-Origin-Opener-Policy: same-origin` severs `window.opener` across the Hub hop. The app
exchanges the ticket and its verifier at `POST /api/v1/web/login-tickets/exchange` for a
30-day `web:session` tenant token and its profile.
- The session (token, expiry, tenant, user name) and the Hub URL are kept in the `cloud` field of
the `ares.config` `localStorage` record. An expired session is not restored. "Sign out" and any
401 from the tenant API drop the session and keep the Hub URL. The manual `printHost` field of
earlier builds is dropped on load, not migrated.
- A "Devices" tab (`#/devices`) follows Preview while signed in. It lists the tenant's printers
(`GET /api/v1/tenants/{tenant}/printers`) with their status, nozzle, bed and chamber
temperatures and the running print's name, layer, time left and progress. It then opens the
printer-event socket (`POST /api/v1/tenants/{tenant}/printer-events/tickets`, then
`GET /api/v1/tenants/{tenant}/printer-events?ticket=`), and each `printer_snapshot` replaces
its printer. A closed socket reconnects after 5 s. The socket is open only while the tab is shown.
- "Print plate" side button: opens the Cloud sign-in when signed out, then the send dialog. The dialog lists the tenant's printers (`GET /api/v1/tenants/{tenant}/printers`) and
uploads. A Bambu printer offers the Hub's calibration modes (0 off, 1 on, 2 auto) with the paired
booleans set to `mode != 0`, plus AMS and timelapse.
- The upload goes to the Pandar Hub client API:
Expand All @@ -51,7 +71,8 @@ Print host UI (GUI, ported only as browser behaviour):
- A Moonraker printer in Pandar accepts only `.gcode` (Hub `artifact_requires_gcode`), so it
gets the plate's plain G-code. A Bambu printer gets the `.gcode.3mf`.
- The Hub must allow the web origin through its `PANDAR_CORS_ALLOWED_ORIGINS` allowlist
(ProjectPandar/pandar#17). The browser sends no cookies.
(ProjectPandar/pandar#17). The same allowlist bounds the sign-in `redirect_url` origin. The
browser sends no cookies.

## Included / deferred

Expand All @@ -67,6 +88,8 @@ Deferred, rejected with a message rather than approximated:
thumbnail renderer port yet.
- AMS slot mapping (`ams_mapping`); the job is sent without a mapping and `use_ams` as chosen.
- Other host types (OctoPrint, Moonraker direct, …).
- Device control from the Devices tab (pause, stop, light, AMS), print history and the camera view.
The tab is read-only.
- "Export plate sliced file" in the File menu. It can reuse the same export, but it is a separate
menu slice.

Expand All @@ -90,10 +113,20 @@ reuse the preview slice. Two consequences follow, both upstream CLI behaviour:
- Web E2E (`web/e2e/pandarSend.spec.ts`): the P1S project `tests/parity/auto-lift-query-frame/project.3mf`
is opened with the P1S installed and sliced. A fake cross-origin Hub answers the CORS preflight,
checks the bearer token and records each job. The spec asserts the following:
- the physical printer config is stored;
- the Cloud sign-in through the popup is stored;
- each job's path and fields;
- the Bambu `.gcode.3mf` has exactly the 11 `--min-save` members;
- its G-code equals the preview G-code apart from the three CLI-kept config lines;
- the Moonraker `.gcode` equals the preview G-code.

`target/web-e2e/pandar-send/` keeps both uploads and `requests.json` as the repeatable artifact.
- Web E2E (`web/e2e/pandarCloud.spec.ts`): the fake Hub (`web/e2e/pandarHub.ts`) redirects the
sign-in popup with a ticket and accepts the exchange only for the verifier whose SHA-256 is the
issued challenge. The spec asserts the following:
- `#/devices` falls back to Prepare and no Devices tab shows while signed out;
- the stored session after sign-in;
- the printer cards, then a `printer_snapshot` updating temperatures and print progress;
- the session outlives a reload;
- sign-out leaves Devices, drops the session and keeps the Hub URL for the next sign-in.

`target/web-e2e/pandar-cloud/` keeps the two Devices screenshots and `session.json`.
16 changes: 16 additions & 0 deletions web/app/public/cloud-callback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Ares Cloud sign-in</title>
</head>
<body>
<p>Signed in. You can close this window.</p>
<script>
// The Pandar Hub's web sign-in redirect: hand the one-use ticket to the Ares window (src/state/cloud.ts).
const query = new URLSearchParams(location.search);
new BroadcastChannel("ares.cloud").postMessage({ ticket: query.get("ticket"), state: query.get("state") });
close();
</script>
</body>
</html>
1 change: 1 addition & 0 deletions web/app/src/assets/orca/tab_monitor_active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions web/app/src/devices/DevicesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { HubPrinter } from "../state/cloud";
import { useDevices } from "../state/devices";

const temperature = (current?: string | null, target?: string | null) =>
current == null ? "—" : target && Number(target) > 0 ? `${current} / ${target} °C` : `${current} °C`;

const remaining = (minutes: number) =>
minutes >= 60 ? `${Math.floor(minutes / 60)} h ${minutes % 60} min` : `${minutes} min`;

/** StatusPanel's temperatures and print progress (StatusPanel.cpp) for one Hub printer. */
function DeviceCard({ printer }: { printer: HubPrinter }) {
const { print } = printer;
const active = print?.gcode_state && !["IDLE", "FINISH", "FAILED"].includes(print.gcode_state);
const rows: [string, string][] = [
...(printer.nozzle_temperatures ?? []).map(
({ label, current_celsius, target_celsius }, index): [string, string] => [
label ?? `Nozzle ${index + 1}`,
temperature(current_celsius, target_celsius),
],
),
["Bed", temperature(printer.bed_temperature_celsius, printer.bed_target_temperature_celsius)],
];
if (printer.chamber_temperature_celsius != null)
rows.push([
"Chamber",
temperature(printer.chamber_temperature_celsius, printer.chamber_target_temperature_celsius),
]);
return (
<article className="device-card" aria-label={printer.name}>
<header className="device-card-header">
<h3>{printer.name}</h3>
<span className="device-status" data-status={printer.status}>
{printer.status}
</span>
</header>
{printer.model && <p className="device-model">{printer.model}</p>}
<dl className="device-values">
{rows.map(([name, value]) => (
<div key={name}>
<dt>{name}</dt>
<dd>{value}</dd>
</div>
))}
</dl>
{active && (
<div className="device-print">
<p>
{print.subtask_name ?? print.gcode_state}
{print.current_layer != null && print.total_layers != null && (
<span>
{" "}
· Layer {print.current_layer}/{print.total_layers}
</span>
)}
{print.remaining_time_minutes != null && <span> · {remaining(print.remaining_time_minutes)} left</span>}
</p>
<progress max={100} value={print.progress_percent ?? 0} aria-label={`${printer.name} progress`} />
</div>
)}
</article>
);
}

/** MainFrame's Device tab (MonitorPanel, MainFrame.cpp:1606-1608): the signed-in tenant's printers. */
export function DevicesPage() {
const { printers, error } = useDevices();
return (
<section className="devices-page" aria-label="Devices">
{error && (
<p className="preset-error" role="alert">
{error}
</p>
)}
{printers?.length === 0 && <p className="devices-empty">No printers in this Pandar tenant.</p>}
{!printers && !error && <p className="devices-empty">Loading printers…</p>}
<div className="devices-grid">
{printers?.map((printer) => (
<DeviceCard key={printer.id} printer={printer} />
))}
</div>
</section>
);
}
12 changes: 11 additions & 1 deletion web/app/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createHashHistory, createRootRoute, createRoute, createRouter, redirect } from "@tanstack/react-router";
import { Shell } from "./shell/Shell";
import { useApp } from "./state/store";

const rootRoute = createRootRoute({ component: Shell });

Expand All @@ -21,8 +22,17 @@ const previewRoute = createRoute({
path: "/preview",
});

/** MainFrame's Device tab, only while signed in to Pandar Cloud. */
const devicesRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/devices",
beforeLoad: () => {
if (!useApp.getState().cloud) throw redirect({ to: "/prepare" });
},
});

export const router = createRouter({
routeTree: rootRoute.addChildren([indexRoute, prepareRoute, previewRoute]),
routeTree: rootRoute.addChildren([indexRoute, prepareRoute, previewRoute, devicesRoute]),
history: createHashHistory(),
});

Expand Down
56 changes: 56 additions & 0 deletions web/app/src/shell/CloudMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useEffect, useRef, useState } from "react";
import { signOut } from "../state/cloud";
import { useApp } from "../state/store";

/**
* The top bar's Pandar account menu: sign in (GUI_App::request_login, GUI_App.cpp:5363) or, once
* signed in, the account and sign out (GUI_App::request_user_logout, :5448). Closes on a pick,
* Escape or a click elsewhere.
*/
export function CloudMenu({ onSignIn }: { onSignIn: () => void }) {
const cloud = useApp((state) => state.cloud);
const [open, setOpen] = useState(false);
const root = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!open) return;
const close = (event: Event) => {
if (event instanceof KeyboardEvent ? event.key === "Escape" : !root.current?.contains(event.target as Node))
setOpen(false);
};
document.addEventListener("pointerdown", close);
document.addEventListener("keydown", close);
return () => {
document.removeEventListener("pointerdown", close);
document.removeEventListener("keydown", close);
};
}, [open]);
const pick = (action: () => void) => () => {
setOpen(false);
action();
};
return (
<div ref={root} className="cloud-menu">
<button className="bar-button" aria-haspopup="menu" aria-expanded={open} onClick={() => setOpen(!open)}>
Cloud
</button>
{open && (
<div className="context-menu" role="menu" aria-label="Cloud">
{cloud ? (
<>
<span className="context-menu-label">
{cloud.userName} · {cloud.tenantName}
</span>
<button type="button" role="menuitem" onClick={pick(signOut)}>
Sign out
</button>
</>
) : (
<button type="button" role="menuitem" onClick={pick(onSignIn)}>
Sign in…
</button>
)}
</div>
)}
</div>
);
}
Loading
Loading