From 8c0e3a896d444021fcaf991241f04edcc06927f0 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Wed, 10 Jul 2024 22:42:05 +0100 Subject: [PATCH] fix config lookups for windows make config.go sensitive to the windows environment. --- README-CONFIGS.md | 33 +++++++++++++++++++++++++++++++++ build.ps1 | 3 +++ config.go | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 README-CONFIGS.md diff --git a/README-CONFIGS.md b/README-CONFIGS.md new file mode 100644 index 0000000..3e6d9ca --- /dev/null +++ b/README-CONFIGS.md @@ -0,0 +1,33 @@ +# FOR WINDOWS USERS + +## MPV +MPV insists on opening a GUI (or "pseudo-gui" as they call it) window, whether you like it or not. +So, here is the best mpv.conf I could come up with, under those +circumstances: +```ini +[default] +terminal=yes +audio-display=no +video=no +force-window=no +window-minimized=yes +idle=yes +``` +The window will still be created, but at least, it will be minimized to the taskbar. + +You should put this file in: `%USERPROFILE%\AppData\Roaming\mpv.net\mpv.conf` + +## RADIOSTATIONS.INI +Make sure your `gostations.exe` is somewhere in your searchable %PATH%. Then, you should +only need to change the player.command option: +```ini +[DEFAULT] +radio_browser.api=all.api.radio-browser.info +player.command=mpvnet.exe +player.options=--no-video +menu_items.max=9999 +``` + +# FOR EVERYONE ELSE + +Continue as you are. The sane people don't need to do anything different. \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 41912bc..8f5a272 100644 --- a/build.ps1 +++ b/build.ps1 @@ -16,3 +16,6 @@ go mod tidy go build -o "$buildpath" -ldflags "-X main.version=$VERSION_STRING" & $buildpath -v + +Copy-Item $buildpath $HOME/.local/bin -Force + diff --git a/config.go b/config.go index ffef6d5..f491155 100644 --- a/config.go +++ b/config.go @@ -4,12 +4,13 @@ import ( "errors" "log" "os" + "runtime" "strconv" "github.com/alyu/configparser" ) -//str2int +// str2int func str2int(strnum string) int { i, err := strconv.Atoi(strnum) if err != nil { @@ -18,12 +19,21 @@ func str2int(strnum string) int { return i } -func configStat(configFile string) string{ +func configStat(configFile string) string { xdgConfigPath := os.Getenv("XDG_CONFIG_HOME") if xdgConfigPath == "" { - xdgConfigPath = os.Getenv("HOME")+"/.config" + if runtime.GOOS == "windows" { + xdgConfigPath = os.Getenv("USERPROFILE") + "\\.config" + } else { + xdgConfigPath = os.Getenv("HOME") + "/.config" + } + } + + if runtime.GOOS == "windows" { + configFile = xdgConfigPath + "\\gostations\\" + configFile + } else { + configFile = xdgConfigPath + "/gostations/" + configFile } - configFile = xdgConfigPath + "/gostations/" + configFile if _, err := os.Stat(configFile); errors.Is(err, os.ErrNotExist) { log.Printf("Your stations config file seems to be missing. A default will be generated.")