Skip to content

Commit 07c5c9a

Browse files
author
Drakirus
committed
refactor: Split init call of Plugin & PluginGLFW
Plugin interface doesn't need a glfw.Window to be instantiated. Calling the init function of the Plugin interface improves the flexibility. #137
1 parent eae922f commit 07c5c9a

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

application.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ func (a *Application) Run() error {
6262
}
6363
defer glfw.Terminate()
6464

65+
a.engine = embedder.NewFlutterEngine()
66+
67+
messenger := newMessenger(a.engine)
68+
for _, p := range a.config.plugins {
69+
err = p.InitPlugin(messenger)
70+
if err != nil {
71+
return errors.Wrap(err, "failed to initialize plugin "+fmt.Sprintf("%T", p))
72+
}
73+
}
74+
6575
a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.x, a.config.windowInitialDimensions.y, "Loading..", nil, nil)
6676
if err != nil {
6777
return errors.Wrap(err, "creating glfw window")
@@ -83,15 +93,7 @@ func (a *Application) Run() error {
8393
}
8494
}
8595

86-
a.engine = embedder.NewFlutterEngine()
87-
88-
messenger := newMessenger(a.engine)
8996
for _, p := range a.config.plugins {
90-
err = p.InitPlugin(messenger)
91-
if err != nil {
92-
return errors.Wrap(err, "failed to initialize plugin "+fmt.Sprintf("%T", p))
93-
}
94-
9597
// Extra init call for plugins that satisfy the PluginGLFW interface.
9698
if glfwPlugin, ok := p.(PluginGLFW); ok {
9799
err = glfwPlugin.InitPluginGLFW(a.window)

plugin.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
// The BinaryMessenger is passed to allow the plugin to register channels.
1414
// A plugin may optionally implement PluginGLFW.
1515
type Plugin interface {
16-
// InitPlugin is called during the startup of the flutter application. The
17-
// plugin is responsible for setting up channels using the BinaryMessenger.
18-
// If an error is returned it is printend the application is stopped.
16+
// InitPlugin is called before creating the GLFW window of the flutter
17+
// application. The plugin is responsible for setting up channels using the
18+
// BinaryMessenger.
19+
// If an error is returned it is printed the application is stopped.
1920
InitPlugin(messenger plugin.BinaryMessenger) error
2021
}
2122

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

0 commit comments

Comments
 (0)