Skip to content

windows: sort installed apps by last-used and extract UWP Application Ids - #1546

Closed
f-trycua wants to merge 1 commit into
mainfrom
codex/port-functionalities-from-interface-agent-to-cua-driver-rs
Closed

windows: sort installed apps by last-used and extract UWP Application Ids#1546
f-trycua wants to merge 1 commit into
mainfrom
codex/port-functionalities-from-interface-agent-to-cua-driver-rs

Conversation

@f-trycua

@f-trycua f-trycua commented May 17, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Make the installed-apps list surface recently-used apps first while keeping deterministic fallback ordering.
  • Improve UWP/package launch tokens by resolving the manifest Application.Id so multi-entry packages launch correctly instead of always falling back to App.

Description

  • Replace the previous name-only sort with a new app_sort_key that orders entries by last_used (most-recent first) and then by lowercase name as a deterministic fallback.
  • Add read_uwp_application_id which parses AppxManifest.xml for the first <Application ... Id="..."> start tag and use that AppId when constructing the UWP launch_path token instead of hardcoding App.
  • Add small robustness checks and formatting cleanups, including early returns for empty names/paths and minor refactors in .lnk reading and string formatting to improve readability.

Testing

  • Ran cargo build and cargo test for the libs/cua-driver-rs/crates/platform-windows crate and the test suite completed successfully.

Codex Task

Summary by CodeRabbit

  • Improvements
    • App list now prioritizes recently used applications with intelligent name-based fallback sorting
    • Enhanced Windows UWP app launching and discovery capabilities
    • Improved app deduplication and shortcut resolution

Review Change Stack

@vercel

vercel Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 17, 2026 6:21pm

Request Review

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refines Windows installed-app enumeration by introducing app-sorting logic that prioritizes last-used timestamps and extracting actual Application IDs from UWP package manifests rather than hardcoding launch tokens. Supporting clarity improvements throughout make error handling and path construction more explicit.

Changes

Windows App Enumeration Improvements

Layer / File(s) Summary
App sorting by last-used and name
libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs
New app_sort_key function centralizes sorting logic, using last_used timestamps when both apps have them, and falling back to case-insensitive name comparison for deterministic ordering when recency is unavailable.
UWP Application ID extraction and launch token generation
libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs
read_uwp_application_id helper parses AppxManifest.xml to extract the first <Application Id=""> value; UWP launch token construction now uses this extracted ID to build shell:appsFolder\{family_name}!{app_id} paths instead of always using !App.
Code clarity improvements throughout
libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs
COM imports, Start Menu path construction, .lnk extension filtering, empty-name guards, shortcut argument decoding, and timestamp formatting are rewritten into explicit multi-line control flow for readability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • trycua/cua#1545: Direct predecessor refining Windows installed-app enumeration with app_sort_key and UWP manifest parsing for Application.Id extraction.
  • trycua/cua#1544: Consumes the updated UWP shell:appsFolder launch tokens (with Application.Id) for packaged-app routing and AUMID handling downstream.

Poem

🐰 Bundled apps now know their place,
Sorted swift by time and face,
Manifest IDs read with care,
Launch tokens build with flair so rare!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'windows: sort installed apps by last-used and extract UWP Application Ids' accurately summarizes the two main changes: sorting by last-used and extracting UWP Application IDs from manifests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/port-functionalities-from-interface-agent-to-cua-driver-rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs (1)

306-316: 💤 Low value

Edge case: Id=" pattern may match attribute suffixes.

The substring search for Id=" can incorrectly match attributes ending in Id, such as EntryPointId="...", extracting the wrong value. Given the "best-effort" nature and "App" fallback, this is low-risk but could cause launch failures for affected packages.

♻️ Optional: Use word-boundary matching
-    let id_key = "Id=\"";
-    let id_pos = start_tag.find(id_key)? + id_key.len();
+    // Match ` Id="` or start-of-tag `Id="` to avoid suffix matches like `EntryPointId=""`
+    let id_key = " Id=\"";
+    let id_pos = start_tag
+        .find(id_key)
+        .map(|p| p + id_key.len())
+        .or_else(|| {
+            // Handle case where Id is the first attribute (no leading space after tag name)
+            start_tag.strip_prefix("Application ")?.find("Id=\"").map(|p| p + "Application ".len() + "Id=\"".len())
+        })?;

Alternatively, a simple check that the character before Id is whitespace would suffice:

let id_key = " Id=\"";  // Note leading space
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs`
around lines 306 - 316, The Id extraction can match suffixes like EntryPointId;
update the search to require a leading whitespace so only the Id attribute is
matched: replace id_key = "Id=\"" with id_key = " Id=\"" when computing id_pos
(and keep the existing id_pos/id_end/app_id logic), and add a fallback: if "
Id=\"" is not found in start_tag, then try the original "Id=\"" only as a last
resort to preserve current behavior for edge tag layouts; reference
variables/apply changes around app_pos, start_tag, id_key, id_pos, and app_id in
installed_apps.rs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs`:
- Around line 306-316: The Id extraction can match suffixes like EntryPointId;
update the search to require a leading whitespace so only the Id attribute is
matched: replace id_key = "Id=\"" with id_key = " Id=\"" when computing id_pos
(and keep the existing id_pos/id_end/app_id logic), and add a fallback: if "
Id=\"" is not found in start_tag, then try the original "Id=\"" only as a last
resort to preserve current behavior for edge tag layouts; reference
variables/apply changes around app_pos, start_tag, id_key, id_pos, and app_id in
installed_apps.rs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 031799bc-6e22-4d37-a76d-05a552820ee9

📥 Commits

Reviewing files that changed from the base of the PR and between c9d99af and be7ff2f.

📒 Files selected for processing (1)
  • libs/cua-driver-rs/crates/platform-windows/src/win32/installed_apps.rs

@f-trycua

Copy link
Copy Markdown
Collaborator Author

Superseded by #1547, which is a strict superset: same last_used sorting + ApplicationId extraction, plus a normalize_uwp_display_name helper that handles the common ms-resource: unresolved-token case via AppxManifest.xml fallback. Closing in favor of #1547.

@f-trycua f-trycua closed this May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant