Skip to content

Commit

Permalink
Update system app traversal and search optimization
Browse files Browse the repository at this point in the history
Enhanced '/System/Applications' path traversal in the Wox plugin system for Darwin OS and streamlined the query routine in the Application Plugin. Removed unnecessary sub-directory checks and iteration, and optimized the search for applications by directly using information from the apps list.
  • Loading branch information
qianlifeng committed May 9, 2024
1 parent b09742b commit 247fc6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
20 changes: 1 addition & 19 deletions Wox/plugin/system/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func (a *ApplicationPlugin) Init(ctx context.Context, initParams plugin.InitPara

func (a *ApplicationPlugin) Query(ctx context.Context, query plugin.Query) []plugin.QueryResult {
var results []plugin.QueryResult
for _, infoShadow := range a.apps {
// action will be executed in another go routine, so we need to copy the variable
info := infoShadow
for _, info := range a.apps {
if isMatch, score := system.IsStringMatchScore(ctx, info.Name, query.Search); isMatch {
results = append(results, plugin.QueryResult{
Id: uuid.NewString(),
Expand Down Expand Up @@ -295,22 +293,6 @@ func (a *ApplicationPlugin) getAppPaths(ctx context.Context, appDirectories []ap
appPaths = append(appPaths, a.getAppPaths(ctx, []appDirectory{{Path: subDir, Recursive: true}})...)
continue
}

appSubDir, readSubDirErr := os.ReadDir(subDir)
if readSubDirErr != nil {
a.api.Log(ctx, plugin.LogLevelError, fmt.Sprintf("error reading sub directory %s: %s", subDir, readSubDirErr.Error()))
continue
}

for _, subEntry := range appSubDir {
isExtensionMatch = lo.ContainsBy(appExtensions, func(ext string) bool {
return strings.HasSuffix(subEntry.Name(), fmt.Sprintf(".%s", ext))
})
if isExtensionMatch {
appPaths = append(appPaths, path.Join(dir.Path, entry.Name(), subEntry.Name()))
continue
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Wox/plugin/system/app/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (a *MacRetriever) GetAppDirectories(ctx context.Context) []appDirectory {
{
Path: "/System/Applications", Recursive: false,
},
{
Path: "/System/Applications/Utilities", Recursive: false,
},
{
Path: "/System/Library/PreferencePanes", Recursive: false,
},
Expand Down

0 comments on commit 247fc6f

Please sign in to comment.