Files
Yggdrasil/app.go

81 lines
1.6 KiB
Go

package main
import (
"context"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// 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
}
func (a *App) Close() {
runtime.Quit(a.ctx)
}
type AddonResponse struct {
Data Addon `json:"data"`
Error string `json:"error,omitempty"`
}
type AddonsResponse struct {
Data map[string]Addon `json:"data"`
Error string `json:"error,omitempty"`
}
type StringResponse struct {
Data string `json:"data"`
Error string `json:"error,omitempty"`
}
func (a *App) GetAddons() (res AddonsResponse) {
res.Data = addonService.Addons
return res
}
func (a *App) GetAddon(name string) (res AddonResponse) {
addon, err := addonService.GetAddon(name)
res.Data = addon
if err != nil {
res.Error = err.Error()
}
return res
}
func (a *App) GetAddonRemoteVersion(name string) (res StringResponse) {
version, err := addonService.GetRemoteVersion(name)
res.Data = version
if err != nil {
res.Error = err.Error()
}
return res
}
func (a *App) GetAddonLocalVersion(name string) (res StringResponse) {
version, err := addonService.GetLocalVersion(name)
res.Data = version
if err != nil {
res.Error = err.Error()
}
return res
}
func (a *App) UpdateAddon(name string) (res AddonResponse) {
addon, err := addonService.UpdateAddon(name)
res.Data = addon
if err != nil {
res.Error = err.Error()
}
return res
}