ElyMark: the print page is staged off the window thread (M-14)
paper::stage takes the background executor and inlines images, reads the style sheet and writes the page there. A gpui test checks nothing is written before the executor runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ca5ac5bb45
commit
6247771f24
5 files changed
+62
-15
No files matched your search
+10
-14
@@ -15,7 +15,7 @@ use ely_ui::{commands, i18n::text};
|
||||
use ely_web_content::{Event, WebView};
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement as _, ParentElement as _,
|
||||
Subscription, Window,
|
||||
Subscription, Task, Window,
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -62,7 +62,7 @@ pub struct Lost {
|
||||
}
|
||||
|
||||
impl Lost {
|
||||
fn of(images: Vec<String>, rendered: &Value) -> Lost {
|
||||
pub fn of(images: Vec<String>, rendered: &Value) -> Lost {
|
||||
let diagrams = rendered["failed"].as_array().into_iter().flatten();
|
||||
let formulas = rendered["formulas"].as_array().into_iter().flatten();
|
||||
Lost {
|
||||
@@ -280,19 +280,15 @@ impl Desk {
|
||||
"html",
|
||||
move |rendered, cx: &mut App| {
|
||||
let staged = work.join(format!("print-{n}.html"));
|
||||
let writing = staged.clone();
|
||||
let page = match rendered {
|
||||
Ok(rendered) => {
|
||||
let print = paper::Print { folder, style, name, page: staged.clone() };
|
||||
paper::stage(cx.background_executor(), rendered, print)
|
||||
}
|
||||
Err(why) => Task::ready(Err(io::Error::other(why))),
|
||||
};
|
||||
cx.spawn(async move |cx| {
|
||||
// Images inline and the page writes off the window thread.
|
||||
let page = cx
|
||||
.background_spawn(async move {
|
||||
rendered.map_err(io::Error::other).and_then(|rendered| {
|
||||
let (html, images) = paper::Marked::read(&rendered)?.inline(&folder);
|
||||
let style = format!("<style>{}</style>", std::fs::read_to_string(&style)?);
|
||||
std::fs::write(&writing, paper::page(&name, &style, &html))?;
|
||||
Ok(Lost::of(images, &rendered))
|
||||
})
|
||||
})
|
||||
.await;
|
||||
let page = page.await;
|
||||
in_window(&desk, cx, |desk, window, cx| match page {
|
||||
Ok(lost) => {
|
||||
let job = Job {
|
||||
|
||||
Reference in new issue
Block a user