FCLauncher/fclauncher/app.go

85 lines
1.7 KiB
Go

package main
import (
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
Ctx context.Context
PrismLauncher Prism
Java JavaManager
Instance InstanceManager
Modpacks ModpackManager
}
// NewApp creates a new App application struct
func NewApp() *App {
a := &App{}
a.PrismLauncher = Prism{app: a}
a.Java = JavaManager{app: a}
a.Instance = InstanceManager{app: a}
a.Modpacks = ModpackManager{app: a}
return a
}
// 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) CheckPrerequisites() {
a.Status("Querrying Existing Instances")
a.Instance.SearchInstances()
a.Status("Pulling Modpacks")
a.Modpacks.QuerryModpacks()
a.Status("Checking Prism")
res := a.PrismLauncher.CheckInstalled()
if res {
a.Status("Prism OK")
} else {
a.Status("Prism MISSING")
a.Status("Installing Prism")
a.PrismLauncher.Install()
a.Status("Prism Installed")
}
a.Status("Checking Java 21")
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 (App) GetVersions() ([]string, error) {
manifest, err := GetVersionManifest()
if err != nil {
fmt.Printf("Manifest Error: %s\n", err)
return []string{}, err
}
versions := []string{}
for _, version := range manifest.Versions {
versions = append(versions, version.Id)
}
return versions, nil
}
func (a *App) Status(status string) {
fmt.Printf("LOG: %s\n", status)
runtime.EventsEmit(a.Ctx, "status", status)
}