treewide: cleanup

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia01590cdeed872cc8ebd16f6ca95f3cc6a6a6964
This commit is contained in:
raf 2026-03-11 17:23:51 +03:00
commit 185e3b562a
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
16 changed files with 258 additions and 219 deletions

View file

@ -35,13 +35,6 @@ pub struct PluginPage {
pub allowed_endpoints: Vec<String>,
}
impl PluginPage {
/// The canonical route for this page, taken directly from the page schema.
pub fn full_route(&self) -> String {
self.page.route.clone()
}
}
/// Registry of all plugin-provided UI pages and widgets
///
/// This is typically stored as a signal in the Dioxus tree.
@ -109,14 +102,11 @@ impl PluginRegistry {
);
return;
}
self.pages.insert(
(plugin_id.clone(), page_id),
PluginPage {
plugin_id,
page,
allowed_endpoints,
},
);
self.pages.insert((plugin_id.clone(), page_id), PluginPage {
plugin_id,
page,
allowed_endpoints,
});
}
/// Get a specific page by plugin ID and page ID
@ -179,7 +169,7 @@ impl PluginRegistry {
self
.pages
.values()
.map(|p| (p.plugin_id.clone(), p.page.id.clone(), p.full_route()))
.map(|p| (p.plugin_id.clone(), p.page.id.clone(), p.page.route.clone()))
.collect()
}
@ -207,7 +197,9 @@ impl PluginRegistry {
}
match self.client.get_plugin_ui_theme_extensions().await {
Ok(vars) => tmp.theme_vars = vars,
Err(e) => tracing::warn!("Failed to refresh plugin theme extensions: {e}"),
Err(e) => {
tracing::warn!("Failed to refresh plugin theme extensions: {e}")
},
}
// Atomic swap: no window where the registry appears empty.
@ -367,7 +359,7 @@ mod tests {
}
#[test]
fn test_page_full_route() {
fn test_page_route() {
let client = ApiClient::default();
let mut registry = PluginRegistry::new(client);
registry.register_page(
@ -376,9 +368,7 @@ mod tests {
vec![],
);
let plugin_page = registry.get_page("my-plugin", "demo").unwrap();
// full_route() returns page.route directly; create_test_page sets it as
// "/plugins/test/{id}"
assert_eq!(plugin_page.full_route(), "/plugins/test/demo");
assert_eq!(plugin_page.page.route, "/plugins/test/demo");
}
#[test]
@ -418,8 +408,16 @@ mod tests {
fn test_all_pages_returns_references() {
let client = ApiClient::default();
let mut registry = PluginRegistry::new(client);
registry.register_page("p1".to_string(), create_test_page("a", "A"), vec![]);
registry.register_page("p2".to_string(), create_test_page("b", "B"), vec![]);
registry.register_page(
"p1".to_string(),
create_test_page("a", "A"),
vec![],
);
registry.register_page(
"p2".to_string(),
create_test_page("b", "B"),
vec![],
);
let pages = registry.all_pages();
assert_eq!(pages.len(), 2);
@ -536,7 +534,11 @@ mod tests {
assert_eq!(registry.all_pages().len(), 0);
// Valid page; should still register fine
registry.register_page("p".to_string(), create_test_page("good", "Good"), vec![]);
registry.register_page(
"p".to_string(),
create_test_page("good", "Good"),
vec![],
);
assert_eq!(registry.all_pages().len(), 1);
}