-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing rofi functions (almost complete)
Added missing rofi functions (almost complete)
- Loading branch information
Showing
4 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package internal | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func GetTokenFromRofi() (string, error) { | ||
// The URL to open | ||
url := "https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token" | ||
|
||
// Use rofi to display a prompt with the URL | ||
message := "Press enter to open the anilist token page in your browser" | ||
_, err := GetUserInputFromRofi(message) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Open the URL in the default browser | ||
err = exec.Command("xdg-open", url).Start() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Use rofi again to get the token input from the user | ||
token, err := GetUserInputFromRofi("Enter the token:") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return token, nil | ||
} | ||
|
||
// GetUserInputFromRofi prompts the user for input using Rofi with a custom message | ||
func GetUserInputFromRofi(message string) (string, error) { | ||
// Create the Rofi command | ||
cmd := exec.Command("rofi", "-dmenu", "-p", "Input", "-mesg", message) | ||
|
||
// Set up pipes for output | ||
var out bytes.Buffer | ||
cmd.Stdout = &out | ||
|
||
// Run the command | ||
err := cmd.Run() | ||
if err != nil { | ||
return "", fmt.Errorf("failed to run Rofi: %w", err) | ||
} | ||
|
||
// Get the entered input | ||
userInput := strings.TrimSpace(out.String()) | ||
|
||
return userInput, nil | ||
} |