Skip to content

Commit

Permalink
Implement new method channels to avoid warnings (#669)
Browse files Browse the repository at this point in the history
* 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 <pierrescalade@gmail.com>
  • Loading branch information
bltavares and Pierre Champion | Drakirus committed Jul 24, 2022
1 parent 34eaff6 commit f538461
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions application.go
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions navigation.go
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions platform.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions 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
}
2 changes: 2 additions & 0 deletions text-input.go
Expand Up @@ -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
Expand Down

0 comments on commit f538461

Please sign in to comment.