Some checks failed
Security Scan / security (push) Failing after 24s
Rebuilt from scratch on current dev (post-fleet AX passes). Stub files: - application.go (expanded App with 12 managers, WebviewWindow satisfies Window) - application_options.go (Options, Mac/Win/Linux/iOS/Android, Server, TLS, Assets) - browser_manager.go, browser_window.go (~47 no-op methods) - clipboard.go, context_menu.go, dialog.go (full dialog builder API) - environment.go, events.go (EventManager with On/Off/Emit/Reset) - keybinding.go, menuitem.go (42 Role constants) - screen.go (Rect/Point/Size geometry), services.go (generic Service[T]) - webview_window_options.go (full platform types) - window.go (Window interface ~50 methods) Wails v3 submodule at internal/wails3/ pinned to alpha 74. All 16 gui packages build and test clean. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
2.6 KiB
Go
76 lines
2.6 KiB
Go
package application
|
|
|
|
import "context"
|
|
|
|
// Service wraps a bound type instance for registration with the application.
|
|
// svc := NewService(&MyService{})
|
|
type Service struct {
|
|
instance any
|
|
options ServiceOptions
|
|
}
|
|
|
|
// ServiceOptions provides optional configuration for a Service.
|
|
// opts := ServiceOptions{Name: "my-service", Route: "/api/my"}
|
|
type ServiceOptions struct {
|
|
// Name overrides the service name used in logging and debugging.
|
|
// Defaults to the value from ServiceName interface, or the type name.
|
|
Name string
|
|
|
|
// Route mounts the service on the internal asset server at this path
|
|
// when the instance implements http.Handler.
|
|
Route string
|
|
|
|
// MarshalError serialises errors returned by service methods to JSON.
|
|
// Return nil to fall back to the globally configured error handler.
|
|
MarshalError func(error) []byte
|
|
}
|
|
|
|
// DefaultServiceOptions is the default service options used by NewService.
|
|
var DefaultServiceOptions = ServiceOptions{}
|
|
|
|
// NewService wraps instance as a Service.
|
|
// svc := NewService(&Calculator{})
|
|
func NewService[T any](instance *T) Service {
|
|
return Service{instance: instance, options: DefaultServiceOptions}
|
|
}
|
|
|
|
// NewServiceWithOptions wraps instance as a Service with explicit options.
|
|
// svc := NewServiceWithOptions(&Calculator{}, ServiceOptions{Name: "calculator"})
|
|
func NewServiceWithOptions[T any](instance *T, options ServiceOptions) Service {
|
|
service := NewService(instance)
|
|
service.options = options
|
|
return service
|
|
}
|
|
|
|
// Instance returns the underlying pointer passed to NewService.
|
|
// raw := svc.Instance().(*Calculator)
|
|
func (s Service) Instance() any {
|
|
return s.instance
|
|
}
|
|
|
|
// Options returns the ServiceOptions for this service.
|
|
// opts := svc.Options()
|
|
func (s Service) Options() ServiceOptions {
|
|
return s.options
|
|
}
|
|
|
|
// ServiceName is an optional interface that service instances may implement
|
|
// to provide a human-readable name for logging and debugging.
|
|
// func (s *MyService) ServiceName() string { return "my-service" }
|
|
type ServiceName interface {
|
|
ServiceName() string
|
|
}
|
|
|
|
// ServiceStartup is an optional interface for services that need initialisation.
|
|
// Called in registration order during application startup.
|
|
// func (s *MyService) ServiceStartup(ctx context.Context, opts ServiceOptions) error { ... }
|
|
type ServiceStartup interface {
|
|
ServiceStartup(ctx context.Context, options ServiceOptions) error
|
|
}
|
|
|
|
// ServiceShutdown is an optional interface for services that need cleanup.
|
|
// Called in reverse registration order during application shutdown.
|
|
// func (s *MyService) ServiceShutdown() error { ... }
|
|
type ServiceShutdown interface {
|
|
ServiceShutdown() error
|
|
}
|