Skip to content

Commit

Permalink
Fix: Better token installer for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraient committed Dec 30, 2024
1 parent 6575139 commit c0ef501
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,57 @@ func createDefaultConfig(path string) error {

func ChangeToken(config *CurdConfig, user *User) {
var err error
if config.RofiSelection {
tokenPath := filepath.Join(os.ExpandEnv(config.StoragePath), "token")

if runtime.GOOS == "windows" {

Check failure on line 143 in internal/config.go

View workflow job for this annotation

GitHub Actions / build

undefined: runtime
// Create a temporary file for the token
tempFile, err := os.CreateTemp("", "curd-token-*.txt")
if err != nil {
Log("Error creating temp file: "+err.Error(), logFile)
ExitCurd(err)
}
tempPath := tempFile.Name()
tempFile.Close()

// Write instructions to the temp file
instructions := "Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token\n" +
"Replace this text with your token and save the file.\n"
if err := os.WriteFile(tempPath, []byte(instructions), 0644); err != nil {
Log("Error writing instructions: "+err.Error(), logFile)
ExitCurd(err)
}

// Open notepad with the temp file
cmd := exec.Command("notepad.exe", tempPath)

Check failure on line 162 in internal/config.go

View workflow job for this annotation

GitHub Actions / build

undefined: exec
if err := cmd.Run(); err != nil {
Log("Error opening notepad: "+err.Error(), logFile)
ExitCurd(err)
}

// Read the token from the file
content, err := os.ReadFile(tempPath)
if err != nil {
Log("Error reading token: "+err.Error(), logFile)
ExitCurd(err)
}

// Clean up the temp file
os.Remove(tempPath)

// Extract token (remove instructions and whitespace)
user.Token = strings.TrimSpace(string(content))
} else if config.RofiSelection {
user.Token, err = GetTokenFromRofi()
} else {
fmt.Println("Please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token")
fmt.Scanln(&user.Token)
}

if err != nil {
Log("Error getting user input: "+err.Error(), logFile)
ExitCurd(err)
}
WriteTokenToFile(user.Token, filepath.Join(os.ExpandEnv(config.StoragePath), "token"))
WriteTokenToFile(user.Token, tokenPath)
}

// Load config file from disk into a map (key=value format)
Expand Down

0 comments on commit c0ef501

Please sign in to comment.