feat: render interactive manuscript from Endor through generic graphics

This commit is contained in:
2026-11-12 10:52:28 +08:00
parent d29a1be329
commit 2715c1ce2c
71 changed files with 3000 additions and 78 deletions
+77 -4
View File
@@ -13,7 +13,7 @@ use std::{
ops::{Deref, DerefMut},
panic::{AssertUnwindSafe, catch_unwind},
sync::{
Arc, RwLock,
Arc, OnceLock, RwLock,
mpsc::{Receiver, SyncSender, TrySendError, sync_channel},
},
sync::{
@@ -51,8 +51,40 @@ pub struct RuntimeControl {
sender: SyncSender<()>,
requested: Arc<AtomicBool>,
completion: ShutdownCompletion,
native_sender: Arc<OnceLock<SyncSender<BuildRequest>>>,
namespace: Arc<RwLock<NamespaceState>>,
}
impl RuntimeControl {
/// Only the native input relay calls this blocking acknowledgement path.
/// Window threads still use a bounded, nonblocking Input sender.
pub(crate) fn dispatch_native(&self, input: crate::events::Input) -> Result<()> {
anyhow::ensure!(!self.is_exiting(), "application is exiting");
let (done, completed) = sync_channel(1);
let job = {
let state = self
.namespace
.read()
.map_err(|_| anyhow::anyhow!("namespace lock is poisoned"))?;
BuildRequest {
request: RequestReply::Native(done),
kind: RequestKind::Event,
source: String::new(),
namespace: state.name.clone(),
submission: state.submission,
native: Some(input),
}
};
self.native_sender
.get()
.ok_or_else(|| anyhow::anyhow!("native input queue is unavailable"))?
.send(job)
.map_err(|_| anyhow::anyhow!("native input worker stopped"))?;
completed
.recv()
.map_err(|_| anyhow::anyhow!("native input acknowledgement stopped"))?
.map_err(anyhow::Error::msg)
}
/// 只发出一次退出请求,唤醒 worker 执行清理,并通过完成句柄通知原生循环。
pub fn request_shutdown(&self) -> bool {
if self.requested.swap(true, Ordering::AcqRel) {
@@ -98,7 +130,8 @@ enum RequestKind {
/// 保留原 HTTP 请求与提交身份的执行工作,完成或失败后由 worker 回应。
struct BuildRequest {
request: ObservedRequest,
request: RequestReply,
native: Option<crate::events::Input>,
kind: RequestKind,
source: String,
namespace: String,
@@ -115,6 +148,8 @@ pub fn start(
sender,
requested: Arc::new(AtomicBool::new(false)),
completion: Arc::new((Mutex::new(None), Condvar::new())),
native_sender: Arc::new(OnceLock::new()),
namespace: namespace.clone(),
};
let shutdown = Shutdown {
receiver,
@@ -135,6 +170,7 @@ pub fn start(
activity.clone(),
notify,
Some(shutdown),
Some(control.native_sender.clone()),
)?;
Ok((activity, control))
}
@@ -153,6 +189,7 @@ fn start_server(
Arc::new(Mutex::new(ActivityLog::default())),
Arc::new(|| {}),
None,
None,
)
}
@@ -164,8 +201,14 @@ fn start_server_observed(
activity: Activity,
observer_notify: Notify,
shutdown: Option<Shutdown>,
native_port: Option<Arc<OnceLock<SyncSender<BuildRequest>>>>,
) -> Result<thread::JoinHandle<()>> {
let (sender, receiver) = sync_channel::<BuildRequest>(8);
if let Some(native_port) = native_port {
native_port
.set(sender.clone())
.map_err(|_| anyhow::anyhow!("native input queue already attached"))?;
}
let worker_namespace = namespace.clone();
let worker_notify = notify.clone();
let exiting = shutdown
@@ -240,7 +283,9 @@ fn start_server_observed(
Ok(job) => {
match worker.begin_request(&job, &worker_namespace, &worker_notify) {
RequestProgress::Pending(input) => {
if matches!(&input, PendingRequest::BeforeInput) {
if job.native.is_none()
&& matches!(&input, PendingRequest::BeforeInput)
{
eprintln!(
"Tessera worker: submission {} waits for active refresh",
job.submission
@@ -299,6 +344,33 @@ fn start_server_observed(
// Capture only allowlisted headers: credentials and cookies never enter the inspector.
/// HTTP 请求的观察包装,在读取正文和响应时维护 Network 工具记录。
/// HTTP and in-process native jobs share one serial execution/refresh path.
/// Native envelopes cannot be created by an HTTP header or request body.
enum RequestReply {
Http(ObservedRequest),
Native(SyncSender<std::result::Result<(), String>>),
}
impl RequestReply {
fn respond(self, response: Response<std::io::Cursor<Vec<u8>>>) -> std::io::Result<()> {
match self {
Self::Http(request) => request.respond(response),
Self::Native(done) => {
let status = response.status_code().0;
let result = if status == 200 || status == 409 {
Ok(())
} else {
Err(String::from_utf8_lossy(response.into_reader().get_ref())
.chars()
.take(2048)
.collect())
};
let _ = done.send(result);
Ok(())
}
}
}
}
struct ObservedRequest {
inner: Request,
activity: Activity,
@@ -572,7 +644,8 @@ fn submit(
}
};
let job = BuildRequest {
request,
request: RequestReply::Http(request),
native: None,
kind,
source,
namespace: addressed.into(),