FCLauncher/fclauncher/app.go

71 lines
1.3 KiB
Go
Raw Normal View History

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"
)
// 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)
err := HttpDownload("modpacks.json", buff)
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 17:05:47 -06:00
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()
}
2024-10-24 15:46:17 -06:00
}