diff options
| author | Bobby <[email protected]> | 2024-09-08 18:34:58 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-09-08 18:34:58 -0400 |
| commit | e25611bde49fe2db28a006aca3ea49eece046c5f (patch) | |
| tree | dae68f8784010ff9002fe0e3c5d228879c15a25f /main.go | |
| parent | 61bc5b38044bc52442415f83390ba72ed3b27491 (diff) | |
| download | yato-main.tar.xz yato-main.zip | |
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 29 |
1 files changed, 5 insertions, 24 deletions
@@ -6,11 +6,9 @@ import ( "log" "net/http" "os" - "os/exec" - "runtime" "yato/config" + "yato/lib" "yato/screens" - "yato/utils" tea "github.com/charmbracelet/bubbletea" ) @@ -50,12 +48,12 @@ func StartApp() { func StartOAuthFlow() { var err error - codeVerifier, err = utils.GetNewCodeVerifier() + codeVerifier, err = lib.GetNewCodeVerifier() if err != nil { log.Fatalf("failed to generate code verifier: %s", err) } - url := utils.GetOAuthURL(codeVerifier) + url := lib.GetOAuthURL(codeVerifier) server := &http.Server{Addr: ":42069"} http.HandleFunc("/authenticate", handleOAuthCallback) @@ -66,7 +64,7 @@ func StartOAuthFlow() { } }() - if err := openBrowser(url); err != nil { + if err := lib.OpenBrowser(url); err != nil { log.Printf("failed to open browser: %v. Visit %s in your browser to authenticate.", err, url) } @@ -89,7 +87,7 @@ func handleOAuthCallback(w http.ResponseWriter, r *http.Request) { return } - malConfig, err := utils.ExchangeToken(code, codeVerifier) + malConfig, err := lib.ExchangeToken(code, codeVerifier) if err != nil { errorChan <- fmt.Errorf("failed to exchange token: %w", err) http.Error(w, "failed to exchange token", http.StatusInternalServerError) @@ -106,20 +104,3 @@ func handleOAuthCallback(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Authentication successful! You can now close this tab.")) authorizationChan <- struct{}{} } - -func openBrowser(url string) error { - var err error - - switch runtime.GOOS { - case "linux": - err = exec.Command("xdg-open", url).Start() - case "windows": - err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() - case "darwin": - err = exec.Command("open", url).Start() - default: - err = fmt.Errorf("unsupported platform") - } - - return err -} |
