FCLauncher/fclauncher/app.go

71 lines
1.3 KiB
Go

package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
)
// App struct
type App struct {
ctx context.Context
prism Prism
}
type Modpack struct {
Name string
Nd 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() []string {
buff := new(bytes.Buffer)
err := HttpDownload("modpacks.json", buff)
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
}
var names []string
for _, pack := range modpacks {
names = append(names, pack.Name)
}
return names
}
func (a *App) CheckPrerequisites() {
a.prism = Prism{}
res := a.prism.CheckInstalled()
fmt.Printf("Checking if prism is installed: ")
if res {
fmt.Println("Yes")
} else {
fmt.Println("No")
fmt.Println("Installing Prism")
a.prism.Install()
}
}