fix(appd): list installed apps in name order

The catalog followed the store's directory listing, so the launcher's
order, and with it its keyboard order, could change between scans. Apps
are listed by name, ignoring case, then by ID.
This commit is contained in:
Marco Allegretti 2026-10-09 20:21:26 +00:00
parent 73dc2cbaa5
commit e83c3f6df0
No known key found for this signature in database

View file

@ -766,6 +766,9 @@ fn scan_installed_apps() -> Vec<AppInfo> {
} }
} }
} }
// A stable order, so the launcher's keyboard order does not follow the
// directory listing.
apps.sort_by_cached_key(|app| (app.name.to_lowercase(), app.app_id.clone()));
apps apps
} }
@ -1191,23 +1194,42 @@ mod tests {
let _env = env_lock().blocking_lock(); let _env = env_lock().blocking_lock();
let store = std::env::temp_dir().join(format!("weft_appd_scan_{}", std::process::id())); let store = std::env::temp_dir().join(format!("weft_appd_scan_{}", std::process::id()));
let app_dir = store.join("com.example.scanner"); // Listed by name, ignoring case, then by ID, whatever the directory
fs::create_dir_all(&app_dir).unwrap(); // order.
fs::write( for (id, name) in [
app_dir.join("wapp.toml"), ("com.example.scanner", "Scanner"),
"[package]\nid = \"com.example.scanner\"\nname = \"Scanner\"\nversion = \"1.0.0\"\n\ ("com.example.zeta", "alpha"),
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n", ("com.example.second", "Alpha"),
) ("com.example.first", "Alpha"),
.unwrap(); ] {
let app_dir = store.join(id);
fs::create_dir_all(&app_dir).unwrap();
fs::write(
app_dir.join("wapp.toml"),
format!(
"[package]\nid = \"{id}\"\nname = \"{name}\"\nversion = \"1.0.0\"\n\
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n"
),
)
.unwrap();
}
let prior = std::env::var("WEFT_APP_STORE").ok(); let prior = std::env::var("WEFT_APP_STORE").ok();
unsafe { std::env::set_var("WEFT_APP_STORE", &store) }; unsafe { std::env::set_var("WEFT_APP_STORE", &store) };
let apps = scan_installed_apps(); let apps = scan_installed_apps();
assert_eq!(apps.len(), 1); let ids: Vec<&str> = apps.iter().map(|a| a.app_id.as_str()).collect();
assert_eq!(apps[0].app_id, "com.example.scanner"); assert_eq!(
assert_eq!(apps[0].name, "Scanner"); ids,
assert_eq!(apps[0].version, "1.0.0"); [
"com.example.first",
"com.example.second",
"com.example.zeta",
"com.example.scanner"
]
);
assert_eq!(apps[3].name, "Scanner");
assert_eq!(apps[3].version, "1.0.0");
unsafe { unsafe {
match prior { match prior {