Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Include all application path on default
Browse files Browse the repository at this point in the history
By default, all system apps, apps in `/Application` and in `~/Application` will be scanned.
  • Loading branch information
harryzcy committed Mar 28, 2021
1 parent 10a19e1 commit 670b00e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions internal/macapp/macapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ import (
"io/fs"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"

"howett.net/plist"
)

const (
applicationPath = "/Applications"
var (
applicationPath []string
)

func init() {
usr, _ := user.Current()
userApplication := filepath.Join(usr.HomeDir, "Applications")

applicationPath = []string{
"/System/Applications",
"/Applications",
userApplication,
}
}

type Application struct {
Name string
Path string
Expand Down Expand Up @@ -76,12 +88,15 @@ func GetAllApplications(dirs []string) ([]Application, error) {
)

if dirs == nil {
dirs = []string{applicationPath}
dirs = applicationPath
}

for _, dir := range dirs {
files, err := ioutil.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
continue
}
return nil, err
}

Expand Down

0 comments on commit 670b00e

Please sign in to comment.