Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 86 additions & 6 deletions WU-Go-ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ package main

import (
"context"
"fmt"
"path/filepath"
"os"

"WU-Go-ui/internal/auth"
"WU-Go-ui/internal/devcenter"
"WU-Go-ui/internal/drivermeta"
"WU-Go-ui/internal/shippinglabel"
"WU-Go-ui/internal/support"
)

// App struct
type App struct {
ctx context.Context
ctx context.Context
httpClient *devcenter.Client
}

// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
return &App{
httpClient: devcenter.NewClient("https://manage.devcenter.microsoft.com/v2.0/my/hardware"),
}
}

// startup is called when the app starts. The context is saved
Expand All @@ -21,7 +31,77 @@ func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
// Config Methods

func (a *App) LoadConfig() (*auth.Credential, error) {
path := a.getCredentialPath()
return auth.LoadCredential(path), nil
}

func (a *App) SaveConfig(c auth.Credential) error {
path := a.getCredentialPath()
auth.SaveCredential(path, &c)
return nil
}

func (a *App) getCredentialPath() string {
// Attempt to store in same dir as executable, fallback to local
exe, err := os.Executable()
if err != nil {
return "credential.json"
}
return filepath.Join(filepath.Dir(exe), "credential.json")
}

// Auth Methods

func (a *App) AcquireToken(tenantID, clientID, clientSecret string) (string, error) {
return auth.AcquireToken(a.ctx, a.httpClient.HTTP, tenantID, clientID, clientSecret)
}

// Submission Methods

func (a *App) GetSubmission(token, productID, submissionID string) (map[string]any, error) {
if support.IsBlank(productID) || support.IsBlank(submissionID) {
return nil, support.NewAPIError("Product ID and Submission ID are required")
}
return devcenter.GetSubmission(a.ctx, a.httpClient, token, productID, submissionID)
}

// Metadata Methods

func (a *App) AnalyzeMetadata(token string, submission map[string]any) (*drivermeta.ParseResult, error) {
url, err := devcenter.FindDriverMetadataURL(submission)
if err != nil {
return nil, err
}

metaRoot, err := devcenter.DownloadDriverMetadata(a.ctx, a.httpClient, token, url)
if err != nil {
return nil, err
}

return drivermeta.Parse(metaRoot)
}

// Label Methods

func (a *App) CreateShippingLabel(
token, productID, submissionID string,
options shippinglabel.LabelOptions,
name string,
targets []drivermeta.HardwareTarget,
chids []string,
) (map[string]any, error) {

if support.IsBlank(name) {
return nil, support.NewAPIError("Shipping label name is required")
}

payload, err := shippinglabel.BuildPayload(options, name, targets, chids)
if err != nil {
return nil, err
}

return devcenter.CreateShippingLabel(a.ctx, a.httpClient, token, productID, submissionID, payload)
}
3 changes: 1 addition & 2 deletions WU-Go-ui/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>WU-Go-ui</title>
<title>WU Shipping Tool</title>
</head>
<body>
<div id="root"></div>
<script src="./src/main.tsx" type="module"></script>
</body>
</html>

Loading