diff --git a/.github/ISSUE_TEMPLATE/BUG.md b/.github/ISSUE_TEMPLATE/BUG.md index f50a431c..9db59b20 100644 --- a/.github/ISSUE_TEMPLATE/BUG.md +++ b/.github/ISSUE_TEMPLATE/BUG.md @@ -31,7 +31,7 @@ Golang's compiling errors ## Does the prebuilt and portable version works ? -###### Download [Link](https://github.com/Drakirus/go-flutter-desktop-embedder/releases) +###### Download [Link](https://github.com/go-flutter-desktop/go-flutter/releases) - Yes / No diff --git a/README.md b/README.md index b6dc50bd..0ca736a8 100755 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The choice of [Golang](https://github.com/golang/go) comes from the fact that it
:package: :penguin: Linux

From binaries

-Check out the Release page for prebuilt versions. +Check out the Release page for prebuilt versions.

From source

@@ -34,7 +34,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/) ```bash # Clone -git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git +git clone https://github.com/go-flutter-desktop/go-flutter.git cd go-flutter-desktop-embedder # Build the flutter simpleDemo project @@ -51,7 +51,7 @@ export CGO_LDFLAGS="-L${PWD}" # The share library must stay next to the generated binary. # Get the libraries -go get -u -v github.com/Drakirus/go-flutter-desktop-embedder +go get -u -v github.com/go-flutter-desktop/go-flutter # Build the example project go build main.go @@ -64,7 +64,7 @@ go build main.go
:package: :checkered_flag: Windows

From binaries

-Check out the Release page for prebuilt versions. +Check out the Release page for prebuilt versions.

From source

@@ -73,7 +73,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/) ```bash # Clone -git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git +git clone https://github.com/go-flutter-desktop/go-flutter.git cd go-flutter-desktop-embedder # Build the flutter simpleDemo project @@ -88,10 +88,10 @@ go run engineDownloader.go # REQUIRED before every `go build`. The CGO compiler need to know where to look for the share library set CGO_LDFLAGS=-L%cd% # The share library must stay next to the generated binary. -# If you ran into a MinGW ld error, checkout: https://github.com/Drakirus/go-flutter-desktop-embedder/issues/34 +# If you ran into a MinGW ld error, checkout: https://github.com/go-flutter-desktop/go-flutter/issues/34 # Get the libraries -go get -u -v github.com/Drakirus/go-flutter-desktop-embedder +go get -u -v github.com/go-flutter-desktop/go-flutter # Build the example project go build main.go @@ -104,7 +104,7 @@ go build main.go
:package: :apple: MacOS

From binaries

-Check out the Release page for prebuilt versions. +Check out the Release page for prebuilt versions.

From source

