mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Plug-ins: a web worker run waits for the tool edit in progress
A plug-in command routed to a Web Worker now applies the edit the active
tool computes on another thread (a Shape Builder merge) before the run is
given the document, as a command run in the app does, so the worker sees
the merged document and its output still applies.
- plugin.dialog's and ui.installPlugin's params text and docs/mcp.md
describe the web build: no live preview, every filter runs in a Web
Worker, and {pending: true} while a worker checks new module bytes.
This commit is contained in:
1 parent
cff9f3dcbe
commit
31401e6262
4 files changed
+53
-8
No files matched your search
@@ -795,12 +795,20 @@ impl Session {
|
||||
self.plugin_calling.is_some()
|
||||
}
|
||||
|
||||
/// Keeps the edit in progress (a drag, a preview, typing) as its own undo step, as a run that
|
||||
/// calls commands does before it starts, so a run made away from the session is given the
|
||||
/// document with it and applies as an undo step of its own → whether that changed the document
|
||||
/// or the selection.
|
||||
/// Applies the edit the active tool computes on another thread (a Shape Builder merge), as a
|
||||
/// command that edits waits for it, and keeps the edit in progress (a drag, a preview, typing)
|
||||
/// as its own undo step, as a run that calls commands does before it starts, so a run made away
|
||||
/// from the session is given the document with them and applies as an undo step of its own →
|
||||
/// whether that changed the document or the selection.
|
||||
pub fn settle_for_plugin_run(&mut self) -> Result<bool> {
|
||||
super::plugin_call::settle(self)
|
||||
let before = self.active().map(|d| (Arc::clone(&d.doc), d.selection.clone()));
|
||||
self.finish_tool_edit_later()?;
|
||||
let finished = match (&before, self.active()) {
|
||||
(Some((doc, selection)), Some(d)) => !Arc::ptr_eq(doc, &d.doc) || *selection != d.selection,
|
||||
(None, None) => false,
|
||||
_ => true,
|
||||
};
|
||||
Ok(super::plugin_call::settle(self)? || finished)
|
||||
}
|
||||
|
||||
/// Is command `id` the one that applies the output of the run that holds the documents?
|
||||
|
||||
@@ -1994,13 +1994,13 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"plugin.dialog",
|
||||
"Plug-in…",
|
||||
"",
|
||||
"{id: an object filter plug-in (plugin.list), params?: {…}} Object › Plug-ins: run the filter at once when it takes no parameters or params are given (plugin.run), else open its dialog (dialog `plugin`: a field per parameter, `__plugin` the id, live preview; OK runs plugin.run as one undo step). A heavy filter, and a filter that lists `progress` and no commandAllowlist, run in the background when they run at once or OK runs them without a kept preview → {background: true, status} (see plugin.cancelRuns)",
|
||||
"{id: an object filter plug-in (plugin.list), params?: {…}} Object › Plug-ins: run the filter at once when it takes no parameters or params are given (plugin.run), else open its dialog (dialog `plugin`: a field per parameter, `__plugin` the id, live preview; OK runs plugin.run as one undo step). A heavy filter, and a filter that lists `progress` and no commandAllowlist, run in the background when they run at once or OK runs them without a kept preview → {background: true, status} (see plugin.cancelRuns). On the web the dialog has no live preview, and every filter it runs, at once or on OK, runs in a Web Worker → {background: true, status}",
|
||||
),
|
||||
(
|
||||
"ui.installPlugin",
|
||||
"Install Plug-in…",
|
||||
"",
|
||||
"{path?: a .wasm file | dataBase64?: the module, name?: the file name shown as its source (with dataBase64), replace?: bool (true: the user agreed it takes the place of the plug-in with its id, as plugin.install), hash?: the module's SHA-256 (as plugin.install)} install a WebAssembly plug-in (plugin.install); without a path pick one (the web opens the browser's file picker; File › Open of a .wasm installs it too). A plug-in that lists permissions the user hasn't granted it asks the user first, showing its name, id, version, file SHA-256 and what each permission lets it do, so does a filter that asks for a heavy budget, and so does one without replace that would take the place of another module with its id and get its settings and cache (needsReplace in plugin.inspect), showing its id and file SHA-256: OK installs it if the file still has the SHA-256 shown, Cancel installs nothing. Only a person can press OK: ui.dialog.confirm, answer_dialog and synthetic input are refused. When automation asked (a control or MCP request, synthetic input, or a file dialog one of them opened, even when the person picked the file), replace: true doesn't skip the question about replacing, and nothing in the dialog installs it, the person's OK included: the person chooses Object › Plug-ins › Install Plug-in… to install it → plugin.install's result | {pending: \"pluginInstall\"} while it asks | {pending: \"pluginInstall\", approval: \"personMustStartInstall\"} while it asks what automation asked | null on the web without path or dataBase64, once the browser's file picker opens (the picked file is handled as above)",
|
||||
"{path?: a .wasm file | dataBase64?: the module, name?: the file name shown as its source (with dataBase64), replace?: bool (true: the user agreed it takes the place of the plug-in with its id, as plugin.install), hash?: the module's SHA-256 (as plugin.install)} install a WebAssembly plug-in (plugin.install); without a path pick one (the web opens the browser's file picker; File › Open of a .wasm installs it too). A plug-in that lists permissions the user hasn't granted it asks the user first, showing its name, id, version, file SHA-256 and what each permission lets it do, so does a filter that asks for a heavy budget, and so does one without replace that would take the place of another module with its id and get its settings and cache (needsReplace in plugin.inspect), showing its id and file SHA-256: OK installs it if the file still has the SHA-256 shown, Cancel installs nothing. Only a person can press OK: ui.dialog.confirm, answer_dialog and synthetic input are refused. When automation asked (a control or MCP request, synthetic input, or a file dialog one of them opened, even when the person picked the file), replace: true doesn't skip the question about replacing, and nothing in the dialog installs it, the person's OK included: the person chooses Object › Plug-ins › Install Plug-in… to install it → plugin.install's result | {pending: \"pluginInstall\"} while it asks | {pending: \"pluginInstall\", approval: \"personMustStartInstall\"} while it asks what automation asked | null on the web without path or dataBase64, once the browser's file picker opens (the picked file is handled as above) | {pending: true} on the web while a Web Worker checks module bytes no worker has checked yet, after which the install goes on as above in the app",
|
||||
),
|
||||
(
|
||||
"plugin.cancelRuns",
|
||||
|
||||
@@ -895,6 +895,41 @@ fn on_the_web_a_failed_check_ends_while_a_run_holds_the_documents() {
|
||||
app.run("plugin.cancelRuns", json!({})).unwrap();
|
||||
}
|
||||
|
||||
/// An edit the active tool computes on another thread (a Shape Builder merge) is applied before a
|
||||
/// worker run is given the document, so the run sees it and its output still applies.
|
||||
#[test]
|
||||
fn on_the_web_a_worker_run_starts_after_the_tool_edit_in_progress() {
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
let (mut app, fake) = web_app();
|
||||
let id = "test.ui.web.tooledit";
|
||||
let manifest = format!(
|
||||
r#"{{"id":"{id}","name":"Test {id}","kind":"filter","api":2,"permissions":["doc.read","doc.write"],"commands":[{{"id":"same","label":"Same"}}]}}"#
|
||||
);
|
||||
let data = vectorcraft_format::base64_encode(&wat::parse_str(tpl::returning(&manifest, TRIANGLE)).unwrap());
|
||||
app.run("plugin.install", json!({"dataBase64": data, "grant": ["doc.read", "doc.write"]})).unwrap();
|
||||
// 40 overlapping squares, which the Shape Builder merges on another thread.
|
||||
let ids: Vec<_> = (0..40)
|
||||
.map(|k| app.run("shape.rectangle", json!({"x": f64::from(k) * 10.0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].clone())
|
||||
.collect();
|
||||
app.run("select.set", json!({ "ids": ids })).unwrap();
|
||||
let v = app.view_info();
|
||||
app.session.select_tool("shapeBuilder", v).unwrap();
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Move, 15.0, 10.0), v).unwrap();
|
||||
app.session.tool_poll(v, true).unwrap();
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
app.session.pointer(&PointerEvent::new(kind, 15.0, 10.0), v).unwrap();
|
||||
}
|
||||
assert!(app.session.tool_editing(), "the merge is being computed");
|
||||
assert_eq!(app.run(&format!("plugin.{id}.same"), json!({})).unwrap()["background"], true);
|
||||
assert!(!app.session.tool_editing(), "the merge applied before the run was given the document");
|
||||
fake.ready(0);
|
||||
plugin_runs::poll(&mut app);
|
||||
fake.serve(0);
|
||||
plugin_runs::poll(&mut app);
|
||||
assert!(app.plugin_runs.running.is_empty());
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.last().unwrap().label, "Same", "{}", app.ui.status);
|
||||
}
|
||||
|
||||
/// The progress window shows the run that holds the documents at once, with Cancel only, also when
|
||||
/// a run that started before it is running.
|
||||
#[test]
|
||||
|
||||
+3
-1
@@ -13341,7 +13341,9 @@ A plug-in of API level 2 (`api: 2` in its entry) that lists `progress` may repor
|
||||
log lines: `notifications/cancelled` makes its `vc_cancelled` return 1, and its log lines go to the server's log
|
||||
under its id. With a desktop app connected, `plugin.dialog` runs such a filter (one without a `commandAllowlist`) in the
|
||||
background when it runs at once or OK runs it with Preview off, and returns `{background: true, status}`;
|
||||
`plugin.cancelRuns` stops it. One that lists `settings` or `cache` keeps settings or a cache of its own in the `Plug-ins` folder
|
||||
`plugin.cancelRuns` stops it. In the web build, `plugin.dialog` has no Preview and runs every filter in a Web Worker,
|
||||
returning `{background: true, status}`, and `ui.installPlugin` returns `{pending: true}` while a worker checks module
|
||||
bytes that no worker has checked yet ([plug-ins](plugins.md#the-web-build)). One that lists `settings` or `cache` keeps settings or a cache of its own in the `Plug-ins` folder
|
||||
(VectorCraft's own caps: 256 settings and 1 MiB, 512 MiB of cache): `plugin.list` and `plugin.info` give the cache's
|
||||
size as `cacheBytes`, `plugin.clearCache {id?}` empties the cache of one plug-in or of all of them and returns
|
||||
`{cleared: [id], bytesFreed}`, replacing a plug-in keeps both, and `plugin.remove` deletes both (also for an id that
|
||||
|
||||
Reference in new issue
Block a user