Skip to content

refactor: Split init call of Plugin & PluginGLFW #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func (a *Application) Run() error {
}
defer glfw.Terminate()

a.engine = embedder.NewFlutterEngine()

messenger := newMessenger(a.engine)
for _, p := range a.config.plugins {
err = p.InitPlugin(messenger)
if err != nil {
return errors.Wrap(err, "failed to initialize plugin "+fmt.Sprintf("%T", p))
}
}

a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", nil, nil)
if err != nil {
return errors.Wrap(err, "creating glfw window")
Expand All @@ -83,15 +93,7 @@ func (a *Application) Run() error {
}
}

a.engine = embedder.NewFlutterEngine()

messenger := newMessenger(a.engine)
for _, p := range a.config.plugins {
err = p.InitPlugin(messenger)
if err != nil {
return errors.Wrap(err, "failed to initialize plugin "+fmt.Sprintf("%T", p))
}

// Extra init call for plugins that satisfy the PluginGLFW interface.
if glfwPlugin, ok := p.(PluginGLFW); ok {
err = glfwPlugin.InitPluginGLFW(a.window)
Expand Down
16 changes: 9 additions & 7 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
// The BinaryMessenger is passed to allow the plugin to register channels.
// A plugin may optionally implement PluginGLFW.
type Plugin interface {
// InitPlugin is called during the startup of the flutter application. The
// plugin is responsible for setting up channels using the BinaryMessenger.
// If an error is returned it is printend the application is stopped.
// InitPlugin is called before creating the GLFW window of the flutter
// application. The plugin is responsible for setting up channels using the
// BinaryMessenger.
// If an error is returned it is printed the application is stopped.
InitPlugin(messenger plugin.BinaryMessenger) error
}

Expand All @@ -26,14 +27,15 @@ type Plugin interface {
//
// PluginGLFW is separated because not all plugins need to know about glfw,
// Adding glfw.Window to the InitPlugin call would add glfw as dependency to
// every plugin implementation. Also, this helps in a scenarion where glfw is
// every plugin implementation. Also, this helps in a scenario where glfw is
// moved into a separate renderer/glfw package.
//
// The PluginGLFW interface is not stable and may change at any time.
type PluginGLFW interface {
// Any type inmplementing PluginGLFW must also implement Plugin.
// Any type implementing PluginGLFW must also implement Plugin.
Plugin
// InitPluginGLFW is called after the call to InitPlugin. When an error is
// returned it is printend the application is stopped.
// InitPluginGLFW is called after the flutter engine is linked to the GLFW
// window. When an error is returned it is printed the application is
// stopped.
InitPluginGLFW(window *glfw.Window) error
}