diff --git a/config/config.go b/config/config.go index 3507833..e62a8bd 100644 --- a/config/config.go +++ b/config/config.go @@ -78,16 +78,15 @@ type Config struct { } // NewConfig creates a config that loads data from the given directory. -func NewConfig(configDir, cacheDir string) *Config { - home, _ := os.UserHomeDir() +func NewConfig(configDir, cacheDir, downloadDir string) *Config { return &Config{ Dir: configDir, CacheDir: cacheDir, + DownloadDir: downloadDir, HistoryPath: filepath.Join(cacheDir, "history.db"), RoomListPath: filepath.Join(cacheDir, "rooms.gob.gz"), StateDir: filepath.Join(cacheDir, "state"), MediaDir: filepath.Join(cacheDir, "media"), - DownloadDir: home, RoomCacheSize: 32, RoomCacheAge: 1 * 60, diff --git a/gomuks.go b/gomuks.go index 1a8cec1..2bc4533 100644 --- a/gomuks.go +++ b/gomuks.go @@ -38,12 +38,12 @@ type Gomuks struct { // NewGomuks creates a new Gomuks instance with everything initialized, // but does not start it. -func NewGomuks(uiProvider ifc.UIProvider, configDir, cacheDir string) *Gomuks { +func NewGomuks(uiProvider ifc.UIProvider, configDir, cacheDir, downloadDir string) *Gomuks { gmx := &Gomuks{ stop: make(chan bool, 1), } - gmx.config = config.NewConfig(configDir, cacheDir) + gmx.config = config.NewConfig(configDir, cacheDir, downloadDir) gmx.ui = uiProvider(gmx) gmx.matrix = matrix.NewContainer(gmx) diff --git a/main.go b/main.go index 43f4d2b..e16aa48 100644 --- a/main.go +++ b/main.go @@ -58,8 +58,14 @@ func main() { fmt.Fprintln(os.Stderr, "Failed to get cache directory:", err) os.Exit(3) } + downloadDir, err := UserDownloadDir() + if err != nil { + fmt.Fprintln(os.Stderr, "Failed to get download directory:", err) + os.Exit(3) + } - gmx := NewGomuks(MainUIProvider, configDir, cacheDir) + + gmx := NewGomuks(MainUIProvider, configDir, cacheDir, downloadDir) gmx.Start() // We use os.Exit() everywhere, so exiting by returning from Start() shouldn't happen. @@ -77,6 +83,11 @@ func UserCacheDir() (dir string, err error) { return } +func UserDownloadDir() (dir string, err error) { + dir = os.Getenv("HOME") + return filepath.Join(dir, "Downloads"), nil +} + func UserConfigDir() (dir string, err error) { dir = os.Getenv("GOMUKS_CONFIG_HOME") if dir != "" {