@@ -113,7 +113,7 @@ Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/) ```bash # Clone -git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git +git clone https://github.com/go-flutter-desktop/go-flutter.git cd go-flutter-desktop-embedder # Build the flutter simpleDemo project @@ -130,7 +130,7 @@ export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path" # The share library must stay next to the generated binary. # Get the libraries -go get -u -v github.com/Drakirus/go-flutter-desktop-embedder +go get -u -v github.com/go-flutter-desktop/go-flutter # Build the example project go build main.go diff --git a/flutter/build.go b/embedder/build.go similarity index 85% rename from flutter/build.go rename to embedder/build.go index 4180647f..5217cd16 100644 --- a/flutter/build.go +++ b/embedder/build.go @@ -1,4 +1,4 @@ -package flutter +package embedder /* // Linux Build Tags @@ -21,5 +21,5 @@ import "C" import ( // prevents dep from stripping out the c source files in flutter library. - _ "github.com/Drakirus/go-flutter-desktop-embedder/flutter/library" + _ "github.com/go-flutter-desktop/go-flutter/embedder/library" ) diff --git a/flutter/flutter.go b/embedder/embedder.go similarity index 76% rename from flutter/flutter.go rename to embedder/embedder.go index ca28fdf1..f81eb522 100644 --- a/flutter/flutter.go +++ b/embedder/embedder.go @@ -1,4 +1,4 @@ -package flutter +package embedder // #include "flutter_embedder.h" // FlutterResult runFlutter(uintptr_t window, FlutterEngine *engine, FlutterProjectArgs * Args, @@ -12,21 +12,21 @@ import ( "unsafe" ) -// the current FlutterEngine running (associated with his callback) -var flutterEngines []*EngineOpenGL +// A list of flutter engines that are managed by this embedder. +var flutterEngines []*FlutterEngine var flutterEnginesLock sync.RWMutex -// SelectEngine return a EngineOpenGL from an index -func SelectEngine(index int) *EngineOpenGL { +// FlutterEngineByIndex returns an existing FlutterEngine by its index in this embedder. +func FlutterEngineByIndex(index int) *FlutterEngine { flutterEnginesLock.RLock() engine := flutterEngines[index] flutterEnginesLock.RUnlock() return engine } -// NumberOfEngines return the number of engine registered into this embedder -func NumberOfEngines() C.int { - return C.int(len(flutterEngines)) +// CountFlutterEngines return the number of engines registered in this embedder. +func CountFlutterEngines() int { + return len(flutterEngines) } // Result corresponds to the C.enum retuned by the shared flutter library @@ -40,8 +40,8 @@ const ( KInvalidArguments Result = C.kInvalidArguments ) -// EngineOpenGL corresponds to the C.FlutterEngine with his associated callback's method. -type EngineOpenGL struct { +// FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method. +type FlutterEngine struct { // Flutter Engine. Engine C.FlutterEngine @@ -63,28 +63,28 @@ type EngineOpenGL struct { IcuDataPath string } -// NewEngineOpenGL creates an empty EngineOpenGL +// NewFlutterEngine creates an empty FlutterEngine // and assigns it an index for global lookup. -func NewEngineOpenGL() *EngineOpenGL { - flu := &EngineOpenGL{} +func NewFlutterEngine() *FlutterEngine { + fe := &FlutterEngine{} flutterEnginesLock.Lock() - flutterEngines = append(flutterEngines, flu) - flu.index = len(flutterEngines) - 1 + flutterEngines = append(flutterEngines, fe) + fe.index = len(flutterEngines) - 1 flutterEnginesLock.Unlock() - return flu + return fe } // Index returns the index of the engine in the global flutterEngines slice -func (flu *EngineOpenGL) Index() int { +func (flu *FlutterEngine) Index() int { return flu.index } // Run launches the Flutter Engine in a background thread. -func (flu *EngineOpenGL) Run(window uintptr, vmArgs []string) Result { - // validate this EngineOpenGL was created correctly +func (flu *FlutterEngine) Run(window uintptr, vmArgs []string) Result { + // validate this FlutterEngine was created correctly flutterEnginesLock.RLock() if len(flutterEngines) <= flu.index || flutterEngines[flu.index] != flu { - panic("EngineOpenGL was wrongly created. Use embedder.NewEngineOpenGL().") + panic("FlutterEngine was wrongly created. Use embedder.NewFlutterEngine().") } flutterEnginesLock.RUnlock() @@ -109,7 +109,7 @@ func (flu *EngineOpenGL) Run(window uintptr, vmArgs []string) Result { } // Shutdown stops the Flutter engine. -func (flu *EngineOpenGL) Shutdown() Result { +func (flu *FlutterEngine) Shutdown() Result { res := C.FlutterEngineShutdown(flu.Engine) return (Result)(res) } @@ -133,8 +133,8 @@ type PointerEvent struct { Y float64 } -// EngineSendPointerEvent is used to send an PointerEvent to the Flutter engine. -func (flu *EngineOpenGL) EngineSendPointerEvent(Event PointerEvent) Result { +// SendPointerEvent is used to send an PointerEvent to the Flutter engine. +func (flu *FlutterEngine) SendPointerEvent(Event PointerEvent) Result { cEvents := C.FlutterPointerEvent{ phase: (_Ctype_FlutterPointerPhase)(Event.Phase), @@ -156,8 +156,8 @@ type WindowMetricsEvent struct { PixelRatio float64 } -// EngineSendWindowMetricsEvent is used to send a WindowMetricsEvent to the Flutter Engine. -func (flu *EngineOpenGL) EngineSendWindowMetricsEvent(Metric WindowMetricsEvent) Result { +// SendWindowMetricsEvent is used to send a WindowMetricsEvent to the Flutter Engine. +func (flu *FlutterEngine) SendWindowMetricsEvent(Metric WindowMetricsEvent) Result { cMetric := C.FlutterWindowMetricsEvent{ width: C.size_t(Metric.Width), @@ -188,7 +188,7 @@ type Message struct { } // SendPlatformMessage is used to send a PlatformMessage to the Flutter engine. -func (flu *EngineOpenGL) SendPlatformMessage(Message *PlatformMessage) Result { +func (flu *FlutterEngine) SendPlatformMessage(Message *PlatformMessage) Result { marshalled, err := json.Marshal(&Message.Message) if err != nil { @@ -213,7 +213,7 @@ func (flu *EngineOpenGL) SendPlatformMessage(Message *PlatformMessage) Result { } // SendPlatformMessageResponse is used to send a message to the Flutter side using the correct ResponseHandle! -func (flu *EngineOpenGL) SendPlatformMessageResponse( +func (flu *FlutterEngine) SendPlatformMessageResponse( responseTo *PlatformMessage, data []byte, ) Result { @@ -228,8 +228,8 @@ func (flu *EngineOpenGL) SendPlatformMessageResponse( } -// EngineFlushPendingTasksNow flush tasks on a message loop not controlled by the Flutter engine. +// FlutterEngineFlushPendingTasksNow flush tasks on a message loop not controlled by the Flutter engine. // deprecated soon. -func EngineFlushPendingTasksNow() { +func FlutterEngineFlushPendingTasksNow() { C.__FlutterEngineFlushPendingTasksNow() } diff --git a/embedder/embedder_helper.c b/embedder/embedder_helper.c new file mode 100644 index 00000000..f1b17967 --- /dev/null +++ b/embedder/embedder_helper.c @@ -0,0 +1,45 @@ + +#include "library/flutter_embedder.h" +#include + +// C proxies def +bool proxy_make_current(void *v); +bool proxy_clear_current(void *v); +bool proxy_present(void *v); +uint32_t proxy_fbo_callback(void *v); +bool proxy_make_resource_current(void *v); +void *proxy_gl_proc_resolver(void *v, const char *procname); +bool proxy_on_platform_message(FlutterPlatformMessage *message, void *window); + +// C helper +FlutterResult runFlutter(uintptr_t window, FlutterEngine *engine, FlutterProjectArgs *Args, + const char *const *vmArgs, int nVmAgrs) +{ + + FlutterRendererConfig config = {}; + config.type = kOpenGL; + + config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig); + config.open_gl.make_current = proxy_make_current; + config.open_gl.clear_current = proxy_clear_current; + config.open_gl.present = proxy_present; + config.open_gl.fbo_callback = proxy_fbo_callback; + config.open_gl.make_resource_current = proxy_make_resource_current; + config.open_gl.gl_proc_resolver = proxy_gl_proc_resolver; + + Args->command_line_argc = nVmAgrs; + Args->command_line_argv = vmArgs; + Args->platform_message_callback = (FlutterPlatformMessageCallback)proxy_on_platform_message; + + return FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, Args, (void *)window, engine); +} + +char **makeCharArray(int size) +{ + return calloc(sizeof(char *), size); +} + +void setArrayString(char **a, char *s, int n) +{ + a[n] = s; +} diff --git a/flutter/flutter_proxy_glfw.go b/embedder/embedder_proxy_glfw.go similarity index 73% rename from flutter/flutter_proxy_glfw.go rename to embedder/embedder_proxy_glfw.go index 2d6b154b..fd8b0056 100644 --- a/flutter/flutter_proxy_glfw.go +++ b/embedder/embedder_proxy_glfw.go @@ -1,4 +1,4 @@ -package flutter +package embedder /* #include "flutter_embedder.h" @@ -31,8 +31,8 @@ func proxy_on_platform_message(message *C.FlutterPlatformMessage, window unsafe. ResponseHandle: message.response_handle, } index := *(*int)(glfw.GoWindow(window).GetUserPointer()) - engine := SelectEngine(index) - return C.bool(engine.FPlatfromMessage(FlutterPlatformMessage, window)) + flutterEngine := FlutterEngineByIndex(index) + return C.bool(flutterEngine.FPlatfromMessage(FlutterPlatformMessage, window)) } return C.bool(false) } @@ -41,40 +41,40 @@ func proxy_on_platform_message(message *C.FlutterPlatformMessage, window unsafe. func proxy_make_current(v unsafe.Pointer) C.bool { w := glfw.GoWindow(v) index := *(*int)(w.GetUserPointer()) - engine := SelectEngine(index) - return C.bool(engine.FMakeCurrent(v)) + flutterEngine := FlutterEngineByIndex(index) + return C.bool(flutterEngine.FMakeCurrent(v)) } //export proxy_clear_current func proxy_clear_current(v unsafe.Pointer) C.bool { w := glfw.GoWindow(v) index := *(*int)(w.GetUserPointer()) - engine := SelectEngine(index) - return C.bool(engine.FClearCurrent(v)) + flutterEngine := FlutterEngineByIndex(index) + return C.bool(flutterEngine.FClearCurrent(v)) } //export proxy_present func proxy_present(v unsafe.Pointer) C.bool { w := glfw.GoWindow(v) index := *(*int)(w.GetUserPointer()) - engine := SelectEngine(index) - return C.bool(engine.FPresent(v)) + flutterEngine := FlutterEngineByIndex(index) + return C.bool(flutterEngine.FPresent(v)) } //export proxy_fbo_callback func proxy_fbo_callback(v unsafe.Pointer) C.uint32_t { w := glfw.GoWindow(v) index := *(*int)(w.GetUserPointer()) - engine := SelectEngine(index) - return C.uint32_t(engine.FFboCallback(v)) + flutterEngine := FlutterEngineByIndex(index) + return C.uint32_t(flutterEngine.FFboCallback(v)) } //export proxy_make_resource_current func proxy_make_resource_current(v unsafe.Pointer) C.bool { w := glfw.GoWindow(v) index := *(*int)(w.GetUserPointer()) - engine := SelectEngine(index) - return C.bool(engine.FMakeResourceCurrent(v)) + flutterEngine := FlutterEngineByIndex(index) + return C.bool(flutterEngine.FMakeResourceCurrent(v)) } //export proxy_gl_proc_resolver diff --git a/flutter/library/flutter_embedder.h b/embedder/library/flutter_embedder.h similarity index 100% rename from flutter/library/flutter_embedder.h rename to embedder/library/flutter_embedder.h diff --git a/flutter/library/library.go b/embedder/library/library.go similarity index 100% rename from flutter/library/library.go rename to embedder/library/library.go diff --git a/example/simpleDemo/.gitignore b/example/simpleDemo/.gitignore new file mode 100644 index 00000000..d758b2f5 --- /dev/null +++ b/example/simpleDemo/.gitignore @@ -0,0 +1,2 @@ +icudtl.dat +main diff --git a/example/simpleDemo/main.go b/example/simpleDemo/main.go index 2d7f5a89..3373e6e4 100644 --- a/example/simpleDemo/main.go +++ b/example/simpleDemo/main.go @@ -13,8 +13,8 @@ import ( "strings" "time" - gutter "github.com/Drakirus/go-flutter-desktop-embedder" - "github.com/Drakirus/go-flutter-desktop-embedder/flutter" + "github.com/go-flutter-desktop/go-flutter" + "github.com/go-flutter-desktop/go-flutter/embedder" "github.com/go-gl/glfw/v3.2/glfw" ) @@ -42,29 +42,29 @@ func main() { initialApplicationHeight := 600 initialApplicationWidth := 800 - options := []gutter.Option{ - gutter.ProjectAssetPath(dir + "/flutter_project/demo/build/flutter_assets"), + options := []flutter.Option{ + flutter.ProjectAssetPath(dir + "/flutter_project/demo/build/flutter_assets"), // This path should not be changed. icudtl.dat is handled by engineDownloader.go - gutter.ApplicationICUDataPath(dir + "/icudtl.dat"), + flutter.ApplicationICUDataPath(dir + "/icudtl.dat"), - gutter.ApplicationWindowDimension(initialApplicationWidth, initialApplicationHeight), + flutter.ApplicationWindowDimension(initialApplicationWidth, initialApplicationHeight), // gutter.OptionPixelRatio(1.2), - gutter.OptionWindowInitializer(setIcon), - gutter.OptionVMArguments([]string{ + flutter.OptionWindowInitializer(setIcon), + flutter.OptionVMArguments([]string{ // "--disable-dart-asserts", // release mode flag // "--disable-observatory", "--observatory-port=50300", }), - // - gutter.OptionAddPluginReceiver(ownPlugin, "plugin_demo"), + + flutter.OptionAddPluginReceiver(ownPlugin, "plugin_demo"), // Default keyboard is Qwerty, if you want to change it, you can check keyboard.go in gutter package. // Otherwise you can create your own by usinng `KeyboardShortcuts` struct. - //gutter.OptionKeyboardLayout(gutter.KeyboardAzertyLayout), + //flutter.OptionKeyboardLayout(flutter.KeyboardAzertyLayout), } - if err := gutter.Run(options...); err != nil { + if err := flutter.Run(options...); err != nil { log.Fatalln(err) } @@ -72,8 +72,8 @@ func main() { // Plugin that read the stdin and send the number to the dart side func ownPlugin( - platMessage *flutter.PlatformMessage, - flutterEngine *flutter.EngineOpenGL, + platMessage *embedder.PlatformMessage, + flutterEngine *embedder.FlutterEngine, window *glfw.Window, ) bool { diff --git a/example/stocks/main.go b/example/stocks/main.go index 409e6270..3414e7bd 100644 --- a/example/stocks/main.go +++ b/example/stocks/main.go @@ -6,7 +6,7 @@ import ( "log" "os" - gutter "github.com/Drakirus/go-flutter-desktop-embedder" + gutter "github.com/go-flutter-desktop/go-flutter" "github.com/go-gl/glfw/v3.2/glfw" ) diff --git a/gutter.go b/flutter.go similarity index 79% rename from gutter.go rename to flutter.go index b1a3374d..8952a408 100644 --- a/gutter.go +++ b/flutter.go @@ -1,4 +1,4 @@ -package gutter +package flutter import ( "encoding/json" @@ -7,7 +7,7 @@ import ( "time" "unsafe" - "github.com/Drakirus/go-flutter-desktop-embedder/flutter" + "github.com/go-flutter-desktop/go-flutter/embedder" "github.com/go-gl/glfw/v3.2/glfw" ) @@ -44,14 +44,14 @@ func Run(options ...Option) (err error) { return err } - engine := runFlutter(window, c) + flu := runFlutter(window, c) - defer engine.Shutdown() + defer flu.Shutdown() for !window.ShouldClose() { // glfw.WaitEvents() glfw.PollEvents() - flutter.EngineFlushPendingTasksNow() + embedder.FlutterEngineFlushPendingTasksNow() } return nil @@ -59,13 +59,13 @@ func Run(options ...Option) (err error) { // GLFW callbacks to the Flutter Engine func glfwCursorPositionCallbackAtPhase( - window *glfw.Window, phase flutter.PointerPhase, + window *glfw.Window, phase embedder.PointerPhase, x float64, y float64, ) { winWidth, _ := window.GetSize() frameBuffWidth, _ := window.GetFramebufferSize() contentScale := float64(frameBuffWidth / winWidth) - event := flutter.PointerEvent{ + event := embedder.PointerEvent{ Phase: phase, X: x * contentScale, Y: y * contentScale, @@ -73,13 +73,12 @@ func glfwCursorPositionCallbackAtPhase( } index := *(*int)(window.GetUserPointer()) - flutterOGL := flutter.SelectEngine(index) + flutterEngine := embedder.FlutterEngineByIndex(index) - flutterOGL.EngineSendPointerEvent(event) + flutterEngine.SendPointerEvent(event) } func glfwMouseButtonCallback(window *glfw.Window, key glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) { - if key == glfw.MouseButton1 { x, y := window.GetCursorPos() @@ -91,25 +90,24 @@ func glfwMouseButtonCallback(window *glfw.Window, key glfw.MouseButton, action g y = y * pixelsPerScreenCoordinate if action == glfw.Press { - glfwCursorPositionCallbackAtPhase(window, flutter.KDown, x, y) + glfwCursorPositionCallbackAtPhase(window, embedder.KDown, x, y) window.SetCursorPosCallback(func(window *glfw.Window, x float64, y float64) { - glfwCursorPositionCallbackAtPhase(window, flutter.KMove, x, y) + x = x * pixelsPerScreenCoordinate + y = y * pixelsPerScreenCoordinate + glfwCursorPositionCallbackAtPhase(window, embedder.KMove, x, y) }) } if action == glfw.Release { - x, y := window.GetCursorPos() - glfwCursorPositionCallbackAtPhase(window, flutter.KUp, x, y) + glfwCursorPositionCallbackAtPhase(window, embedder.KUp, x, y) window.SetCursorPosCallback(nil) } } - } var state = textModel{} func glfwKey(keyboardLayout KeyboardShortcuts) func(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { - return func(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { if key == glfw.KeyEscape && action == glfw.Press { w.SetShouldClose(true) @@ -181,7 +179,7 @@ func glfwKey(keyboardLayout KeyboardShortcuts) func(w *glfw.Window, key glfw.Key func newGLFWFramebufferSizeCallback(pixelRatio float64, monitorScreenCoordinatesPerInch float64) func(*glfw.Window, int, int) { return func(window *glfw.Window, widthPx int, heightPx int) { index := *(*int)(window.GetUserPointer()) - flutterOGL := flutter.SelectEngine(index) + flutterEngine := embedder.FlutterEngineByIndex(index) if pixelRatio == 0 { width, _ := window.GetSize() @@ -196,12 +194,12 @@ func newGLFWFramebufferSizeCallback(pixelRatio float64, monitorScreenCoordinates } } - event := flutter.WindowMetricsEvent{ + event := embedder.WindowMetricsEvent{ Width: widthPx, Height: heightPx, PixelRatio: pixelRatio, } - flutterOGL.EngineSendWindowMetricsEvent(event) + flutterEngine.SendWindowMetricsEvent(event) } } @@ -212,44 +210,45 @@ func glfwCharCallback(w *glfw.Window, char rune) { } // Flutter Engine -func runFlutter(window *glfw.Window, c config) *flutter.EngineOpenGL { +func runFlutter(window *glfw.Window, c config) *embedder.FlutterEngine { + flutterEngine := embedder.NewFlutterEngine() - flutterOGL := flutter.NewEngineOpenGL() // Engine arguments - flutterOGL.AssetsPath = c.AssetPath - flutterOGL.IcuDataPath = c.ICUDataPath + flutterEngine.AssetsPath = c.AssetPath + flutterEngine.IcuDataPath = c.ICUDataPath + // Render callbacks - flutterOGL.FMakeCurrent = func(v unsafe.Pointer) bool { + flutterEngine.FMakeCurrent = func(v unsafe.Pointer) bool { w := glfw.GoWindow(v) w.MakeContextCurrent() return true } - flutterOGL.FClearCurrent = func(v unsafe.Pointer) bool { + flutterEngine.FClearCurrent = func(v unsafe.Pointer) bool { glfw.DetachCurrentContext() return true } - flutterOGL.FPresent = func(v unsafe.Pointer) bool { + flutterEngine.FPresent = func(v unsafe.Pointer) bool { w := glfw.GoWindow(v) w.SwapBuffers() return true } - flutterOGL.FFboCallback = func(v unsafe.Pointer) int32 { + flutterEngine.FFboCallback = func(v unsafe.Pointer) int32 { return 0 } - flutterOGL.FMakeResourceCurrent = func(v unsafe.Pointer) bool { + flutterEngine.FMakeResourceCurrent = func(v unsafe.Pointer) bool { return false } // PlatformMessage - flutterOGL.FPlatfromMessage = func(platMessage *flutter.PlatformMessage, window unsafe.Pointer) bool { + flutterEngine.FPlatfromMessage = func(platMessage *embedder.PlatformMessage, window unsafe.Pointer) bool { windows := glfw.GoWindow(window) hasDispatched := false // Dispatch the message from the Flutter Engine, to all of the PluginReceivers - // having the same flutter.PlatformMessage.Channel name + // having the same embedder.PlatformMessage.Channel name for _, receivers := range c.PlatformMessageReceivers[platMessage.Channel] { - hasDispatched = receivers(platMessage, flutterOGL, windows) || hasDispatched + hasDispatched = receivers(platMessage, flutterEngine, windows) || hasDispatched } return hasDispatched @@ -260,11 +259,11 @@ func runFlutter(window *glfw.Window, c config) *flutter.EngineOpenGL { updateEditingState(window) } - flutterOGLIndex := flutterOGL.Index() - window.SetUserPointer(unsafe.Pointer(&flutterOGLIndex)) - result := flutterOGL.Run(window.GLFWWindow(), c.VMArguments) + flutterEngineIndex := flutterEngine.Index() + window.SetUserPointer(unsafe.Pointer(&flutterEngineIndex)) + result := flutterEngine.Run(window.GLFWWindow(), c.VMArguments) - if result != flutter.KSuccess { + if result != embedder.KSuccess { window.Destroy() panic("Couldn't launch the FlutterEngine") } @@ -284,7 +283,7 @@ func runFlutter(window *glfw.Window, c config) *flutter.EngineOpenGL { window.SetFramebufferSizeCallback(glfwFramebufferSizeCallback) window.SetMouseButtonCallback(glfwMouseButtonCallback) window.SetCharCallback(glfwCharCallback) - return flutterOGL + return flutterEngine } // getScreenCoordinatesPerInch returns the number of screen coordinates per @@ -309,7 +308,6 @@ func getScreenCoordinatesPerInch() float64 { // Update the TextInput with the current state func updateEditingState(window *glfw.Window) { - editingState := argsEditingState{ Text: string(state.word), SelectionAffinity: "TextAffinity.downstream", @@ -323,20 +321,20 @@ func updateEditingState(window *glfw.Window) { editingState, }) - message := flutter.Message{ + message := embedder.Message{ Args: editingStateMarchalled, Method: textUpdateStateMethod, } - var mess = &flutter.PlatformMessage{ + var mess = &embedder.PlatformMessage{ Channel: textInputChannel, Message: message, } index := *(*int)(window.GetUserPointer()) - flutterOGL := flutter.SelectEngine(index) + flutterEngine := embedder.FlutterEngineByIndex(index) - flutterOGL.SendPlatformMessage(mess) + flutterEngine.SendPlatformMessage(mess) } func performAction(window *glfw.Window, action string) { @@ -344,17 +342,17 @@ func performAction(window *glfw.Window, action string) { state.clientID, "TextInputAction." + action, }) - message := flutter.Message{ + message := embedder.Message{ Args: actionArgs, Method: "TextInputClient.performAction", } - var mess = &flutter.PlatformMessage{ + var mess = &embedder.PlatformMessage{ Channel: textInputChannel, Message: message, } index := *(*int)(window.GetUserPointer()) - flutterOGL := flutter.SelectEngine(index) + flutterEngine := embedder.FlutterEngineByIndex(index) - flutterOGL.SendPlatformMessage(mess) + flutterEngine.SendPlatformMessage(mess) } diff --git a/flutter/flutter_helper.c b/flutter/flutter_helper.c deleted file mode 100644 index c9a99946..00000000 --- a/flutter/flutter_helper.c +++ /dev/null @@ -1,47 +0,0 @@ - -#include "library/flutter_embedder.h" -#include - - -// C proxies def -bool proxy_make_current(void *v); -bool proxy_clear_current(void *v); -bool proxy_present(void *v); -uint32_t proxy_fbo_callback(void *v); -bool proxy_make_resource_current(void *v); -void *proxy_gl_proc_resolver(void *v, const char *procname); - -bool proxy_on_platform_message(FlutterPlatformMessage *message, - void *window); - -// C helper -FlutterResult runFlutter(uintptr_t window, FlutterEngine *engine, FlutterProjectArgs * Args, - const char *const * vmArgs, int nVmAgrs) { - - FlutterRendererConfig config = {}; - config.type = kOpenGL; - - config.open_gl.struct_size = sizeof(FlutterOpenGLRendererConfig); - - config.open_gl.make_current = proxy_make_current; - config.open_gl.clear_current = proxy_clear_current; - config.open_gl.present = proxy_present; - config.open_gl.fbo_callback = proxy_fbo_callback; - config.open_gl.make_resource_current = proxy_make_resource_current; - config.open_gl.gl_proc_resolver = proxy_gl_proc_resolver; - - Args->command_line_argc = nVmAgrs; - Args->command_line_argv = vmArgs; - Args->platform_message_callback = (FlutterPlatformMessageCallback)proxy_on_platform_message; - - return FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, Args, (void*)window, engine); -} - -char** makeCharArray(int size) { - return calloc(sizeof(char*), size); -} - -void setArrayString(char **a, char *s, int n) { - a[n] = s; -} - diff --git a/keyboard.go b/keyboard.go index 6d81b167..1fc8dd54 100644 --- a/keyboard.go +++ b/keyboard.go @@ -1,4 +1,4 @@ -package gutter +package flutter import "github.com/go-gl/glfw/v3.2/glfw" diff --git a/option.go b/option.go index 5ffd2bed..7db3cea8 100644 --- a/option.go +++ b/option.go @@ -1,4 +1,4 @@ -package gutter +package flutter import ( "log" diff --git a/plugin_receiver.go b/plugin_receiver.go index d862a15f..cdf5444a 100644 --- a/plugin_receiver.go +++ b/plugin_receiver.go @@ -1,14 +1,14 @@ -package gutter +package flutter import ( - "github.com/Drakirus/go-flutter-desktop-embedder/flutter" + "github.com/go-flutter-desktop/go-flutter/embedder" "github.com/go-gl/glfw/v3.2/glfw" ) // PluginReceivers do stuff when receiving Message from the Engine, // send result with `flutterEngine.SendPlatformMessageResponse` type PluginReceivers func( - message *flutter.PlatformMessage, - flutterEngine *flutter.EngineOpenGL, + message *embedder.PlatformMessage, + flutterEngine *embedder.FlutterEngine, window *glfw.Window, ) bool diff --git a/system_plugins.go b/system_plugins.go index c27d98e2..a317792f 100644 --- a/system_plugins.go +++ b/system_plugins.go @@ -1,9 +1,9 @@ -package gutter +package flutter import ( "encoding/json" - "github.com/Drakirus/go-flutter-desktop-embedder/flutter" + "github.com/go-flutter-desktop/go-flutter/embedder" "github.com/go-gl/glfw/v3.2/glfw" ) @@ -32,10 +32,9 @@ type ArgsAppSwitcherDescription struct { } func addHandlerWindowTitle() Option { - var handler PluginReceivers = func( - platMessage *flutter.PlatformMessage, - flutterEngine *flutter.EngineOpenGL, + platMessage *embedder.PlatformMessage, + flutterEngine *embedder.FlutterEngine, window *glfw.Window, ) bool { message := &platMessage.Message @@ -50,12 +49,11 @@ func addHandlerWindowTitle() Option { } return OptionAddPluginReceiver(handler, platformChannel) - } func addHandlerClipboard() Option { - handler := func(platMessage *flutter.PlatformMessage, - flutterEngine *flutter.EngineOpenGL, + handler := func(platMessage *embedder.PlatformMessage, + flutterEngine *embedder.FlutterEngine, window *glfw.Window) bool { message := &platMessage.Message @@ -122,10 +120,9 @@ type argsEditingState struct { } func addHandlerTextInput() Option { - var handler PluginReceivers = func( - platMessage *flutter.PlatformMessage, - flutterEngine *flutter.EngineOpenGL, + platMessage *embedder.PlatformMessage, + flutterEngine *embedder.FlutterEngine, window *glfw.Window, ) bool { @@ -154,5 +151,4 @@ func addHandlerTextInput() Option { } return OptionAddPluginReceiver(handler, textInputChannel) - } diff --git a/text_model.go b/text_model.go index c407e815..1c5b165f 100644 --- a/text_model.go +++ b/text_model.go @@ -1,4 +1,4 @@ -package gutter +package flutter import ( "sort"