From f538461a8cb20ead4756c01d7ac423419c06ddf9 Mon Sep 17 00:00:00 2001 From: Bruno Tavares Date: Sun, 24 Jul 2022 10:16:22 -0300 Subject: [PATCH] Implement new method channels to avoid warnings (#669) * Implement new method channels to avoid warnings Since the upgrade to Flutter 3.0 there were new method channels introduced. This commit implement a couple of them, to reduce the amount of warnings when running the project. Fixes #667 * Update restoration.go Co-authored-by: Pierre Champion | Drakirus --- application.go | 1 + navigation.go | 6 ++++++ platform.go | 14 ++++++++++++++ restoration.go | 19 +++++++++++++++++++ text-input.go | 2 ++ 5 files changed, 42 insertions(+) create mode 100644 restoration.go diff --git a/application.go b/application.go index 93a493ca..a436fee1 100644 --- a/application.go +++ b/application.go @@ -54,6 +54,7 @@ func NewApplication(opt ...Option) *Application { opt = append(opt, AddPlugin(defaultAccessibilityPlugin)) opt = append(opt, AddPlugin(defaultIsolatePlugin)) opt = append(opt, AddPlugin(defaultMousecursorPlugin)) + opt = append(opt, AddPlugin(defaultRestorationPlugin)) // apply all configs for _, o := range opt { diff --git a/navigation.go b/navigation.go index 405ec96f..91e93462 100644 --- a/navigation.go +++ b/navigation.go @@ -17,7 +17,13 @@ var defaultNavigationPlugin = &navigationPlugin{} func (p *navigationPlugin) InitPlugin(messenger plugin.BinaryMessenger) error { p.channel = plugin.NewMethodChannel(messenger, navigationChannelName, plugin.JSONMethodCodec{}) + // Ignored: This information isn't properly formated to set the window.SetTitle p.channel.HandleFuncSync("routeUpdated", func(_ interface{}) (interface{}, error) { return nil, nil }) + + // Currently ignored on platforms other than web + p.channel.HandleFuncSync("selectSingleEntryHistory", func(_ interface{}) (interface{}, error) { return nil, nil }) + p.channel.HandleFuncSync("routeInformationUpdated", func(_ interface{}) (interface{}, error) { return nil, nil }) + return nil } diff --git a/platform.go b/platform.go index a804ac74..fe5834aa 100644 --- a/platform.go +++ b/platform.go @@ -38,6 +38,8 @@ func (p *platformPlugin) InitPlugin(messenger plugin.BinaryMessenger) error { channel.HandleFuncSync("Clipboard.setData", p.handleClipboardSetData) channel.HandleFuncSync("Clipboard.getData", p.handleClipboardGetData) + channel.HandleFuncSync("Clipboard.hasStrings", p.handleClipboardHasString) + channel.HandleFuncSync("SystemNavigator.pop", p.handleSystemNavigatorPop) channel.HandleFunc("SystemChrome.setApplicationSwitcherDescription", p.handleWindowSetTitle) @@ -89,6 +91,18 @@ func (p *platformPlugin) handleClipboardGetData(arguments interface{}) (reply in return reply, nil } +func (p *platformPlugin) handleClipboardHasString(arguments interface{}) (reply interface{}, err error) { + var clipText string + clipText = p.window.GetClipboardString() + + reply = struct { + Value bool `json:"value"` + }{ + Value: len(clipText) > 0, + } + return reply, nil +} + func (p *platformPlugin) handleWindowSetTitle(arguments interface{}) (reply interface{}, err error) { // triggers flutter framework initialized callbacks for _, f := range p.flutterInitialized { diff --git a/restoration.go b/restoration.go new file mode 100644 index 00000000..714f2729 --- /dev/null +++ b/restoration.go @@ -0,0 +1,19 @@ +package flutter + +import ( + "github.com/go-flutter-desktop/go-flutter/plugin" +) + +type restorationPlugin struct{} + +// all hardcoded because theres not pluggable renderer system. +var defaultRestorationPlugin = &restorationPlugin{} + +var _ Plugin = &restorationPlugin{} // compile-time type check + +func (p *restorationPlugin) InitPlugin(messenger plugin.BinaryMessenger) error { + channel := plugin.NewMethodChannel(messenger, "flutter/restoration", plugin.StandardMethodCodec{}) + // Ignored: desktop doesn't need application "restoration" + channel.HandleFunc("get", func(_ interface{}) (interface{}, error) { return nil, nil }) + return nil +} diff --git a/text-input.go b/text-input.go index 6ff73ea7..fe475696 100644 --- a/text-input.go +++ b/text-input.go @@ -73,6 +73,8 @@ func (p *textinputPlugin) InitPlugin(messenger plugin.BinaryMessenger) error { }) // Ignored: This information is used by the flutter Web Engine p.channel.HandleFuncSync("TextInput.setStyle", func(_ interface{}) (interface{}, error) { return nil, nil }) + // Ignored: Used on MacOS to position accent selection menu + p.channel.HandleFuncSync("TextInput.setCaretRect", func(_ interface{}) (interface{}, error) { return nil, nil }) // Ignored: GLFW dosn't support setting the input method of the current cursor location #426 p.channel.HandleFuncSync("TextInput.setEditableSizeAndTransform", func(_ interface{}) (interface{}, error) { return nil, nil }) // Ignored: GLFW dosn't support setting the input method of the current cursor location #426