Skip to content

Commit 99db278

Browse files
committed
Add initial implementation for system navigator pop event
1 parent a633350 commit 99db278

File tree

8 files changed

+212
-9
lines changed

8 files changed

+212
-9
lines changed

application.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ func NewApplication(opt ...Option) *Application {
3636
config: defaultApplicationConfig,
3737
}
3838

39-
// The platformPlugin and textinputPlugin are currently hardcoded as we have
40-
// a hard link with GLFW. The plugins must be singleton and are accessed
41-
// directly from the flutter package to wire up with glfw. If there's going
42-
// to be a renderer interface, it's init would replace this configuration.
39+
// The platformPlugin, textinputPlugin, etc. are currently hardcoded as we
40+
// have a hard link with GLFW. The plugins must be singleton and are
41+
// accessed directly from the flutter package to wire up with glfw. If
42+
// there's going to be a renderer interface, it's init would replace this
43+
// configuration.
4344
opt = append(opt, AddPlugin(defaultNavigationPlugin))
4445
opt = append(opt, AddPlugin(defaultPlatformPlugin))
4546
opt = append(opt, AddPlugin(defaultTextinputPlugin))
47+
opt = append(opt, AddPlugin(defaultLifecyclePlugin))
4648

4749
// apply all configs
4850
for _, o := range opt {
@@ -180,6 +182,8 @@ func (a *Application) Run() error {
180182
a.window.SetKeyCallback(defaultTextinputPlugin.glfwKeyCallback)
181183
a.window.SetCharCallback(defaultTextinputPlugin.glfwCharCallback)
182184

185+
a.window.SetIconifyCallback(defaultLifecyclePlugin.glfwIconifyCallback)
186+
183187
a.window.SetCursorEnterCallback(m.glfwCursorEnterCallback)
184188
a.window.SetCursorPosCallback(m.glfwCursorPosCallback)
185189
a.window.SetMouseButtonCallback(m.glfwMouseButtonCallback)

go.mod

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,25 @@ module github.com/go-flutter-desktop/go-flutter
33
go 1.12
44

55
require (
6+
github.com/coreos/etcd v3.3.13+incompatible // indirect
7+
github.com/coreos/go-semver v0.3.0 // indirect
8+
github.com/daaku/go.zipexe v1.0.1 // indirect
69
github.com/davecgh/go-spew v1.1.1
10+
github.com/go-flutter-desktop/hover v0.15.0 // indirect
711
github.com/go-gl/glfw v0.0.0-20190217072633-93b30450e032
12+
github.com/magiconair/properties v1.8.1 // indirect
13+
github.com/nkovacs/streamquote v1.0.0 // indirect
14+
github.com/otiai10/copy v1.0.1 // indirect
15+
github.com/pelletier/go-toml v1.4.0 // indirect
816
github.com/pkg/errors v0.8.1
17+
github.com/spf13/afero v1.2.2 // indirect
18+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
19+
github.com/stretchr/objx v0.2.0 // indirect
920
github.com/stretchr/testify v1.3.0
21+
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
22+
golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
23+
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb // indirect
24+
golang.org/x/text v0.3.2 // indirect
25+
golang.org/x/tools v0.0.0-20190517183331-d88f79806bbd // indirect
26+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
1027
)

go.sum

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,79 @@
1+
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
4+
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
5+
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
6+
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
7+
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
8+
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
9+
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
10+
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
11+
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
12+
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
13+
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
14+
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
15+
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
116
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
217
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
318
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
19+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
20+
github.com/go-flutter-desktop/hover v0.15.0 h1:c9aOo4xRJhJo7AdedZBARtZYll0qoygBcrqU6EpZ3aE=
21+
github.com/go-flutter-desktop/hover v0.15.0/go.mod h1:ysBOepB0fgxBJqKH3F1YXCE1GjX/n3kFswHR60NfTq4=
422
github.com/go-gl/glfw v0.0.0-20190217072633-93b30450e032 h1:WUDJN6o1AZlnNR0UZ11zsr0Quh44CV7svcg6VzEsySc=
523
github.com/go-gl/glfw v0.0.0-20190217072633-93b30450e032/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
24+
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
25+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
26+
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
27+
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
28+
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
29+
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
30+
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
31+
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
32+
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
33+
github.com/otiai10/copy v1.0.1 h1:gtBjD8aq4nychvRZ2CyJvFWAw0aja+VHazDdruZKGZA=
34+
github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc=
35+
github.com/otiai10/mint v1.2.3/go.mod h1:YnfyPNhBvnY8bW4SGQHCs/aAFhkgySlMZbrF5U0bOVw=
36+
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
37+
github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
638
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
739
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
840
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
941
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
42+
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
43+
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
44+
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
45+
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
46+
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
47+
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
48+
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
49+
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
50+
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
51+
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
1052
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
53+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
54+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
1155
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
1256
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
57+
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
58+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
59+
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
60+
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
61+
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
62+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
63+
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
64+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
65+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
66+
golang.org/x/net v0.0.0-20190514140710-3ec191127204/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
67+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
68+
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
69+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
70+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
71+
golang.org/x/sys v0.0.0-20190516110030-61b9204099cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
72+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
73+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
74+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
75+
golang.org/x/tools v0.0.0-20190517183331-d88f79806bbd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
76+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
77+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
78+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
79+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

lifecycle.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package flutter
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/go-flutter-desktop/go-flutter/plugin"
7+
"github.com/go-gl/glfw/v3.2/glfw"
8+
)
9+
10+
const lifecycleChannelName = "flutter/lifecycle"
11+
12+
// lifecyclePlugin implements flutter.Plugin and handles method calls to the
13+
// flutter/lifecycle channel.
14+
type lifecyclePlugin struct {
15+
channel *plugin.BasicMessageChannel
16+
}
17+
18+
// all hardcoded because theres not pluggable renderer system.
19+
var defaultLifecyclePlugin = &lifecyclePlugin{}
20+
21+
var _ Plugin = &lifecyclePlugin{} // compile-time type check
22+
23+
func (p *lifecyclePlugin) InitPlugin(messenger plugin.BinaryMessenger) error {
24+
p.channel = plugin.NewBasicMessageChannel(messenger, lifecycleChannelName, plugin.StringCodec{})
25+
return nil
26+
}
27+
28+
func (p *lifecyclePlugin) glfwIconifyCallback(w *glfw.Window, iconified bool) {
29+
var state string
30+
switch iconified {
31+
case true:
32+
state = "AppLifecycleState.paused"
33+
case false:
34+
state = "AppLifecycleState.resumed"
35+
}
36+
_, err := p.channel.Send(state)
37+
if err != nil {
38+
fmt.Printf("go-flutter: Failed to send lifecycle event %s: %v\n", state, err)
39+
}
40+
}

navigation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
const navigationChannelName = "flutter/navigation"
88

99
// navigationPlugin implements flutter.Plugin and handles method calls to the
10-
// flutter/platform channel.
10+
// flutter/navigation channel.
1111
type navigationPlugin struct {
1212
channel *plugin.MethodChannel
1313
}

platform.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import (
1313
// platformPlugin implements flutter.Plugin and handles method calls to the
1414
// flutter/platform channel.
1515
type platformPlugin struct {
16+
popBehavior PopBehaviorKind
17+
1618
messenger plugin.BinaryMessenger
1719
glfwTasker *tasker.Tasker
1820
window *glfw.Window
1921
channel *plugin.MethodChannel
2022
}
2123

2224
// hardcoded because there is no swappable renderer interface.
23-
var defaultPlatformPlugin = &platformPlugin{}
25+
var defaultPlatformPlugin = &platformPlugin{
26+
popBehavior: PopBehaviorNone,
27+
}
2428

2529
var _ Plugin = &platformPlugin{} // compile-time type check
2630
var _ PluginGLFW = &platformPlugin{} // compile-time type check
@@ -37,6 +41,7 @@ func (p *platformPlugin) InitPluginGLFW(window *glfw.Window) (err error) {
3741
p.channel.HandleFunc("Clipboard.setData", p.handleClipboardSetData)
3842
p.channel.HandleFunc("Clipboard.getData", p.handleClipboardGetData)
3943
p.channel.HandleFunc("SystemChrome.setApplicationSwitcherDescription", p.handleWindowSetTitle)
44+
p.channel.HandleFunc("SystemNavigator.pop", p.handleSystemNavigatorPop)
4045

4146
return nil
4247
}

plugin/method-channel.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ func (m *MethodChannel) InvokeMethod(name string, arguments interface{}) (result
5555
if err != nil {
5656
return nil, errors.Wrap(err, "failed to send methodcall")
5757
}
58+
// TODO(GeertJohan): InvokeMethod may not return any JSON. In Java this is
59+
// handled by not having a callback handler, which means no reponse is
60+
// expected and reponse is never unmarshalled. We should perhaps define
61+
// InvokeMethod(..) and InovkeMethodNoResponse(..) to avoid errors when no
62+
// response is given.
63+
// https://github.com/go-flutter-desktop/go-flutter/issues/141
5864
result, err = m.methodCodec.DecodeEnvelope(encodedReply)
59-
if flutterError, ok := err.(*FlutterError); ok {
60-
return nil, flutterError
61-
}
6265
if err != nil {
6366
return nil, err
6467
}

pop.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package flutter
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/pkg/errors"
7+
)
8+
9+
// PopBehaviorKind defines how an application should handle the navigation pop
10+
// event from the flutter side.
11+
type PopBehaviorKind int
12+
13+
const (
14+
// PopBehaviorNone means the system navigation pop event is ignored.
15+
PopBehaviorNone PopBehaviorKind = iota
16+
// PopBehaviorHide hides the application window on a system navigation pop
17+
// event.
18+
PopBehaviorHide
19+
// PopBehaviorIconify iconifies the application window on a system
20+
// navigation pop event.
21+
PopBehaviorIconify
22+
// PopBehaviorClose closes the application on a system navigation pop event.
23+
PopBehaviorClose
24+
)
25+
26+
// PopBehavior sets the PopBehavior on the application
27+
func PopBehavior(popBehavior PopBehaviorKind) Option {
28+
return func(c *config) {
29+
// TODO: this is a workarround because there is no renderer interface
30+
// yet. We rely on a platform plugin singleton to handle events from the
31+
// flutter side. Should go via Application and renderer abstraction
32+
// layer.
33+
//
34+
// Downside of this workarround is that it will configure the pop
35+
// behavior for all Application's within the same Go process.
36+
defaultPlatformPlugin.popBehavior = popBehavior
37+
}
38+
}
39+
40+
func (p *platformPlugin) handleSystemNavigatorPop(arguments interface{}) (reply interface{}, err error) {
41+
switch p.popBehavior {
42+
case PopBehaviorNone:
43+
return nil, nil
44+
case PopBehaviorHide:
45+
p.glfwTasker.Do(func() {
46+
p.window.Hide()
47+
})
48+
return nil, nil
49+
case PopBehaviorIconify:
50+
var err error
51+
p.glfwTasker.Do(func() {
52+
err = p.window.Iconify()
53+
})
54+
if err != nil {
55+
fmt.Printf("go-flutter: error on iconifying window: %v\n", err)
56+
return nil, errors.Wrap(err, "failed to iconify window")
57+
}
58+
return nil, nil
59+
case PopBehaviorClose:
60+
p.glfwTasker.Do(func() {
61+
p.window.SetShouldClose(true)
62+
})
63+
return nil, nil
64+
default:
65+
return nil, errors.Errorf("unknown pop behavior %T not implemented by platform handler", p.popBehavior)
66+
}
67+
}

0 commit comments

Comments
 (0)