Skip to content

Conversation

@MuhammadAbdullahIqbal23
Copy link
Collaborator

What was the issue

  • The app only used mdls to get app metadata, which could fail on some systems or wouldn't work if storage on the device is full, leaving users with incomplete or no app information.

How you solved it

- Added plutil as a fallback mechanism that:

  1. Runs when mdls command fails (status ≠ 0)
  2. Uses spawn("plutil", ["-p", "${app}/Contents/Info.plist"]) for each app
  3. Parses plist output to extract CFBundleDisplayName, CFBundleVersion, and CFBundleIdentifier
  4. Maintains same data structure as mdls output

Problems within it

  • Inconsistent parsing - Different regex patterns for mdls vs plutil output formats

Refactor getAppsFileInfo to improve error handling and update fallback logic; add test for mdls failure fallback to plutil
…n, appCreatedDate, appIdentifier only not all the properties in the Info.Plist
…l, no changes made for mdls as spawnsync is used by default by the package
Copy link
Member

@SaadBazaz SaadBazaz left a comment

Choose a reason for hiding this comment

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

Please fix these problems, quite unoptimized right now. But promising. No worries about the format change, I see that's a recurring problem in this code.

src/mac.ts Outdated
for (const app of appsFile) {
try {
const result = await new Promise<any>((resolve) => {
const runPlutilShell = spawn("plutil", ["-p", `${app}/Contents/Info.plist`]);
Copy link
Member

Choose a reason for hiding this comment

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

This is not actually running in parallel; it's still just calling a for loop and just awaiting each call. Same thing as before.

Try creating separate spawns in parallel.

Here's a prompt which might help you:

You're a senior software engineer experienced in parallel computing and optimization.

Turn this block of code into a parallel call; each spawn should be saved into a list, and use Promise.all to resolve them all together (of course, don't crash upon fail. Just keep going). 

src/mac.ts Outdated
} catch (error) {
// Fallback to plutil for all apps if mdls fails
for (const app of appsFile) {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Don't do this try catch in the iteration itself, do it once on the entire loop. If something in the loop fails, throw an error and catch it, then in the catch, try the fallback.

Copy link
Member

@SaadBazaz SaadBazaz left a comment

Choose a reason for hiding this comment

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

Your formattings are very verbose. And don't return the full data.

src/mac.ts Outdated
}
}

resolve({ appName, appVersion, appInstallDate: "", appIdentifier });
Copy link
Member

Choose a reason for hiding this comment

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

Also return all the other data...

2) used promised for Asynchronous Flow
3) returning all data for plutil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants