package main import ( "context" "sgg-ai-skill-manager/internal/domain" "sgg-ai-skill-manager/internal/service" ) type App struct { ctx context.Context service *service.Service initErr error } func NewApp() *App { svc, err := service.NewDefault() return &App{service: svc, initErr: err} } func (a *App) startup(ctx context.Context) { a.ctx = ctx if a.service != nil { a.service.StartAutoUpdate(ctx) } } func (a *App) LoadConfig() (domain.Config, error) { if err := a.ready(); err != nil { return domain.Config{}, err } return a.service.LoadConfig() } func (a *App) SaveConfig(req domain.SaveConfigRequest) error { if err := a.ready(); err != nil { return err } return a.service.SaveConfig(a.context(), req) } func (a *App) TestConnection(req domain.SaveConfigRequest) (domain.TestConnectionResult, error) { if err := a.ready(); err != nil { return domain.TestConnectionResult{}, err } return a.service.TestConnection(a.context(), req) } func (a *App) ListRemoteSkills() ([]domain.RemoteSkill, error) { if err := a.ready(); err != nil { return nil, err } return a.service.ListRemoteSkills(a.context()) } func (a *App) ListLocalSkills() ([]domain.SkillState, error) { if err := a.ready(); err != nil { return nil, err } return a.service.ListLocalSkills(a.context()) } func (a *App) DownloadSkill(repo domain.RemoteSkill) (domain.SkillState, error) { if err := a.ready(); err != nil { return domain.SkillState{}, err } return a.service.DownloadSkill(a.context(), repo) } func (a *App) UpdateSkill(org, repo string) (domain.SkillState, error) { if err := a.ready(); err != nil { return domain.SkillState{}, err } return a.service.UpdateSkill(a.context(), org, repo) } func (a *App) InstallSkill(org, repo, targetID string) (domain.SkillState, error) { if err := a.ready(); err != nil { return domain.SkillState{}, err } return a.service.InstallSkill(a.context(), org, repo, targetID) } func (a *App) UninstallSkill(org, repo, targetID string) (domain.SkillState, error) { if err := a.ready(); err != nil { return domain.SkillState{}, err } return a.service.UninstallSkill(a.context(), org, repo, targetID) } func (a *App) DeleteSkill(org, repo string) error { if err := a.ready(); err != nil { return err } return a.service.DeleteSkill(a.context(), org, repo) } func (a *App) OpenInVSCode(org, repo string) error { if err := a.ready(); err != nil { return err } return a.service.OpenInVSCode(a.context(), org, repo) } func (a *App) OpenFolder(org, repo string) error { if err := a.ready(); err != nil { return err } return a.service.OpenFolder(a.context(), org, repo) } func (a *App) RunAutoUpdate() error { if err := a.ready(); err != nil { return err } return a.service.RunAutoUpdate(a.context()) } func (a *App) ready() error { return a.initErr } func (a *App) context() context.Context { if a.ctx == nil { return context.Background() } return a.ctx }