generated from dave/wails-template
79 lines
1.5 KiB
Go
79 lines
1.5 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() AddonsResponse {
|
|
return AddonsResponse{
|
|
Data: addonService.Addons,
|
|
Error: "",
|
|
}
|
|
}
|
|
|
|
func (a *App) GetAddon(name string) AddonResponse {
|
|
addon, err := addonService.GetAddon(name)
|
|
return AddonResponse{
|
|
Data: addon,
|
|
Error: err.Error(),
|
|
}
|
|
}
|
|
|
|
func (a *App) GetAddonRemoteVersion(name string) StringResponse {
|
|
version, err := addonService.GetRemoteVersion(name)
|
|
return StringResponse{
|
|
Data: version,
|
|
Error: err.Error(),
|
|
}
|
|
}
|
|
|
|
func (a *App) GetAddonLocalVersion(name string) StringResponse {
|
|
version, err := addonService.GetLocalVersion(name)
|
|
return StringResponse{
|
|
Data: version,
|
|
Error: err.Error(),
|
|
}
|
|
}
|
|
|
|
func (a *App) UpdateAddon(name string) AddonResponse {
|
|
addon, err := addonService.UpdateAddon(name)
|
|
return AddonResponse{
|
|
Data: addon,
|
|
Error: err.Error(),
|
|
}
|
|
}
|