Skip to content

Commit e5791b7

Browse files
committed
Fix issue for broken homedir
1 parent 8ee99ff commit e5791b7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package main
22

33
import (
44
"encoding/json"
5+
"github.com/mitchellh/go-homedir"
56
"github.com/spf13/viper"
67
"os"
7-
"os/user"
88
"path/filepath"
99
)
1010

1111
type config struct {
1212
AccessToken string `json:"accessToken"`
13+
ID string `json:"id"`
1314
}
1415

15-
var C config
16+
var marshaledConfig config
1617

1718
func getDefaultConfigPath() string {
18-
currentUser, _ := user.Current()
19-
return filepath.Join(currentUser.HomeDir, "Library/Application Support/Alfred 2/Workflow Data/", bundleId)
19+
homeDir, _ := homedir.Dir()
20+
return filepath.Join(homeDir, "Library/Application Support/Alfred 2/Workflow Data/", bundleID)
2021
}
2122

2223
func loadConfig() error {
@@ -33,9 +34,9 @@ func loadConfig() error {
3334

3435
func saveConfig() error {
3536
configPath := getDefaultConfigPath()
36-
viper.Marshal(&C)
37+
viper.Unmarshal(&marshaledConfig)
3738

38-
buf, err := json.MarshalIndent(C, "", " ")
39+
buf, err := json.MarshalIndent(marshaledConfig, "", " ")
3940
if err != nil {
4041
return err
4142
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
const (
12-
bundleId = "co.randompaper.alfred-qiita-workflow"
12+
bundleID = "co.randompaper.alfred-qiita-workflow"
1313
version = "2.0.0"
1414
)
1515

0 commit comments

Comments
 (0)