From e83c3f6df07026a6831440b24a6955d0f781f9a9 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 20:21:26 +0000 Subject: [PATCH] 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. --- crates/weft-appd/src/main.rs | 46 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/crates/weft-appd/src/main.rs b/crates/weft-appd/src/main.rs index d3e716f..693b9ee 100644 --- a/crates/weft-appd/src/main.rs +++ b/crates/weft-appd/src/main.rs @@ -766,6 +766,9 @@ fn scan_installed_apps() -> Vec { } } } + // 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 } @@ -1191,23 +1194,42 @@ mod tests { let _env = env_lock().blocking_lock(); let store = std::env::temp_dir().join(format!("weft_appd_scan_{}", std::process::id())); - let app_dir = store.join("com.example.scanner"); - fs::create_dir_all(&app_dir).unwrap(); - fs::write( - app_dir.join("wapp.toml"), - "[package]\nid = \"com.example.scanner\"\nname = \"Scanner\"\nversion = \"1.0.0\"\n\ - [runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n", - ) - .unwrap(); + // Listed by name, ignoring case, then by ID, whatever the directory + // order. + for (id, name) in [ + ("com.example.scanner", "Scanner"), + ("com.example.zeta", "alpha"), + ("com.example.second", "Alpha"), + ("com.example.first", "Alpha"), + ] { + 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(); unsafe { std::env::set_var("WEFT_APP_STORE", &store) }; let apps = scan_installed_apps(); - assert_eq!(apps.len(), 1); - assert_eq!(apps[0].app_id, "com.example.scanner"); - assert_eq!(apps[0].name, "Scanner"); - assert_eq!(apps[0].version, "1.0.0"); + let ids: Vec<&str> = apps.iter().map(|a| a.app_id.as_str()).collect(); + assert_eq!( + ids, + [ + "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 { match prior {