diff --git a/.gitignore b/.gitignore index 404a2aa4..f36a48ff 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ coverage.html /coverage.txt bin/ tasks +/core diff --git a/pkg/framework/core/core.go b/pkg/framework/core/core.go index 27deb9e6..29395fb2 100644 --- a/pkg/framework/core/core.go +++ b/pkg/framework/core/core.go @@ -1,4 +1,4 @@ -package framework +package core import ( "context" @@ -150,7 +150,7 @@ func (c *Core) ServiceStartup(ctx context.Context, options any) error { } // ServiceShutdown is the entry point for the Core service's shutdown lifecycle. -// It is called by Wails when the application shuts down. +// It is called by the GUI runtime when the application shuts down. func (c *Core) ServiceShutdown(ctx context.Context) error { var agg error if err := c.ACTION(ActionServiceShutdown{}); err != nil { @@ -262,14 +262,21 @@ func MustServiceFor[T any](c *Core, name string) T { } // App returns the global application instance. -// It panics if the Core has not been initialized. +// It panics if the Core has not been initialized via SetInstance. +// This is typically used by GUI runtimes that need global access. func App() any { if instance == nil { - panic("framework.App() called before framework.Setup() was successfully initialized") + panic("core.App() called before core.SetInstance()") } return instance.App } +// SetInstance sets the global Core instance for App() access. +// This is typically called by GUI runtimes during initialization. +func SetInstance(c *Core) { + instance = c +} + // Config returns the registered Config service. func (c *Core) Config() Config { cfg := MustServiceFor[Config](c, "config") diff --git a/pkg/framework/core/core_extra_test.go b/pkg/framework/core/core_extra_test.go index ebde048e..38da57f1 100644 --- a/pkg/framework/core/core_extra_test.go +++ b/pkg/framework/core/core_extra_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "testing" diff --git a/pkg/framework/core/core_lifecycle_test.go b/pkg/framework/core/core_lifecycle_test.go index 219be431..3982a363 100644 --- a/pkg/framework/core/core_lifecycle_test.go +++ b/pkg/framework/core/core_lifecycle_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "context" diff --git a/pkg/framework/core/core_test.go b/pkg/framework/core/core_test.go index 6b566d8f..6dbdaec6 100644 --- a/pkg/framework/core/core_test.go +++ b/pkg/framework/core/core_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "embed" diff --git a/pkg/framework/core/e.go b/pkg/framework/core/e.go index 9001f77d..fb1a1e47 100644 --- a/pkg/framework/core/e.go +++ b/pkg/framework/core/e.go @@ -1,4 +1,4 @@ -// Package e provides a standardized error handling mechanism for the Core library. +// Package core provides a standardized error handling mechanism for the Core library. // It allows for wrapping errors with contextual information, making it easier to // trace the origin of an error and provide meaningful feedback. // @@ -13,7 +13,7 @@ // that is more informative than a raw stack trace. // - Consistent error handling: Encourages a uniform approach to error // handling across the entire codebase. -package framework +package core import ( "fmt" diff --git a/pkg/framework/core/e_test.go b/pkg/framework/core/e_test.go index 1d5c8b8a..71b04c03 100644 --- a/pkg/framework/core/e_test.go +++ b/pkg/framework/core/e_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "errors" diff --git a/pkg/framework/core/interfaces.go b/pkg/framework/core/interfaces.go index a5001e50..3a803847 100644 --- a/pkg/framework/core/interfaces.go +++ b/pkg/framework/core/interfaces.go @@ -1,4 +1,4 @@ -package framework +package core import ( "context" diff --git a/pkg/framework/core/runtime_pkg.go b/pkg/framework/core/runtime_pkg.go index 8278c84b..04a3bd93 100644 --- a/pkg/framework/core/runtime_pkg.go +++ b/pkg/framework/core/runtime_pkg.go @@ -1,4 +1,4 @@ -package framework +package core import ( "context" @@ -49,7 +49,6 @@ type ServiceFactory func() (any, error) // This is the most flexible way to create a new Runtime, as it allows for // the registration of any number of services. func NewWithFactories(app any, factories map[string]ServiceFactory) (*Runtime, error) { - services := make(map[string]any) coreOpts := []Option{ WithApp(app), } @@ -66,7 +65,6 @@ func NewWithFactories(app any, factories map[string]ServiceFactory) (*Runtime, e if err != nil { return nil, fmt.Errorf("failed to create service %s: %w", name, err) } - services[name] = svc svcCopy := svc coreOpts = append(coreOpts, WithName(name, func(c *Core) (any, error) { return svcCopy, nil })) } @@ -76,14 +74,10 @@ func NewWithFactories(app any, factories map[string]ServiceFactory) (*Runtime, e return nil, err } - // --- Type Assertions --- - - rt := &Runtime{ + return &Runtime{ app: app, Core: coreInstance, - } - - return rt, nil + }, nil } // NewRuntime creates and wires together all application services. @@ -104,7 +98,7 @@ func (r *Runtime) ServiceStartup(ctx context.Context, options any) { r.Core.ServiceStartup(ctx, options) } -// ServiceShutdown is called by Wails at application shutdown. +// ServiceShutdown is called by the GUI runtime at application shutdown. // This is where the Core's shutdown lifecycle is initiated. func (r *Runtime) ServiceShutdown(ctx context.Context) { if r.Core != nil { diff --git a/pkg/framework/core/runtime_pkg_extra_test.go b/pkg/framework/core/runtime_pkg_extra_test.go index df29ee79..c63a4a1c 100644 --- a/pkg/framework/core/runtime_pkg_extra_test.go +++ b/pkg/framework/core/runtime_pkg_extra_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "testing" diff --git a/pkg/framework/core/runtime_pkg_test.go b/pkg/framework/core/runtime_pkg_test.go index ada309b0..0600d819 100644 --- a/pkg/framework/core/runtime_pkg_test.go +++ b/pkg/framework/core/runtime_pkg_test.go @@ -1,4 +1,4 @@ -package framework +package core import ( "testing" diff --git a/pkg/framework/framework.go b/pkg/framework/framework.go index 6cff7dd6..64540364 100644 --- a/pkg/framework/framework.go +++ b/pkg/framework/framework.go @@ -11,7 +11,7 @@ package framework import ( - core "github.com/host-uk/core/pkg/framework/core" + "github.com/host-uk/core/pkg/framework/core" ) // Re-export core types for cleaner imports