Use $HOME/Downloads as default download directory

TODO: Get the default directory properly with XDG
This commit is contained in:
Tulir Asokan 2020-04-08 15:49:42 +03:00
parent a6f6fb3ef2
commit 79b61b86c9
3 changed files with 16 additions and 6 deletions

View File

@ -78,16 +78,15 @@ type Config struct {
} }
// NewConfig creates a config that loads data from the given directory. // NewConfig creates a config that loads data from the given directory.
func NewConfig(configDir, cacheDir string) *Config { func NewConfig(configDir, cacheDir, downloadDir string) *Config {
home, _ := os.UserHomeDir()
return &Config{ return &Config{
Dir: configDir, Dir: configDir,
CacheDir: cacheDir, CacheDir: cacheDir,
DownloadDir: downloadDir,
HistoryPath: filepath.Join(cacheDir, "history.db"), HistoryPath: filepath.Join(cacheDir, "history.db"),
RoomListPath: filepath.Join(cacheDir, "rooms.gob.gz"), RoomListPath: filepath.Join(cacheDir, "rooms.gob.gz"),
StateDir: filepath.Join(cacheDir, "state"), StateDir: filepath.Join(cacheDir, "state"),
MediaDir: filepath.Join(cacheDir, "media"), MediaDir: filepath.Join(cacheDir, "media"),
DownloadDir: home,
RoomCacheSize: 32, RoomCacheSize: 32,
RoomCacheAge: 1 * 60, RoomCacheAge: 1 * 60,

View File

@ -38,12 +38,12 @@ type Gomuks struct {
// NewGomuks creates a new Gomuks instance with everything initialized, // NewGomuks creates a new Gomuks instance with everything initialized,
// but does not start it. // 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{ gmx := &Gomuks{
stop: make(chan bool, 1), stop: make(chan bool, 1),
} }
gmx.config = config.NewConfig(configDir, cacheDir) gmx.config = config.NewConfig(configDir, cacheDir, downloadDir)
gmx.ui = uiProvider(gmx) gmx.ui = uiProvider(gmx)
gmx.matrix = matrix.NewContainer(gmx) gmx.matrix = matrix.NewContainer(gmx)

13
main.go
View File

@ -58,8 +58,14 @@ func main() {
fmt.Fprintln(os.Stderr, "Failed to get cache directory:", err) fmt.Fprintln(os.Stderr, "Failed to get cache directory:", err)
os.Exit(3) 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() gmx.Start()
// We use os.Exit() everywhere, so exiting by returning from Start() shouldn't happen. // 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 return
} }
func UserDownloadDir() (dir string, err error) {
dir = os.Getenv("HOME")
return filepath.Join(dir, "Downloads"), nil
}
func UserConfigDir() (dir string, err error) { func UserConfigDir() (dir string, err error) {
dir = os.Getenv("GOMUKS_CONFIG_HOME") dir = os.Getenv("GOMUKS_CONFIG_HOME")
if dir != "" { if dir != "" {