context passing

This commit is contained in:
Ilia Denisov
2026-03-12 19:46:59 +02:00
parent 079b9facb0
commit f985370089
5 changed files with 23 additions and 11 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ func main() {
defer cancel()
app := app.New()
l, err := loader.NewLoader(app, nil)
l, err := loader.NewLoader(ctx, app, nil)
if err != nil {
return
}
+5 -5
View File
@@ -12,17 +12,17 @@ import (
"fyne.io/fyne/v2"
)
type ClientInit func(connector.UIConnector, fyne.App, mc.Settings) (mc.Client, error)
type ClientInit func(context.Context, connector.UIConnector, fyne.App, mc.Settings) (mc.Client, error)
type loader struct {
conn connector.Connector
cli mc.Client
}
func NewLoader(app fyne.App, conn connector.Connector) (*loader, error) {
func NewLoader(ctx context.Context, app fyne.App, conn connector.Connector) (*loader, error) {
app.Storage().List()
settings := mc.Settings{}
cli, err := loadClientPlugin(conn, app, settings, "./client.so", "NewClient")
cli, err := loadClientPlugin(ctx, conn, app, settings, "./client.so", "NewClient")
if err != nil {
return nil, err
}
@@ -61,7 +61,7 @@ func (l *loader) backgroundLoop(ctx context.Context, final <-chan struct{}) {
// loadClientPlugin loads a Client implementation from a shared object (.so) file at the specified path.
// It calls the constructor function by name, passing the necessary dependencies, and returns the initialized Client.
func loadClientPlugin(conn connector.UIConnector, app fyne.App, s mc.Settings, path, name string) (mc.Client, error) {
func loadClientPlugin(ctx context.Context, conn connector.UIConnector, app fyne.App, s mc.Settings, path, name string) (mc.Client, error) {
if path == "" {
return nil, errors.New("no plugin path given")
}
@@ -81,5 +81,5 @@ func loadClientPlugin(conn connector.UIConnector, app fyne.App, s mc.Settings, p
return nil, fmt.Errorf("unexpected type %T; want %T", sym, initializerPtr)
}
return (*initializerPtr)(conn, app, s)
return (*initializerPtr)(ctx, conn, app, s)
}