115 lines
3.2 KiB
Go
115 lines
3.2 KiB
Go
package desktop
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/Apale7/opencode-provider-switch/internal/app"
|
|
)
|
|
|
|
// Bindings is the thin desktop-callable facade shared by the fallback HTTP shell
|
|
// and the Wails bridge.
|
|
type Bindings struct {
|
|
service *app.Service
|
|
}
|
|
|
|
func NewBindings(service *app.Service) *Bindings {
|
|
return &Bindings{service: service}
|
|
}
|
|
|
|
func (b *Bindings) GetOverview(ctx context.Context) (app.Overview, error) {
|
|
return b.service.GetOverview(ctx)
|
|
}
|
|
|
|
func (b *Bindings) ListProviders(ctx context.Context) ([]app.ProviderView, error) {
|
|
return b.service.ListProviders(ctx)
|
|
}
|
|
|
|
func (b *Bindings) ListAliases(ctx context.Context) ([]app.AliasView, error) {
|
|
return b.service.ListAliases(ctx)
|
|
}
|
|
|
|
func (b *Bindings) RunDoctor(ctx context.Context) (app.DoctorReport, error) {
|
|
return b.service.RunDoctor(ctx)
|
|
}
|
|
|
|
func (b *Bindings) SyncOpenCode(ctx context.Context, in app.SyncInput) (app.SyncResult, error) {
|
|
return b.service.ApplyOpenCodeSync(ctx, in)
|
|
}
|
|
|
|
func (b *Bindings) PreviewOpenCodeSync(ctx context.Context, in app.SyncInput) (app.SyncPreview, error) {
|
|
return b.service.PreviewOpenCodeSync(ctx, in)
|
|
}
|
|
|
|
func (b *Bindings) GetProxyStatus(ctx context.Context) (app.ProxyStatusView, error) {
|
|
return b.service.GetProxyStatus(ctx)
|
|
}
|
|
|
|
func (b *Bindings) StartProxy(ctx context.Context) (app.ProxyStatusView, error) {
|
|
if err := b.service.StartProxy(ctx); err != nil {
|
|
return app.ProxyStatusView{}, err
|
|
}
|
|
return b.service.GetProxyStatus(ctx)
|
|
}
|
|
|
|
func (b *Bindings) StopProxy(ctx context.Context) (app.ProxyStatusView, error) {
|
|
if err := b.service.StopProxy(ctx); err != nil {
|
|
return app.ProxyStatusView{}, err
|
|
}
|
|
return b.service.GetProxyStatus(ctx)
|
|
}
|
|
|
|
func (b *Bindings) Overview() (app.Overview, error) {
|
|
return b.GetOverview(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) Providers() ([]app.ProviderView, error) {
|
|
return b.ListProviders(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) Aliases() ([]app.AliasView, error) {
|
|
return b.ListAliases(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) Doctor() (app.DoctorReport, error) {
|
|
return b.RunDoctor(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) ProxyStatus() (app.ProxyStatusView, error) {
|
|
return b.GetProxyStatus(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) StartProxyNow() (app.ProxyStatusView, error) {
|
|
return b.StartProxy(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) StopProxyNow() (app.ProxyStatusView, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
return b.StopProxy(ctx)
|
|
}
|
|
|
|
func (b *Bindings) DesktopPrefs() (app.DesktopPrefsView, error) {
|
|
return b.GetDesktopPrefs(context.Background())
|
|
}
|
|
|
|
func (b *Bindings) SavePrefs(in app.DesktopPrefsInput) (app.DesktopPrefsView, error) {
|
|
return b.SaveDesktopPrefs(context.Background(), in)
|
|
}
|
|
|
|
func (b *Bindings) PreviewSync(in app.SyncInput) (app.SyncPreview, error) {
|
|
return b.PreviewOpenCodeSync(context.Background(), in)
|
|
}
|
|
|
|
func (b *Bindings) ApplySync(in app.SyncInput) (app.SyncResult, error) {
|
|
return b.SyncOpenCode(context.Background(), in)
|
|
}
|
|
|
|
func (b *Bindings) GetDesktopPrefs(ctx context.Context) (app.DesktopPrefsView, error) {
|
|
return b.service.GetDesktopPrefs(ctx)
|
|
}
|
|
|
|
func (b *Bindings) SaveDesktopPrefs(ctx context.Context, in app.DesktopPrefsInput) (app.DesktopPrefsView, error) {
|
|
return b.service.SaveDesktopPrefs(ctx, in)
|
|
}
|