Skip to content

Commit

Permalink
Add recursion depth to app directory retrieval
Browse files Browse the repository at this point in the history
This commit introduces a 'RecursiveDepth' attribute as an enhancement to the app directory retrieval in the Wox plugin system. This allows more flexibility in controlling the depth of recursion when retrieving apps. Additionally, this commit alters the 'GetAppDirectories' implementation on both macOS and Windows to reflect this new feature.
  • Loading branch information
qianlifeng committed May 12, 2024
1 parent 9da9d4a commit 1556fbb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
5 changes: 2 additions & 3 deletions Wox/plugin/system/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ func (a *ApplicationPlugin) getAppPaths(ctx context.Context, appDirectories []ap
continue
}

if dir.Recursive {
appPaths = append(appPaths, a.getAppPaths(ctx, []appDirectory{{Path: subDir, Recursive: true}})...)
continue
if dir.Recursive && dir.RecursiveDepth > 0 {
appPaths = append(appPaths, a.getAppPaths(ctx, []appDirectory{{Path: subDir, Recursive: true, RecursiveDepth: dir.RecursiveDepth - 1}})...)
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions Wox/plugin/system/app/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ func (a *MacRetriever) GetAppDirectories(ctx context.Context) []appDirectory {
Path: userHomeApps, Recursive: false,
},
{
Path: "/Applications", Recursive: false,
Path: "/Applications", Recursive: true, RecursiveDepth: 2,
},
{
Path: "/Applications/Utilities", Recursive: false,
},
{
Path: "/System/Applications", Recursive: false,
},
{
Path: "/System/Applications/Utilities", Recursive: false,
Path: "/System/Applications", Recursive: true, RecursiveDepth: 2,
},
{
Path: "/System/Library/PreferencePanes", Recursive: false,
Expand Down
6 changes: 3 additions & 3 deletions Wox/plugin/system/app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/lxn/win"
"github.com/parsiya/golnk"
"image"
"image/color"
Expand Down Expand Up @@ -39,8 +38,9 @@ func (a *WindowsRetriever) GetPlatform() string {
func (a *WindowsRetriever) GetAppDirectories(ctx context.Context) []appDirectory {
return []appDirectory{
{
Path: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs",
Recursive: true,
Path: "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs",
Recursive: true,
RecursiveDepth: 2,
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions Wox/plugin/system/app/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type appInfo struct {
}

type appDirectory struct {
Path string
Recursive bool
Path string
Recursive bool
RecursiveDepth int
}

type Retriever interface {
Expand Down

0 comments on commit 1556fbb

Please sign in to comment.