package main import ( "context" "os" "path/filepath" "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"` } type BoolResponse struct { Data bool `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 BoolResponse) { hasBreakingChanges, err := addonService.UpdateAddon(name) res.Data = hasBreakingChanges if err != nil { res.Error = err.Error() } return res } func (a *App) GetGamePath() (res StringResponse) { res.Data = settings.GamePath return res } func (a *App) SetGamePath(path string) (res StringResponse) { settings.GamePath = path err := SaveSettings(*settings) if err != nil { res.Error = err.Error() } return res } func (a *App) IsGamePathValid() (res BoolResponse) { if settings.GamePath == "" { res.Data = false return res } // Check if the path exists and contains the Interface/AddOns directory addonPath := filepath.Join(settings.GamePath, "Interface", "AddOns") if _, err := os.Stat(addonPath); os.IsNotExist(err) { res.Data = false return res } res.Data = true return res } func (a *App) SelectDirectory() (res StringResponse) { path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{ Title: "Select World of Warcraft Directory", }) if err != nil { res.Error = err.Error() return } res.Data = path return } func (a *App) GetLocale() string { if settings.Locale == "" { return "en" } return settings.Locale } func (a *App) SetLocale(locale string) error { settings.Locale = locale return SaveSettings(*settings) }