Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alfred 5 #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions util/build/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,45 @@ func (info *Info) findAlfredVersion() error {
if info.AlfredMajorVersion != 0 {
return nil
}
if util.PathExists(filepath.Join(info.dir, "Application Support/Alfred/prefs.json")) {
info.AlfredMajorVersion = 4

var (
// Alfred 4+ has a dedicated prefs.json file, but earlier versions store
// the setting in Alfred Preference's version-specific prefs file
prefsJSON = filepath.Join(info.dir, "Application Support/Alfred/prefs.json")
prefsPlist = filepath.Join(info.dir, "Preferences/com.runningwithcrayons.Alfred-Preferences-3.plist")
)

if util.PathExists(prefsJSON) {
var (
err error
prefs = struct {
Current string `json:"current"`
Versions map[string]string `json:"syncfolders"`
}{}
data []byte
)

if data, err = ioutil.ReadFile(prefsJSON); err != nil {
return err
}

if err = json.Unmarshal(data, &prefs); err != nil {
return err
}

var version, maxVersion int
for v := range prefs.Versions {
version, err = strconv.Atoi(v)
if err != nil && version > maxVersion {
maxVersion = version
}
}

info.AlfredMajorVersion = maxVersion

return nil
}
if util.PathExists(filepath.Join(info.dir, "Preferences/com.runningwithcrayons.Alfred-Preferences-3.plist")) {
if util.PathExists(prefsPlist) {
info.AlfredMajorVersion = 3
return nil
}
Expand Down Expand Up @@ -267,18 +301,8 @@ func findSyncFolder(v int, dir string) (string, error) {
if err = json.Unmarshal(data, &prefs); err != nil {
return "", err
}
if v == 0 {
return filepath.Dir(prefs.Current), nil
}

if path, ok := prefs.Versions[fmt.Sprintf("%d", v)]; ok {
p := expand(path)
if util.PathExists(p) {
return p, nil
}
return defaultSyncDirV4, nil
}
return "", fmt.Errorf("no syncfolder for version %d", v)
return filepath.Dir(prefs.Current), nil
}

// Look for Alfred 3 preferences plist
Expand Down