2024-10-24 13:31:01 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-10-24 19:48:19 -06:00
|
|
|
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
2024-10-24 13:31:01 -06:00
|
|
|
)
|
|
|
|
|
2024-10-30 15:39:11 -06:00
|
|
|
|
|
|
|
const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d"
|
|
|
|
|
2024-10-24 13:31:01 -06:00
|
|
|
// App struct
|
|
|
|
type App struct {
|
2024-10-26 14:00:53 -06:00
|
|
|
Ctx context.Context
|
|
|
|
PrismLauncher Prism
|
|
|
|
Java JavaManager
|
|
|
|
Instance InstanceManager
|
|
|
|
Modpacks ModpackManager
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewApp creates a new App application struct
|
|
|
|
func NewApp() *App {
|
2024-10-26 14:00:53 -06:00
|
|
|
a := &App{}
|
|
|
|
a.PrismLauncher = Prism{app: a}
|
|
|
|
a.Java = JavaManager{app: a}
|
|
|
|
a.Instance = InstanceManager{app: a}
|
|
|
|
a.Modpacks = ModpackManager{app: a}
|
|
|
|
return a
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Ctx = ctx
|
2024-10-24 13:31:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Greet returns a greeting for the given name
|
|
|
|
|
2024-10-24 15:46:17 -06:00
|
|
|
|
|
|
|
func (a *App) CheckPrerequisites() {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Querrying Existing Instances")
|
|
|
|
a.Instance.SearchInstances()
|
|
|
|
a.Status("Pulling Modpacks")
|
|
|
|
a.Modpacks.QuerryModpacks()
|
|
|
|
a.Status("Checking Prism")
|
|
|
|
res := a.PrismLauncher.CheckInstalled()
|
2024-10-24 17:05:47 -06:00
|
|
|
if res {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Prism OK")
|
2024-10-24 17:05:47 -06:00
|
|
|
} else {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Prism MISSING")
|
|
|
|
a.Status("Installing Prism")
|
|
|
|
a.PrismLauncher.Install()
|
|
|
|
a.Status("Prism Installed")
|
2024-10-24 17:05:47 -06:00
|
|
|
}
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Checking Java 21")
|
|
|
|
res = a.Java.CheckJavaVer(21)
|
2024-10-25 20:46:06 -06:00
|
|
|
if res {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Java 21 OK")
|
2024-10-25 20:46:06 -06:00
|
|
|
} else {
|
2024-10-26 14:00:53 -06:00
|
|
|
a.Status("Java 21 MISSING")
|
|
|
|
a.Status("Installing Java 21")
|
|
|
|
a.Java.InstallJavaVer(21)
|
|
|
|
a.Status("Java 21 Installed")
|
2024-10-25 20:46:06 -06:00
|
|
|
}
|
2024-10-29 21:48:59 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-10-24 15:46:17 -06:00
|
|
|
}
|
2024-10-24 19:48:19 -06:00
|
|
|
|
2024-10-26 14:00:53 -06:00
|
|
|
func (a *App) Status(status string) {
|
2024-10-24 19:48:19 -06:00
|
|
|
fmt.Printf("LOG: %s\n", status)
|
2024-10-26 14:00:53 -06:00
|
|
|
runtime.EventsEmit(a.Ctx, "status", status)
|
2024-10-24 19:48:19 -06:00
|
|
|
}
|