M9: web: a workspace page publishes every new file to its server (#2119, part) (#2958)

A browser page that names its figcraft-server and says <meta name="figcraft-workspace" content="on"> opens on Home > Online and publishes every file made or opened there to that server once, through collab.publish, so with the server's team_publish each new design is on the team list at once and every edit is kept there. A file already on a server is never republished as a copy; a refused publish leaves the file local with the server's reason. Docs: packaging/web/README.md, docs/server.md, docs/collaboration-parity.md.
This commit is contained in:
BFlat
2026-12-03 07:19:53 +07:00
committed by GitHub
parent 89eea4d09d
commit c4a627fb2e
6 changed files with 117 additions and 4 deletions
+6
View File
@@ -31,6 +31,10 @@
//! and stores what FigCraft saves. `&author=` names the user for comments and board notes in either
//! host mode, and `&save=managed` makes document saves wait for the host's `saved`.
//!
//! Workspace mode: a page that names its server and says `<meta name="figcraft-workspace"
//! content="on">` starts on Home ▸ Online and publishes every file it makes or opens to that server
//! once (`workspace`), so with the server's `team_publish` the team's files are all on the list.
//!
//! URL fragment: `#join=<invite link or join code>` joins that live session once the page has
//! loaded, so a bookmark opens a shared file. `join` takes the rest of the fragment: put it last.
//! The link carries the session's secret; a fragment is never sent to the web host, but the address
@@ -72,6 +76,8 @@ mod recovery_tests;
mod saved_files;
#[cfg(target_arch = "wasm32")]
mod web;
#[cfg(any(target_arch = "wasm32", test))]
mod workspace;
#[cfg(target_arch = "wasm32")]
fn main() {
+25 -3
View File
@@ -44,6 +44,12 @@ pub fn start() {
// `figcraft:publish` goes to.
let page_server = page_meta("figcraft-server").as_deref().and_then(crate::query::page_server);
let bridge = crate::host::Bridge::connect(&canvas, confirms_saves, page_server.clone());
// Workspace mode (`crate::workspace`): every file the page makes or opens is kept on its
// server. Not in host mode, where the host keeps the files.
let workspace = page_server
.clone()
.filter(|_| bridge.is_none() && page_meta("figcraft-workspace").is_some_and(|c| c.trim().eq_ignore_ascii_case("on")))
.map(crate::workspace::Workspace::new);
let app_bridge = bridge.clone();
let mut options = eframe::WebOptions::default();
// `?webgl`: force the WebGL2 backend (troubleshooting, and headless browsers whose WebGPU
@@ -69,10 +75,14 @@ pub fn start() {
// mode, where the host sends the files).
let present =
crate::query::present_entry(&hash).filter(|_| app_bridge.is_none()).map(|(file, start)| (decoded(file), start.map(decoded)));
// A page that only presents keeps its file off the workspace.
let workspace = workspace.filter(|_| present.is_none());
// Host mode: the host sends the file to edit, so start with no document (the
// home screen), as the desktop app does without a file; so does a page that
// only presents. Otherwise the session starts with one new document.
let mut session = if app_bridge.is_some() || present.is_some() { Session::empty() } else { Session::new() };
// only presents, and a workspace, whose files are on its server. Otherwise the
// session starts with one new document.
let empty = app_bridge.is_some() || present.is_some() || workspace.is_some();
let mut session = if empty { Session::empty() } else { Session::new() };
// The host names its own server: the default for sharing, codes and the team list.
if let Some(server) = page_server {
session.prefs.publish_server = server;
@@ -86,6 +96,10 @@ pub fn start() {
session.live.install(Box::new(figcraft_collab_net::NetLink::new(std::sync::Arc::new(move || ctx.request_repaint()))));
let mut fig = FigApp::new(session, Box::new(WebServices { reduce_motion, ctx: cc.egui_ctx.clone(), host: app_bridge.clone() }));
fig.note_recovered(recovered);
// A workspace opens on its files: Home ▸ Online lists the team's.
if workspace.is_some() {
fig.ui.home_view.section = figcraft_ui_egui::home::Section::Online;
}
if let Err(e) = crate::pasted::install(cc.egui_ctx.clone()) {
log::error!("couldn't listen for pasted images: {e:?}");
}
@@ -115,7 +129,7 @@ pub fn start() {
if let Some(bridge) = &app_bridge {
bridge.listen(cc.egui_ctx.clone());
}
Ok(Box::new(WebShell { fig, host: app_bridge }))
Ok(Box::new(WebShell { fig, host: app_bridge, workspace }))
}),
)
.await;
@@ -241,6 +255,8 @@ struct WebShell {
fig: FigApp,
/// The host bridge, when the page hosts the app (`?host=parent` or `data-host="page"`).
host: Option<crate::host::Bridge>,
/// Workspace mode: new files go to the page's server (`crate::workspace`).
workspace: Option<crate::workspace::Workspace>,
}
impl eframe::App for WebShell {
@@ -259,6 +275,12 @@ impl eframe::App for WebShell {
bridge.frame(&mut self.fig, ctx, now_ms());
}
figcraft_ui_egui::windows::guard(&mut self.fig, ctx, |fig| fig.background_tick(ctx));
if let Some(workspace) = &mut self.workspace {
let front = self.fig.session.ds().ok().map(|d| d.uid);
if let Some(params) = workspace.step(front, self.fig.session.live.iter()) {
self.fig.run("collab.publish", params);
}
}
// The host hears when unsaved changes appear or go away (crate::host).
if let Some(bridge) = &self.host {
bridge.set_dirty(self.fig.session.docs.iter().any(|d| d.is_dirty()));
+71
View File
@@ -0,0 +1,71 @@
//! Workspace mode: a page served beside its own `figcraft-server` that says
//! `<meta name="figcraft-workspace" content="on">` keeps every file on that server. Each document
//! that comes to the front without being on a server already (a new design, a file opened from the
//! computer, one kept from a stopped page) is published there once, as File ▸ Publish to server…
//! does, so it joins the team list and every edit is kept as it happens. Testable without a
//! browser (like [`crate::host_publish`]).
use std::collections::BTreeSet;
use figcraft_engine::live::Live;
use serde_json::{Value, json};
/// The page's server and the documents already decided on.
pub struct Workspace {
server: String,
/// Every document seen in front: each is published at most once, so a failed or refused
/// publish isn't retried and a file you leave isn't put back.
seen: BTreeSet<u64>,
}
impl Workspace {
pub fn new(server: String) -> Self {
Workspace { server, seen: BTreeSet::new() }
}
/// After a frame: the `collab.publish` parameters for the document in front (`front`, its
/// `DocState::uid`), when it is new to the workspace and no session syncs it (`sessions`).
pub fn step<'a>(&mut self, front: Option<u64>, sessions: impl IntoIterator<Item = &'a Live>) -> Option<Value> {
let uid = front?;
if !self.seen.insert(uid) {
return None;
}
let on_server = sessions.into_iter().any(|l| l.doc_uid == Some(uid));
(!on_server).then(|| json!({ "server": self.server }))
}
}
#[cfg(test)]
mod tests {
use figcraft_engine::live::Live;
use serde_json::json;
use super::Workspace;
const SERVER: &str = "wss://team.example/";
fn syncing(doc: u64) -> Live {
let mut l = Live::default();
l.doc_uid = Some(doc);
l
}
#[test]
fn a_new_document_is_published_once() {
let mut w = Workspace::new(SERVER.into());
assert_eq!(w.step(Some(1), &[]), Some(json!({"server": SERVER})));
assert_eq!(w.step(Some(1), &[]), None, "the publish is under way, or failed: not again");
assert_eq!(w.step(None, &[]), None, "the home screen");
assert!(w.step(Some(2), &[]).is_some(), "the next new design");
assert_eq!(w.step(Some(1), &[]), None, "back to the first");
}
#[test]
fn a_file_on_a_server_already_is_left_alone() {
let mut w = Workspace::new(SERVER.into());
let joined = syncing(3);
assert_eq!(w.step(Some(3), [&joined]), None, "opened from the team list");
assert_eq!(w.step(Some(3), &[]), None, "and after leaving its session it isn't published as a copy");
assert!(w.step(Some(4), [&joined]).is_some(), "another session's file doesn't count");
}
}
+1
View File
@@ -27,6 +27,7 @@ cursors, selections, text carets, cursor chat and spotlights shown live ([`colla
| Date | Change | Summary |
|---|---|---|
| 2026-12-03 | minor | M9, #2119: workspace mode for the browser build. A page that names its server and says `<meta name="figcraft-workspace" content="on">` opens on Home ▸ Online, and every file made or opened there is published to that server once, without the Publish dialog; with the server's `team_publish` it is on the team list at once and every edit is kept there. A file already on a server is never published again as a copy, and a refused publish leaves the file local with the server's reason. Tests: `figcraft-web::workspace`. Numbers unchanged |
| 2026-12-03 | minor | M9, #2945: a session you joined or published shows where your changes stand on their way to the server, and says saved only once the server confirmed them: Preparing, Uploading (bytes sent of the total and a percentage, in the desktop app and the MCP server), Waiting for the server to confirm, All changes saved to the server (with when), changes not yet saved while reconnecting, and the last time the server had everything after a failure. The Share popover shows it with a progress bar; a tab whose changes have been on their way for a second shows a thin bar and the line on hover. `collab.peers` reports `upload` and `confirmedAt`. The browser can't measure its socket's bytes and shows waiting. Numbers unchanged |
| 2026-12-02 | minor | M9, part of #2119: `team_publish = true` (beside `team_files = "edit"`, refused with `open_publish`) makes `figcraft-server` a workspace for the team: everyone who reaches it publishes from the app or the browser with the plain address, no key, and the file is on the team list (Home ▸ Online) for everyone at once until it is removed. Such files never expire, and their publisher manages them with an owner token from Home ▸ Online (rename, remove, share with a code); the server reports `open` with no idle time, so apps of any version publish there with no protocol change. Tests: `figcraft-server::team_publish_tests`. Numbers unchanged |
| 2026-12-01 | minor | M9, #2786: a page hosting the browser build (`?host=parent` or `data-host="page"`) asks for the open file to be put on the server it names in `<meta name="figcraft-server">`: `figcraft:publish {name?}` opens File ▸ Publish to server… for the file in front, addressed to that server, and the user presses Publish as in the app (`collab.publish`); the page hears `figcraft:published {file, name, edit, view}`, or `{error}` when it names no server, no file is open, a request still waits, the user closed the dialog (`"cancelled"`), the publish failed or went to another server. A server in the message is never used. A publish sent while the file the page just sent is still opening waits for it. Tests: `figcraft-web` `host_publish_tests`, `ui-egui` `live_publish_to_tests`; run in a browser through an iframe host page against a local open `figcraft-server` (open then publish, Publish, Cancel, a second request while one waits, no file open). Numbers unchanged |
+4 -1
View File
@@ -215,7 +215,10 @@ keep: **File ▸ Publish to server…** with the server's plain address (`wss://
no `?key=`) puts the open file there, and from any computer or browser that reaches the server,
**Home ▸ Online** lists it under **Shared by your team on …**; a click opens it, and every edit is
kept on the server as it is made. In a browser build whose page names the server
(`<meta name="figcraft-server">`), the Publish dialog already has its address.
(`<meta name="figcraft-server">`), the Publish dialog already has its address, and with
`<meta name="figcraft-workspace" content="on">` beside it there is no Publish step at all: the
page opens on **Home ▸ Online**, and every file made or opened there goes to the server by itself
(see [packaging/web/README.md](../packaging/web/README.md#live-sessions)).
- **Who may publish.** Reaching the server is all it takes, so turn it on only for a server just
your team reaches (a private network, an allowlist or a sign-in in front of it). It is refused
+10
View File
@@ -52,6 +52,16 @@ A site served beside its own `figcraft-server` can name it in `index.html`:
address without a query). The page then uses it as the server for online sharing, join codes and
the server's team list (Home ▸ Online), without anyone setting it in Preferences.
Add `<meta name="figcraft-workspace" content="on">` beside it to make the page a workspace on that
server: it opens on Home ▸ Online instead of a blank file, and every file made or opened in it
(a new design, a file from the computer, one kept from a stopped page) is published to the server
once, by itself, as File ▸ Publish to server… does. Pair it with the server's `team_publish = true`
([A workspace for the team](../../docs/server.md#a-workspace-for-the-team)): each new design is
then on the team list for everyone at once and every edit is kept there, with no link to keep.
A file opened from the server is never published again as a copy. If the server refuses (it has no
`team_publish`), the file stays in the page unsaved and the notifications say why. Host mode and
`#present=` pages ignore it.
## Sizes
Measured on the 0.1.0 build (`trunk build --release`; gzip `-9`, Brotli quality 11):