open browser for auth
This commit is contained in:
parent
d4f9711699
commit
69791e5188
@ -5,10 +5,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d"
|
||||
@ -40,6 +43,25 @@ func (a *App) startup(ctx context.Context) {
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
|
||||
func openbrowser(url string) {
|
||||
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")
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (a *App) CheckPrerequisites() {
|
||||
a.Status("Querrying Existing Instances")
|
||||
a.Instance.SearchInstances()
|
||||
@ -91,5 +113,5 @@ func (App) GetVersions() ([]string, error) {
|
||||
|
||||
func (a *App) Status(status string) {
|
||||
fmt.Printf("LOG: %s\n", status)
|
||||
runtime.EventsEmit(a.Ctx, "status", status)
|
||||
wruntime.EventsEmit(a.Ctx, "status", status)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ type McProfile struct {
|
||||
type devcodeResp struct {
|
||||
User_code string
|
||||
Device_code string
|
||||
Verification_url string
|
||||
Verification_uri string
|
||||
Expires_in string
|
||||
Interval int
|
||||
Message string
|
||||
@ -114,6 +114,8 @@ func AuthCode(a App) (authenticationResp, error) {
|
||||
codeResp := devcodeResp{}
|
||||
json.Unmarshal(data, &codeResp)
|
||||
//display message
|
||||
fmt.Printf("resp: %s\n", data)
|
||||
openbrowser(codeResp.Verification_uri)
|
||||
wruntime.MessageDialog(a.Ctx, wruntime.MessageDialogOptions{Type: wruntime.InfoDialog, Title: "Authentication", Message: codeResp.Message})
|
||||
ticker := time.NewTicker(time.Second * time.Duration(codeResp.Interval))
|
||||
for range ticker.C {
|
||||
|
Loading…
Reference in New Issue
Block a user