Commit 72b93bbe58
Unsigned
Layout: unified · split
cmd/curd/main.go +9 −6
| @@ -29,14 +29,17 @@ func main() { | ||
| 29 | 29 | |
| 30 | 30 | internal.SetGlobalAnime(&anime) |
| 31 | 31 | |
| 32 | var homeDir string | |
| 33 | if runtime.GOOS == "windows" { | |
| 34 | homeDir = os.Getenv("USERPROFILE") | |
| 35 | } else { | |
| 36 | homeDir = os.Getenv("HOME") | |
| 32 | configDir, err := os.UserConfigDir() | |
| 33 | if err != nil { | |
| 34 | // Fallback if UserConfigDir fails | |
| 35 | if runtime.GOOS == "windows" { | |
| 36 | configDir = filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Roaming") | |
| 37 | } else { | |
| 38 | configDir = filepath.Join(os.Getenv("HOME"), ".config") | |
| 39 | } | |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | configFilePath := filepath.Join(homeDir, ".config", "curd", "curd.conf") | |
| 42 | configFilePath := filepath.Join(configDir, "curd", "curd.conf") | |
| 40 | 43 | |
| 41 | 44 | // load curd userCurdConfig |
| 42 | 45 | userCurdConfig, err := internal.LoadConfig(configFilePath) |
internal/anime_list.go +1 −6
| @@ -6,7 +6,6 @@ import ( | ||
| 6 | 6 | "fmt" |
| 7 | 7 | "io" |
| 8 | 8 | "net/http" |
| 9 | "os" | |
| 10 | 9 | "path/filepath" |
| 11 | 10 | "strings" |
| 12 | 11 | ) |
| @@ -94,11 +93,7 @@ func searchAllAnime(query, mode string) ([]SelectionOption, error) { | ||
| 94 | 93 | |
| 95 | 94 | func searchAnimeByMode(query, mode, preferredMode string) ([]SelectionOption, error) { |
| 96 | 95 | userCurdConfig := GetGlobalConfig() |
| 97 | if userCurdConfig == nil { | |
| 98 | logFile = os.ExpandEnv("$HOME/.local/share/curd/debug.log") | |
| 99 | } else { | |
| 100 | logFile = filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "debug.log") | |
| 101 | } | |
| 96 | logFile = filepath.Join(GetStoragePath(), "debug.log") | |
| 102 | 97 | const ( |
| 103 | 98 | agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" |
| 104 | 99 | allanimeRef = "https://allanime.to" |
internal/config.go +10
| @@ -63,6 +63,13 @@ type CurdConfig struct { | ||
| 63 | 63 | Provider string `config:"Provider"` |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | func GetStoragePath() string { | |
| 67 | if globalConfig != nil && globalConfig.StoragePath != "" { | |
| 68 | return os.ExpandEnv(globalConfig.StoragePath) | |
| 69 | } | |
| 70 | return filepath.Join(os.ExpandEnv("$HOME"), ".local", "share", "curd") | |
| 71 | } | |
| 72 | ||
| 66 | 73 | // Default configuration values as a map |
| 67 | 74 | func defaultConfigMap() map[string]string { |
| 68 | 75 | return map[string]string{ |
| @@ -124,9 +131,12 @@ func parseStringArray(value string) []string { | ||
| 124 | 131 | return result |
| 125 | 132 | } |
| 126 | 133 | |
| 134 | var GlobalConfigPath string | |
| 135 | ||
| 127 | 136 | // LoadConfig reads or creates the config file, adds missing fields, and returns the populated CurdConfig struct |
| 128 | 137 | func LoadConfig(configPath string) (CurdConfig, error) { |
| 129 | 138 | configPath = os.ExpandEnv(configPath) // Substitute environment variables like $HOME |
| 139 | GlobalConfigPath = configPath | |
| 130 | 140 | |
| 131 | 141 | // Check if config file exists |
| 132 | 142 | if _, err := os.Stat(configPath); os.IsNotExist(err) { |
internal/curd.go +1 −1
| @@ -2109,7 +2109,7 @@ func ChangeProvider(userCurdConfig *CurdConfig) { | ||
| 2109 | 2109 | CurrentProvider = nil // reset the provider instance |
| 2110 | 2110 | |
| 2111 | 2111 | // Save to config file |
| 2112 | configPath := filepath.Join(os.ExpandEnv("$HOME"), ".config", "curd", "curd.conf") | |
| 2112 | configPath := GlobalConfigPath | |
| 2113 | 2113 | configMap, err := LoadConfigFromFile(configPath) |
| 2114 | 2114 | if err == nil { |
| 2115 | 2115 | configMap["Provider"] = selected.Key |
internal/provider_animepahe.go +5 −1
| @@ -19,15 +19,19 @@ import ( | ||
| 19 | 19 | ) |
| 20 | 20 | |
| 21 | 21 | var animepaheCookiesBypassed bool |
| 22 | var cookieFilePath = filepath.Join(os.ExpandEnv("$HOME"), ".local", "share", "curd", "animepahe_cookies.json") | |
| 22 | func getCookieFilePath() string { | |
| 23 | return filepath.Join(GetStoragePath(), "animepahe_cookies.json") | |
| 24 | } | |
| 23 | 25 | |
| 24 | 26 | func saveCookies(cookies []*http.Cookie) { |
| 27 | cookieFilePath := getCookieFilePath() | |
| 25 | 28 | os.MkdirAll(filepath.Dir(cookieFilePath), 0755) |
| 26 | 29 | b, _ := json.Marshal(cookies) |
| 27 | 30 | os.WriteFile(cookieFilePath, b, 0644) |
| 28 | 31 | } |
| 29 | 32 | |
| 30 | 33 | func loadCookies() []*http.Cookie { |
| 34 | cookieFilePath := getCookieFilePath() | |
| 31 | 35 | b, err := os.ReadFile(cookieFilePath) |
| 32 | 36 | if err != nil { |
| 33 | 37 | return nil |
internal/rofi.go +1 −6
| @@ -3,7 +3,6 @@ package internal | ||
| 3 | 3 | import ( |
| 4 | 4 | "bytes" |
| 5 | 5 | "fmt" |
| 6 | "os" | |
| 7 | 6 | "os/exec" |
| 8 | 7 | "path/filepath" |
| 9 | 8 | "strings" |
| @@ -37,12 +36,8 @@ func GetTokenFromRofi() (string, error) { | ||
| 37 | 36 | |
| 38 | 37 | // GetUserInputFromRofi prompts the user for input using Rofi with a custom message |
| 39 | 38 | func GetUserInputFromRofi(message string) (string, error) { |
| 40 | userCurdConfig := GetGlobalConfig() | |
| 41 | if userCurdConfig.StoragePath == "" { | |
| 42 | userCurdConfig.StoragePath = os.ExpandEnv("${HOME}/.local/share/curd") | |
| 43 | } | |
| 44 | 39 | // Create the Rofi command |
| 45 | cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "userinput.rasi"), "-p", "Input", "-mesg", message) | |
| 40 | cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(GetStoragePath(), "userinput.rasi"), "-p", "Input", "-mesg", message) | |
| 46 | 41 | |
| 47 | 42 | // Set up pipes for output |
| 48 | 43 | var out bytes.Buffer |
internal/selection_menu.go +3 −11
| @@ -382,10 +382,7 @@ func DynamicSelectPreview(options map[string]RofiSelectPreview, addnewoption boo | ||
| 382 | 382 | func DynamicSelectPreviewWithRefresh(options map[string]RofiSelectPreview, addnewoption bool, refreshConfig *PreviewSelectionRefreshConfig) (SelectionOption, error) { |
| 383 | 383 | go preDownloadImages(options, 14) |
| 384 | 384 | |
| 385 | userCurdConfig := GetGlobalConfig() | |
| 386 | if userCurdConfig.StoragePath == "" { | |
| 387 | userCurdConfig.StoragePath = os.ExpandEnv("${HOME}/.local/share/curd") | |
| 388 | } | |
| 385 | // Removed boilerplate check | |
| 389 | 386 | |
| 390 | 387 | currentOptions := options |
| 391 | 388 | |
| @@ -409,7 +406,7 @@ func DynamicSelectPreviewWithRefresh(options map[string]RofiSelectPreview, addne | ||
| 409 | 406 | rofiInput.WriteString("Back\n") |
| 410 | 407 | rofiInput.WriteString("Quit\n") |
| 411 | 408 | |
| 412 | configPath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "selectanimepreview.rasi") | |
| 409 | configPath := filepath.Join(GetStoragePath(), "selectanimepreview.rasi") | |
| 413 | 410 | cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-show-icons", "-p", "Select Anime", "-i", "-no-custom") |
| 414 | 411 | cmd.Stdin = strings.NewReader(rofiInput.String()) |
| 415 | 412 | var stdout, stderr bytes.Buffer |
| @@ -561,16 +558,11 @@ func RofiSelect(options []SelectionOption, isHomeMenu bool) (SelectionOption, er | ||
| 561 | 558 | } |
| 562 | 559 | |
| 563 | 560 | func RofiSelectWithRefresh(options []SelectionOption, isHomeMenu bool, refreshConfig *SelectionRefreshConfig) (SelectionOption, error) { |
| 564 | userCurdConfig := GetGlobalConfig() | |
| 565 | if userCurdConfig.StoragePath == "" { | |
| 566 | userCurdConfig.StoragePath = os.ExpandEnv("${HOME}/.local/share/curd") | |
| 567 | } | |
| 568 | ||
| 569 | 561 | currentOptions := options |
| 570 | 562 | |
| 571 | 563 | for { |
| 572 | 564 | optionsString := buildRofiOptionsString(currentOptions, isHomeMenu) |
| 573 | configPath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "selectanime.rasi") | |
| 565 | configPath := filepath.Join(GetStoragePath(), "selectanime.rasi") | |
| 574 | 566 | cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-i", "-p", "Select") |
| 575 | 567 | cmd.Stdin = strings.NewReader(optionsString) |
| 576 | 568 | var stdout, stderr bytes.Buffer |