Skip to content

Commit d56c273

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 d56c273

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
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)

0 commit comments

Comments
 (0)