From 454b55dd17ee9949f4e98d2f9eb206a78525ee64 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Mon, 20 Mar 2023 08:37:28 -0700 Subject: [PATCH 1/2] Use 'current' path for syncfolder --- util/build/info.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/util/build/info.go b/util/build/info.go index d8e41d2..f6cc148 100644 --- a/util/build/info.go +++ b/util/build/info.go @@ -267,18 +267,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 From ab5d9170264a2ccf1356815e5111ac25289f7ca4 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Mon, 20 Mar 2023 08:37:52 -0700 Subject: [PATCH 2/2] Get max version from preferences --- util/build/info.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/util/build/info.go b/util/build/info.go index f6cc148..8436232 100644 --- a/util/build/info.go +++ b/util/build/info.go @@ -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 }