92 lines
1.8 KiB
Go
92 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
prism Prism
|
|
java Java
|
|
}
|
|
|
|
type Modpack struct {
|
|
Name string
|
|
Id string
|
|
Last_updated string
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
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)
|
|
}
|
|
|
|
func (a *App) GetModpacks() []Modpack {
|
|
buff := new(bytes.Buffer)
|
|
err := HttpDownload("modpacks.json", buff, nil)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
body, err := io.ReadAll(buff)
|
|
var modpacks []Modpack
|
|
err = json.Unmarshal([]byte(body), &modpacks)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
return nil
|
|
}
|
|
return modpacks
|
|
}
|
|
|
|
func (a *App) CheckPrerequisites() {
|
|
a.status("Checking Prism")
|
|
a.prism = Prism{ctx: a.ctx}
|
|
res := a.prism.CheckInstalled()
|
|
if res {
|
|
a.status("Prism OK")
|
|
} else {
|
|
a.status("Prism MISSING")
|
|
a.status("Installing Prism")
|
|
a.prism.Install()
|
|
a.status("Prism Installed")
|
|
}
|
|
a.status("Checking Java 21")
|
|
a.java = Java{ctx: a.ctx}
|
|
res = a.java.CheckJavaVer(21)
|
|
if res {
|
|
a.status("Java 21 OK")
|
|
} else {
|
|
a.status("Java 21 MISSING")
|
|
a.status("Installing Java 21")
|
|
a.java.InstallJavaVer(21)
|
|
a.status("Java 21 Installed")
|
|
}
|
|
}
|
|
|
|
func (a *App) InstallModpack(pack Modpack) {
|
|
a.status(fmt.Sprintf("Installing %s\n", pack.Name))
|
|
a.prism.InstallModpack(pack)
|
|
}
|
|
|
|
func (a *App) status(status string) {
|
|
fmt.Printf("LOG: %s\n", status)
|
|
runtime.EventsEmit(a.ctx, "status", status)
|
|
}
|