Add managed Window resource and native shell operations
Verify Tessera GUI / verify (push) Failing after 7m25s

This commit is contained in:
2026-10-21 17:12:55 +08:00
parent 3ea4bac48c
commit 76e293d3b8
11 changed files with 681 additions and 41 deletions
+65 -19
View File
@@ -29,6 +29,7 @@ pub const TYPE_NAMES: &[&str] = &[
"Column",
"Button",
"Page",
"Window",
"Mount",
"Event",
"Subscription",
@@ -195,6 +196,8 @@ enum Operation {
Mounts,
Stats,
Viewport,
Window,
PageWindow,
State,
StateSet,
Increment,
@@ -440,11 +443,8 @@ fn new_typed_block(
fn show(cx: &mut NativeContext<'_>, page: ObjectRef, session: &Shared) -> Result<(), VmError> {
let mut state = session.lock().map_err(|_| invalid("UI session poisoned"))?;
cx.dict_set(
state.tabs,
Value::Text(page.to_string()),
Value::Object(page),
)?;
let window = object(Some(&cx.store().get_attr(state.desktop, "window")?))?;
crate::window::register_page(cx, window, page)?;
cx.set_attr(state.desktop, "pending", Value::Object(page))?;
state.pending = Some(Some(page));
Ok(())
@@ -496,7 +496,7 @@ impl NativeCallable for Function {
use Operation::*;
let (minimum, maximum) = match self.operation {
IsInstance | IsSubtype => (2, 2),
Stats | Viewport | Mounts => (0, 0),
Stats | Viewport | Window | PageWindow | Mounts => (0, 0),
State | StateSet => (1, 1),
Increment => (0, 0),
TextOf => (2, 4),
@@ -507,7 +507,8 @@ impl NativeCallable for Function {
Row | Column => (2, MAX_UI_NODES + 2),
Button => (1, 1),
Replace | Move => (2, 2),
Page | Unmount | Open | Close | Activate | Back | Forward | Children => (0, 0),
Page | Unmount | Close | Activate | Back | Forward | Children => (0, 0),
Open => (0, 1),
Click | Invalidate => (0, 1),
On => (2, 3),
Dispatch => (1, 2),
@@ -608,6 +609,16 @@ impl NativeCallable for Function {
)?;
return Ok(NativeResult::Return(Value::Object(set)));
}
if matches!(self.operation, Window) {
let desktop = self
.session
.lock()
.map_err(|_| invalid("UI session poisoned"))?
.desktop;
return Ok(NativeResult::Return(
cx.store().get_attr(desktop, "window")?,
));
}
if matches!(self.operation, Viewport) {
let desktop = self
.session
@@ -939,7 +950,34 @@ impl NativeCallable for Function {
}];
show(cx, owner, &self.session)?;
}
PageWindow => {
let desktop = self
.session
.lock()
.map_err(|_| invalid("UI session poisoned"))?
.desktop;
let window = object(Some(&cx.store().get_attr(desktop, "window")?))?;
let value = if crate::window::pages(cx.store(), window)?.contains(&owner) {
Value::Object(window)
} else {
Value::Nil
};
return Ok(NativeResult::Return(value));
}
Open | Activate => {
if let Some(requested) = args.first()
&& !matches!(requested, Value::Nil)
{
let desktop = self
.session
.lock()
.map_err(|_| invalid("UI session poisoned"))?
.desktop;
let window = cx.store().get_attr(desktop, "window")?;
if requested != &window {
return Err(invalid("Page.open requires this runtime's native Window"));
}
}
show(cx, owner, &self.session)?;
return Ok(NativeResult::Return(Value::Object(owner)));
}
@@ -951,19 +989,10 @@ impl NativeCallable for Function {
.session
.lock()
.map_err(|_| invalid("UI session poisoned"))?;
cx.dict_delete(session.tabs, &Value::Text(owner.to_string()))?;
let window = object(Some(&cx.store().get_attr(session.desktop, "window")?))?;
crate::window::unregister_page(cx, window, owner)?;
if session.active == Some(owner) || session.pending == Some(Some(owner)) {
let next =
cx.store()
.dict_items(session.tabs)?
.first()
.and_then(|(_, value)| {
if let Value::Object(page) = value {
Some(*page)
} else {
None
}
});
let next = crate::window::pages(cx.store(), window)?.first().copied();
cx.set_attr(
session.desktop,
"pending",
@@ -1050,6 +1079,18 @@ pub struct UiBridge {
}
impl UiBridge {
pub fn take_window_commands(&self, vm: &Vm) -> Result<Vec<crate::window::Command>> {
let desktop = self
.session
.lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
.desktop;
let Value::Object(window) = vm.get_attr(desktop, "window")? else {
bail!("native Window is unavailable");
};
Ok(crate::window::take_commands(vm, window)?)
}
pub fn set_viewport(&self, vm: &mut Vm, viewport: Option<crate::layout::Size>) -> Result<bool> {
if let Some(size) = viewport
&& (!size.width.is_finite()
@@ -1493,6 +1534,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
("textOf", Operation::TextOf),
("stats", Operation::Stats),
("viewport", Operation::Viewport),
("window", Operation::Window),
] {
let function = vm.allocate(ContextNativeFunction::new(
name,
@@ -1526,6 +1568,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
("Column", "ContainerBlock", Some("column")),
("Button", "ContainerBlock", Some("button")),
("Page", "ContainerBlock", Some("page")),
("Window", "Object", None),
("Mount", "Object", None),
("Event", "Object", Some("event")),
("Subscription", "Object", None),
@@ -1645,6 +1688,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
"textOf",
"stats",
"viewport",
"window",
"isInstance",
"isSubtype",
] {
@@ -1672,6 +1716,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
("Page", "render", Operation::Render),
("Page", "unmount", Operation::Unmount),
("Page", "open", Operation::Open),
("Page", "window", Operation::PageWindow),
("Page", "close", Operation::Close),
("Page", "activate", Operation::Activate),
("Page", "navigate", Operation::Navigate),
@@ -1692,6 +1737,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
vm.attach_type(method, function_type)?;
vm.define_method(expected, name, method)?;
}
crate::window::install(vm, roots, desktop, tabs)?;
let block_type = object(Some(&vm.get_attr(ui, "Block")?))?;
crate::native_visual::install(vm, roots, desktop, block_type, function_type)?;
let event_type = object(Some(&vm.get_attr(ui, "Event")?))?;