Commit 49488fa4ff
Unsigned
Layout: unified · split
cmd/curd/main.go +10 −2
| @@ -112,8 +112,16 @@ func main() { | ||
| 112 | 112 | internal.Log("Error reading token", logFile) |
| 113 | 113 | } |
| 114 | 114 | if user.Token == "" { |
| 115 | fmt.Println("No token found, please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") | |
| 116 | fmt.Scanln(&user.Token) | |
| 115 | if userCurdConfig.RofiSelection { | |
| 116 | user.Token, err = internal.GetTokenFromRofi() | |
| 117 | } else { | |
| 118 | fmt.Println("No token found, please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") | |
| 119 | fmt.Scanln(&user.Token) | |
| 120 | } | |
| 121 | if err != nil { | |
| 122 | internal.Log("Error getting user input: "+err.Error(), logFile) | |
| 123 | internal.ExitCurd(err) | |
| 124 | } | |
| 117 | 125 | internal.WriteTokenToFile(user.Token, filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token")) |
| 118 | 126 | } |
| 119 | 127 | |
internal/rofi.go added +31
| @@ -0,0 +1,31 @@ | ||
| 1 | package internal | |
| 2 | ||
| 3 | import ( | |
| 4 | "os/exec" | |
| 5 | ) | |
| 6 | ||
| 7 | func GetTokenFromRofi() (string, error) { | |
| 8 | // The URL to open | |
| 9 | url := "https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token" | |
| 10 | ||
| 11 | // Use rofi to display a prompt with the URL | |
| 12 | message := "Press enter to open the anilist token page in your browser" | |
| 13 | _, err := GetUserInputFromRofi(message) | |
| 14 | if err != nil { | |
| 15 | return "", err | |
| 16 | } | |
| 17 | ||
| 18 | // Open the URL in the default browser | |
| 19 | err = exec.Command("xdg-open", url).Start() | |
| 20 | if err != nil { | |
| 21 | return "", err | |
| 22 | } | |
| 23 | ||
| 24 | // Use rofi again to get the token input from the user | |
| 25 | token, err := GetUserInputFromRofi("Enter the token:") | |
| 26 | if err != nil { | |
| 27 | return "", err | |
| 28 | } | |
| 29 | ||
| 30 | return token, nil | |
| 31 | } | |