ui-egui, mcp: clippy clean (imports, arguments, test checks)

Explicit super imports in the form modules; smartart_gallery takes a
LayoutPick; needless borrows and get_or_insert_with; OpeningJobs before the
test module. Tests: clipboard seeds assert the write landed (Written::Written,
as the framework's own tests do); the edit-points test's setup, target and
closing checks are helpers; the mcp backend test module is a plain
cfg(test) module (with its wasm gate beside it) so its helpers count as test
code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 02:22:24 +00:00
co-authored by Claude Opus 5.5
parent 30735ede88
commit cbb58bc974
12 changed files with 164 additions and 117 deletions
+2 -1
View File
@@ -87,7 +87,8 @@ impl Backend for Remote {
}
}
#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
#[cfg(not(target_arch = "wasm32"))]
mod tests {
use super::*;
use serde_json::json;
+1 -1
View File
@@ -251,7 +251,7 @@ fn preview(ui: &mut Ui, bs: &mut Backstage, doc: Arc<deckcraft_model::Presentati
}
};
Stack::new().sizing(Sizing::FillWidth).gap(Gap::Row).show(ui, |ui, _| {
Picture::painter("Print preview", ThumbAspect::from_ratio(pw / ph.max(1.0)), &paint_page).extent(PictureSize::Fit).show(ui);
Picture::painter("Print preview", ThumbAspect::from_ratio(pw / ph.max(1.0)), paint_page).extent(PictureSize::Fit).show(ui);
// PanePager reports only the input delivered to this pass; a second pass cannot repeat its step.
match (PanePager {
shown: if count == 0 { 0 } else { index + 1 },
+1 -2
View File
@@ -116,8 +116,7 @@ pub(crate) fn show(app: &mut SlideApp, ui: &mut egui::Ui, space: &CanvasSpace) {
let size = ((page_size.width * scale).round().max(1.0) as u32, (page_size.height * scale).round().max(1.0) as u32);
let visible = visible_region(space.view.visible(), scale);
let picture = &mut app.picture;
let source =
picture.source.get_or_insert_with(|| Reach { uid, page, dimensions, slide: None, master: None, estimate: Rect::ZERO, drawn: Rect::ZERO });
let source = picture.source.get_or_insert(Reach { uid, page, dimensions, slide: None, master: None, estimate: Rect::ZERO, drawn: Rect::ZERO });
if source.uid != uid || source.page != page || source.dimensions != dimensions || !same(&source.slide, &slide) || !same(&source.master, &master) {
let estimate = match layout {
Some((master, layout)) => deckcraft_render::layout_extent(render_doc, master, layout),
+73 -51
View File
@@ -340,20 +340,66 @@ fn right_click(h: &mut Harness<'_, SlideApp>, pos: Pos2) {
h.run_steps(2);
}
/// A rectangle in point editing, its outline opened at the first vertex when `open_path`, with canvas menu
/// input confined to one pass.
fn edit_points_harness(open_path: bool) -> Harness<'static, SlideApp> {
let mut h = harness();
h.ctx.on_end_pass(
"canvas menu second pass",
Arc::new(|ui| {
if ui.ctx().current_pass_index() == 0 {
ui.ctx().request_discard("canvas menu input belongs to one pass");
}
}),
);
h.state_mut().run("slide.layout", json!({"layout": "blank"})).unwrap();
h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [200, 150, 300, 200]})).unwrap();
h.state_mut().run("shape.editPoints", json!({"on": true})).unwrap();
if open_path {
h.state_mut().run("shape.openPath", json!({"path": 0, "index": 0})).unwrap();
}
h.run_steps(3);
h
}
/// The edited shape's `shape.points` answer and its first path's vertices.
fn path_points(h: &mut Harness<'_, SlideApp>) -> (Value, Vec<Point>) {
let value = h.state_mut().session.execute("shape.points", &json!({})).unwrap();
let vertices = value["paths"][0].as_array().unwrap().iter().map(|p| Point::new(p[0].as_f64().unwrap(), p[1].as_f64().unwrap())).collect();
(value, vertices)
}
/// A point-editing menu command and the geometry it is asked for.
#[derive(Clone, Copy, Debug)]
enum Case {
Curve,
Add,
OpenSegment,
OpenVertex,
DeleteSegment,
DisabledDelete,
CloseVertex,
DeleteVertex,
}
impl Case {
/// The slide point right-clicked on the rectangle with vertices `original`, and the menu row's label and role.
fn target(self, original: &[Point]) -> (Point, &'static str, Role) {
match self {
Case::Curve => (Point::new(500.0, 250.0), "Curved Segment", Role::MenuItemRadio),
Case::Add => (Point::new(275.0, 150.0), "Add Point", Role::MenuItem),
Case::OpenSegment => (Point::new(500.0, 250.0), "Open Path", Role::MenuItem),
Case::OpenVertex => (original[2], "Open Path", Role::MenuItem),
Case::DeleteSegment | Case::DisabledDelete => (Point::new(500.0, 250.0), "Delete Segment", Role::MenuItem),
Case::CloseVertex => (original[0], "Close Path", Role::MenuItem),
Case::DeleteVertex => (original[1], "Delete Point", Role::MenuItem),
}
}
}
/// Segment menus use the pointer's parameter and the segment's start, and renumbering drops stale picks.
#[test]
fn edit_points_segment_menu_adds_points_and_deletes_segments() {
#[derive(Clone, Copy, Debug)]
enum Case {
Curve,
Add,
OpenSegment,
OpenVertex,
DeleteSegment,
DisabledDelete,
CloseVertex,
DeleteVertex,
}
for case in [
Case::Curve,
Case::Add,
@@ -364,37 +410,9 @@ fn edit_points_segment_menu_adds_points_and_deletes_segments() {
Case::CloseVertex,
Case::DeleteVertex,
] {
let mut h = harness();
h.ctx.on_end_pass(
"canvas menu second pass",
Arc::new(|ui| {
if ui.ctx().current_pass_index() == 0 {
ui.ctx().request_discard("canvas menu input belongs to one pass");
}
}),
);
h.state_mut().run("slide.layout", json!({"layout": "blank"})).unwrap();
h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [200, 150, 300, 200]})).unwrap();
h.state_mut().run("shape.editPoints", json!({"on": true})).unwrap();
if matches!(case, Case::DisabledDelete | Case::CloseVertex) {
h.state_mut().run("shape.openPath", json!({"path": 0, "index": 0})).unwrap();
}
h.run_steps(3);
let query = |h: &mut Harness<'_, SlideApp>| h.state_mut().session.execute("shape.points", &json!({})).unwrap();
let vertices = |value: &Value| -> Vec<Point> {
value["paths"][0].as_array().unwrap().iter().map(|p| Point::new(p[0].as_f64().unwrap(), p[1].as_f64().unwrap())).collect()
};
let before = query(&mut h);
let original = vertices(&before);
let (at, label, role) = match case {
Case::Curve => (Point::new(500.0, 250.0), "Curved Segment", Role::MenuItemRadio),
Case::Add => (Point::new(275.0, 150.0), "Add Point", Role::MenuItem),
Case::OpenSegment => (Point::new(500.0, 250.0), "Open Path", Role::MenuItem),
Case::OpenVertex => (original[2], "Open Path", Role::MenuItem),
Case::DeleteSegment | Case::DisabledDelete => (Point::new(500.0, 250.0), "Delete Segment", Role::MenuItem),
Case::CloseVertex => (original[0], "Close Path", Role::MenuItem),
Case::DeleteVertex => (original[1], "Delete Point", Role::MenuItem),
};
let mut h = edit_points_harness(matches!(case, Case::DisabledDelete | Case::CloseVertex));
let (before, original) = path_points(&mut h);
let (at, label, role) = case.target(&original);
let p = screen(h.state(), at.x, at.y);
let asked = slide_point(&h, p);
right_click(&mut h, p);
@@ -407,8 +425,7 @@ fn edit_points_segment_menu_adds_points_and_deletes_segments() {
assert!(!h.get_by_role_and_label(role, label).accesskit_node().is_disabled(), "{case:?}: the command is available");
h.get_by_role_and_label(role, label).click();
h.run_steps(3);
let after = query(&mut h);
let result = vertices(&after);
let (after, result) = path_points(&mut h);
match case {
Case::Curve => {
let (path, index) = picks.0.unwrap();
@@ -447,16 +464,21 @@ fn edit_points_segment_menu_adds_points_and_deletes_segments() {
assert!(!result.contains(&at), "the picked vertex is removed");
}
}
if !matches!(case, Case::Curve) {
assert!(
h.state().session.tool.edit_segment.is_none() && h.state().session.tool.edit_vertex.is_none(),
"{case:?}: renumbering clears both picks"
);
}
assert!(h.state().canvas_menu.is_none(), "a picked command closes the menu across the second pass");
assert_command_settled(&h, case);
}
}
/// After `case`'s command: a renumbering command cleared both picks, and the menu closed.
fn assert_command_settled(h: &Harness<'_, SlideApp>, case: Case) {
if !matches!(case, Case::Curve) {
assert!(
h.state().session.tool.edit_segment.is_none() && h.state().session.tool.edit_vertex.is_none(),
"{case:?}: renumbering clears both picks"
);
}
assert!(h.state().canvas_menu.is_none(), "a picked command closes the menu across the second pass");
}
/// The menu follows live selection and text state, including a repeated word's actual character range.
#[test]
fn canvas_menu_rows_follow_the_selection() {
+6 -2
View File
@@ -7,7 +7,9 @@ use serde_json::{Value, json};
/// The slide show configuration form.
pub(crate) mod setup_show {
use super::*;
use super::{
Bind, Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult, SlideApp, Value, json,
};
/// Opens show options seeded from the deck and the cursor preference.
pub(crate) fn open(app: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
@@ -62,7 +64,9 @@ pub(crate) mod setup_show {
/// The clipboard representation form.
pub(crate) mod paste_special {
use super::*;
use super::{
Bind, Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamDialog, ParamKind, ParamLayout, ParamResult, SlideApp, Value, json,
};
/// Opens paste choices with reasons for formats requiring copied shapes.
pub(crate) fn open(app: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
+7 -7
View File
@@ -14,7 +14,7 @@ fn form(ctx: &Context, id: &'static str, title: &'static str, fields: DialogFiel
/// The table dimensions form.
pub(crate) mod table {
use super::*;
use super::{Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamKind, ParamResult, SlideApp, Value, form, json};
/// Opens the table dimensions with positive row and column counts.
pub(crate) fn open(_: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
@@ -39,7 +39,7 @@ pub(crate) mod table {
/// The comment composition form.
pub(crate) mod comment {
use super::*;
use super::{Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamKind, ParamResult, SlideApp, Value, form, json};
/// Opens a multiline comment editor.
pub(crate) fn open(_: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
@@ -66,7 +66,7 @@ pub(crate) mod comment {
/// The outline insertion form.
pub(crate) mod outline {
use super::*;
use super::{Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamKind, ParamResult, SlideApp, Value, form, json};
/// Opens an outline editor that preserves indentation.
pub(crate) fn open(_: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
@@ -120,7 +120,7 @@ fn finish_rename(app: &mut SlideApp, result: &ParamResult) -> Result<(), String>
/// The section rename form.
pub(crate) mod rename_section {
use super::*;
use super::{Context, DialogHost, HostedParamDialog, ParamResult, SlideApp, Value, finish_rename, rename};
/// Opens a name editor carrying the section index.
pub(crate) fn open(_: &SlideApp, ctx: &Context, params: &Value) -> HostedParamDialog {
@@ -135,7 +135,7 @@ pub(crate) mod rename_section {
/// The shape rename form.
pub(crate) mod rename_shape {
use super::*;
use super::{Context, DialogHost, HostedParamDialog, ParamResult, SlideApp, Value, finish_rename, rename};
/// Opens a name editor carrying the shape id.
pub(crate) fn open(_: &SlideApp, ctx: &Context, params: &Value) -> HostedParamDialog {
@@ -150,7 +150,7 @@ pub(crate) mod rename_shape {
/// The layout rename form.
pub(crate) mod rename_layout {
use super::*;
use super::{Context, DialogHost, HostedParamDialog, ParamResult, SlideApp, Value, finish_rename, rename};
/// Opens the layout name editor.
pub(crate) fn open(_: &SlideApp, ctx: &Context, params: &Value) -> HostedParamDialog {
@@ -165,7 +165,7 @@ pub(crate) mod rename_layout {
/// The linear equation insertion form.
pub(crate) mod equation {
use super::*;
use super::{Context, DialogFields, DialogHost, HostedParamDialog, Param, ParamKind, ParamResult, SlideApp, Value, form, json};
/// Opens the equation editor with its linear notation guide.
pub(crate) fn open(_: &SlideApp, ctx: &Context, _: &Value) -> HostedParamDialog {
+34 -34
View File
@@ -108,6 +108,40 @@ impl SlideApp {
}
}
/// The native open queue and its monotonic attempt-key allocator.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) struct OpeningJobs {
queue: craft::host::queue::JobQueue<u64, Result<LoadedFile, String>>,
next_key: u64,
}
#[cfg(not(target_arch = "wasm32"))]
impl OpeningJobs {
/// Build the queue with the installed host's jobs and its window's repaint wake.
pub(crate) fn new(jobs: std::sync::Arc<dyn craft::host::Jobs>, wake: craft::host::Wake) -> Self {
Self { queue: craft::host::queue::JobQueue::new(jobs, wake, Default::default()), next_key: 0 }
}
fn submit(&mut self, path: &str, host: &craft::host::Host) -> Result<u64, String> {
let key = self.next_key.checked_add(1).ok_or_else(|| "The opening attempt limit was reached".to_owned())?;
self.next_key = key;
let path = path.to_owned();
let host = host.clone();
let roots = deckcraft_engine::file_access::current();
self.queue.submit(key, craft::host::queue::Priority::VISIBLE, move |_| {
deckcraft_engine::file_access::confine(roots.as_ref(), || {
deckcraft_engine::cmd::file::read_presentation_file_with(
&path,
|path| host.files().read_metadata(std::path::Path::new(path)).map_err(|error| error.to_string()),
|path| host.files().read(std::path::Path::new(path)).map_err(|error| error.to_string()),
)
.map_err(|error| error.to_string())
})
});
Ok(key)
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used)]
@@ -302,37 +336,3 @@ mod tests {
}
}
}
/// The native open queue and its monotonic attempt-key allocator.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) struct OpeningJobs {
queue: craft::host::queue::JobQueue<u64, Result<LoadedFile, String>>,
next_key: u64,
}
#[cfg(not(target_arch = "wasm32"))]
impl OpeningJobs {
/// Build the queue with the installed host's jobs and its window's repaint wake.
pub(crate) fn new(jobs: std::sync::Arc<dyn craft::host::Jobs>, wake: craft::host::Wake) -> Self {
Self { queue: craft::host::queue::JobQueue::new(jobs, wake, Default::default()), next_key: 0 }
}
fn submit(&mut self, path: &str, host: &craft::host::Host) -> Result<u64, String> {
let key = self.next_key.checked_add(1).ok_or_else(|| "The opening attempt limit was reached".to_owned())?;
self.next_key = key;
let path = path.to_owned();
let host = host.clone();
let roots = deckcraft_engine::file_access::current();
self.queue.submit(key, craft::host::queue::Priority::VISIBLE, move |_| {
deckcraft_engine::file_access::confine(roots.as_ref(), || {
deckcraft_engine::cmd::file::read_presentation_file_with(
&path,
|path| host.files().read_metadata(std::path::Path::new(path)).map_err(|error| error.to_string()),
|path| host.files().read(std::path::Path::new(path)).map_err(|error| error.to_string()),
)
.map_err(|error| error.to_string())
})
});
Ok(key)
}
}
+1 -1
View File
@@ -80,7 +80,7 @@ pub(crate) fn color_row_named(
});
field.settle(|_, output| {
let mut popup = Popover::new(Word::plain("Color"), Bind::kept().reset(false))
.id_salt(&format!("{key}:menu"))
.id_salt(format!("{key}:menu"))
.overlay(|overlay| overlay.opened_by(&output.response, Trigger::Click))
.show(ui, |ui, cx| color_menu(app, ui, cx, &key, none));
let picked = popup.settle(|_, pick| pick.take()).flatten();
+18 -10
View File
@@ -65,18 +65,26 @@ const QUICK_STYLE_ASPECT: f32 = 40.0 / 26.0;
/// Width over height of a slide layout picture: the 16:9 slide.
const LAYOUT_TILE_ASPECT: f32 = 96.0 / 54.0;
/// The diagram a layout gallery previews and the command a picked layout runs.
pub(crate) struct LayoutPick<'a> {
/// The command run with the picked layout's `kind`.
pub cmd: &'a str,
/// Further command parameters.
pub extra: Value,
/// The layout shown as selected.
pub current: &'a str,
/// The quick style the previews draw in.
pub style: &'a str,
/// The colour scheme the previews draw in.
pub colors: &'a str,
/// The selected diagram's items, previewed in each layout.
pub nodes: Option<&'a [deckcraft_model::DiagramNode]>,
}
/// Shows diagram layouts by category, with a preview of the graphic's outline in each tooltip.
pub(crate) fn smartart_gallery(
app: &mut SlideApp,
ui: &mut Ui,
cx: &mut BodyCx<'_>,
cmd: &str,
extra: Value,
current: &str,
(style, colors): (&str, &str),
nodes: Option<&[deckcraft_model::DiagramNode]>,
) {
pub(crate) fn smartart_gallery(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>, pick: LayoutPick<'_>) {
use deckcraft_engine::cmd::smartart::{LAYOUTS, category};
let LayoutPick { cmd, extra, current, style, colors, nodes } = pick;
let Some((doc, slide)) = app.session.active().map(|active| (active.doc.clone(), active.selection.slide)) else { return };
let thumbs = super::diagram_thumbs::thumbnails(ui.ctx());
let pictures = super::diagram_thumbs::DiagramThumbs::new(&doc, slide, style, colors, nodes);
+3 -2
View File
@@ -17,7 +17,7 @@ use egui::{Color32, Ui};
use serde_json::{Value, json};
use super::arrange::arrange_menu;
use super::galleries::{self, cref_param, effects_menu, layout_gallery, outline_menu, quick_styles, shapes_gallery, smartart_gallery};
use super::galleries::{self, LayoutPick, cref_param, effects_menu, layout_gallery, outline_menu, quick_styles, shapes_gallery, smartart_gallery};
use super::{fmt_state, fonts};
use crate::SlideApp;
use crate::icons::Icon;
@@ -359,7 +359,8 @@ fn paragraph(app: &mut SlideApp, ui: &mut Ui) {
.enabled(commands::resolve(ui.ctx(), "smartArt.fromText").enabled)
.show(ui);
Menu::new(Word::plain("Convert to Diagram")).opened_by(&diagram.response, Trigger::Click).show(ui, |ui, cx| {
smartart_gallery(app, ui, cx, "smartArt.fromText", json!({}), "", ("", ""), None);
let pick = LayoutPick { cmd: "smartArt.fromText", extra: json!({}), current: "", style: "", colors: "", nodes: None };
smartart_gallery(app, ui, cx, pick);
});
Button::command("format.paragraphDialog").label(Word::plain("Paragraph…")).show(ui);
});
+10 -2
View File
@@ -1,5 +1,5 @@
use super::arrange::arrange_group;
use super::galleries::smartart_gallery;
use super::galleries::{LayoutPick, smartart_gallery};
use super::{Icon, SlideApp, Value, json};
use craft::menu::ribbon::{RibbonGroup, RibbonRow};
use craft::ui::buttons::{Arrangement, Button};
@@ -75,7 +75,15 @@ pub(crate) fn smartart_design(app: &mut SlideApp, row: &mut RibbonRow<'_>) {
.enabled(menu_enabled(ui, "smartArt.layout"))
.show(ui);
Menu::new("Layouts").opened_by(&opener.response, Trigger::Click).show(ui, |ui, cx| {
smartart_gallery(app, ui, cx, "smartArt.layout", json!({"id": gid}), &kind, (&style, &colors), outline.as_deref());
let pick = LayoutPick {
cmd: "smartArt.layout",
extra: json!({"id": gid}),
current: &kind,
style: &style,
colors: &colors,
nodes: outline.as_deref(),
};
smartart_gallery(app, ui, cx, pick);
});
let opener = Button::new("Convert")
.icon(Icon::Layout.id())
+8 -4
View File
@@ -2,9 +2,11 @@
use super::*;
use craft::host::{Picked, ScriptedFiles};
use craft::platform::clipboard::Written;
use craft::ui::runtime::commands::{ClipItem, ClipboardHandle};
use craft::ui::runtime::env::WindowKey;
use craft::ui::runtime::windows::WindowHost;
use deckcraft_engine::Mods;
use egui_kittest::kittest::Queryable;
use std::sync::Arc;
@@ -421,7 +423,7 @@ fn ctrl_v_pastes_the_picture_a_browser_copied_not_its_link() {
image.as_raw(),
))));
}
ClipboardHandle::of(&harness.ctx).offer(&offer).unwrap();
assert_eq!(ClipboardHandle::of(&harness.ctx).offer(&offer).unwrap(), Written::Written);
harness.run_steps(2);
let shapes_before = harness.state().session.active().unwrap().doc.slides[0].shapes.len();
harness.event(egui::Event::Paste(text.clone()));
@@ -447,7 +449,8 @@ fn ctrl_v_pastes_an_image_when_no_paste_event_arrives() {
app.session.active().unwrap().doc.slides[0].shapes.iter().filter(|s| matches!(s.kind, deckcraft_model::ShapeKind::Picture { .. })).count()
};
let before = pictures(h.state());
ClipboardHandle::of(&h.ctx).offer(&[ClipItem::Image(Arc::new(egui::ColorImage::filled([2, 2], egui::Color32::RED)))]).unwrap();
let image = ClipItem::Image(Arc::new(egui::ColorImage::filled([2, 2], egui::Color32::RED)));
assert_eq!(ClipboardHandle::of(&h.ctx).offer(&[image]).unwrap(), Written::Written);
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::V);
h.run_steps(2);
assert_eq!(pictures(h.state()), before + 1);
@@ -758,7 +761,7 @@ fn copy_and_cut_commands_reach_the_system_clipboard() {
harness.get_by_role_and_label(egui::accesskit::Role::Button, "Copy").click();
harness.run_steps(1);
assert_eq!(copied(&harness).as_deref(), Some("Aurora"), "Copy puts the text on the clipboard");
clipboard.offer(&[ClipItem::Text("clipboard sentinel".into())]).unwrap();
assert_eq!(clipboard.offer(&[ClipItem::Text("clipboard sentinel".into())]).unwrap(), Written::Written);
harness.run_steps(1);
assert_eq!(copied(&harness).as_deref(), Some("clipboard sentinel"), "copy is published once");
@@ -1038,7 +1041,8 @@ fn copy_offers_html_and_paste_keeps_bold() {
assert!(html.contains("<b>"), "{html}");
assert_eq!(plain, "Hi");
let mut h = step_app(Services::default());
ClipboardHandle::of(&h.ctx).offer(&[ClipItem::Html(html.into()), ClipItem::Text(plain.clone().into())]).unwrap();
let offer = [ClipItem::Html(html.into()), ClipItem::Text(plain.clone().into())];
assert_eq!(ClipboardHandle::of(&h.ctx).offer(&offer).unwrap(), Written::Written);
h.event(egui::Event::Paste(plain));
h.run_steps(1);
let st = h.state().session.active().unwrap();