From d6ac226ed07f2ba9d9e26a5eef47e64dd748e4cb Mon Sep 17 00:00:00 2001 From: Wraient Date: Mon, 28 Oct 2024 14:16:07 +0530 Subject: [PATCH] Minor mistakes --- cmd/curd/main.go | 29 +++++++++++++++++------------ internal/curd.go | 2 +- internal/rofi.go | 2 +- internal/selection_menu.go | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cmd/curd/main.go b/cmd/curd/main.go index 22cf44d..85f53a7 100644 --- a/cmd/curd/main.go +++ b/cmd/curd/main.go @@ -99,18 +99,6 @@ func main() { } if *rofiSelection { - // Define a slice of file names to check and download - filesToCheck := []string{ - "selectanimepreview.rasi", - "selectanime.rasi", - "userinput.rasi", - } - - // Call the function to check and download files - if err := internal.CheckAndDownloadFiles(userCurdConfig.StoragePath, filesToCheck); err != nil { - internal.CurdOut(fmt.Sprintf("Error checking and downloading files: %v\n", err)) - internal.ExitCurd(err) - } userCurdConfig.RofiSelection = true } @@ -139,6 +127,23 @@ func main() { internal.ChangeToken(&userCurdConfig, &user) } + if userCurdConfig.RofiSelection { + // Define a slice of file names to check and download + filesToCheck := []string{ + "selectanimepreview.rasi", + "selectanime.rasi", + "userinput.rasi", + } + + // Call the function to check and download files + err := internal.CheckAndDownloadFiles(os.ExpandEnv(userCurdConfig.StoragePath), filesToCheck) + if err != nil { + internal.Log(fmt.Sprintf("Error checking and downloading files: %v\n", err), logFile) + internal.CurdOut(fmt.Sprintf("Error checking and downloading files: %v\n", err)) + internal.ExitCurd(err) + } + } + // Load animes in database databaseFile := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_history.txt") databaseAnimes := internal.LocalGetAllAnime(databaseFile) diff --git a/internal/curd.go b/internal/curd.go index 0fdfaf5..42d3435 100644 --- a/internal/curd.go +++ b/internal/curd.go @@ -600,7 +600,7 @@ func CheckAndDownloadFiles(storagePath string, filesToCheck []string) error { // Check each file for _, fileName := range filesToCheck { - filePath := filepath.Join(storagePath, fileName) + filePath := filepath.Join(os.ExpandEnv(storagePath), fileName) // Skip if file already exists if _, err := os.Stat(filePath); err == nil { diff --git a/internal/rofi.go b/internal/rofi.go index c3606d9..ffe2791 100644 --- a/internal/rofi.go +++ b/internal/rofi.go @@ -42,7 +42,7 @@ func GetUserInputFromRofi(message string) (string, error) { userCurdConfig.StoragePath = os.ExpandEnv("${HOME}/.local/share/curd") } // Create the Rofi command - cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(userCurdConfig.StoragePath, "userinput.rasi"), "-p", "Input", "-mesg", message) + cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "userinput.rasi"), "-p", "Input", "-mesg", message) // Set up pipes for output var out bytes.Buffer diff --git a/internal/selection_menu.go b/internal/selection_menu.go index 2f3cccf..3d469e9 100644 --- a/internal/selection_menu.go +++ b/internal/selection_menu.go @@ -207,7 +207,7 @@ func DynamicSelectPreview(options map[string]RofiSelectPreview, addnewoption boo rofiInput.WriteString("Quit\n") // Get the absolute path to the rasi config - configPath := filepath.Join(userCurdConfig.StoragePath, "selectanimepreview.rasi") + configPath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "selectanimepreview.rasi") // Create the command with explicit arguments args := []string{ @@ -353,7 +353,7 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e optionsString := strings.Join(optionsList, "\n") // Prepare the Rofi command - cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(userCurdConfig.StoragePath, "selectanime.rasi"), "-i", "-p", "Select an anime") + cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "selectanime.rasi"), "-i", "-p", "Select an anime") // Set up pipes for input and output cmd.Stdin = strings.NewReader(optionsString)