2024-10-24 13:31:01 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-24 17:05:47 -06:00
|
|
|
"bytes"
|
2024-10-24 13:31:01 -06:00
|
|
|
"context"
|
2024-10-24 15:49:14 -06:00
|
|
|
"encoding/json"
|
2024-10-24 13:31:01 -06:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2024-10-24 19:48:19 -06:00
|
|
|
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
2024-10-24 13:31:01 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// App struct
|
|
|
|
type App struct {
|
2024-10-24 17:05:47 -06:00
|
|
|
ctx context.Context
|
|
|
|
prism Prism
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type Modpack struct {
|
2024-10-24 15:49:14 -06:00
|
|
|
Name string
|
|
|
|
Nd string
|
|
|
|
Last_updated string
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() []string {
|
2024-10-24 17:05:47 -06:00
|
|
|
buff := new(bytes.Buffer)
|
2024-10-24 19:48:19 -06:00
|
|
|
err := HttpDownload("modpacks.json", buff, nil)
|
2024-10-24 15:49:14 -06:00
|
|
|
if err != nil {
|
2024-10-24 17:05:47 -06:00
|
|
|
fmt.Println(err)
|
2024-10-24 15:49:14 -06:00
|
|
|
}
|
2024-10-24 17:05:47 -06:00
|
|
|
body, err := io.ReadAll(buff)
|
2024-10-24 15:49:14 -06:00
|
|
|
var modpacks []Modpack
|
|
|
|
err = json.Unmarshal([]byte(body), &modpacks)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var names []string
|
|
|
|
for _, pack := range modpacks {
|
|
|
|
names = append(names, pack.Name)
|
|
|
|
}
|
|
|
|
return names
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
2024-10-24 15:46:17 -06:00
|
|
|
|
|
|
|
func (a *App) CheckPrerequisites() {
|
2024-10-24 19:48:19 -06:00
|
|
|
a.status("Checking Prism")
|
|
|
|
a.prism = Prism{ctx: a.ctx}
|
2024-10-24 17:05:47 -06:00
|
|
|
res := a.prism.CheckInstalled()
|
|
|
|
if res {
|
2024-10-24 19:48:19 -06:00
|
|
|
a.status("Prism OK")
|
2024-10-24 17:05:47 -06:00
|
|
|
} else {
|
2024-10-24 19:48:19 -06:00
|
|
|
a.status("Prism MISSING")
|
|
|
|
a.status("Installing Prism")
|
2024-10-24 17:05:47 -06:00
|
|
|
a.prism.Install()
|
2024-10-24 19:48:19 -06:00
|
|
|
a.status("Prism Installed")
|
2024-10-24 17:05:47 -06:00
|
|
|
}
|
2024-10-24 15:46:17 -06:00
|
|
|
}
|
2024-10-24 19:48:19 -06:00
|
|
|
|
|
|
|
func (a *App) status(status string) {
|
|
|
|
fmt.Printf("LOG: %s\n", status)
|
|
|
|
runtime.EventsEmit(a.ctx, "status", status)
|
|
|
|
}
|