Skip to content

all: update to Gio 0.6 and Go 1.22 #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ First, you must download the `plugin` package:
go get -u github.com/gioui-plugins/gio-plugins@latest
```

Now, you need to modify your event-loop, you must include `plugin.Install()` in your event-loop, before handling
Now, you need to modify your event-loop, you must include `gioplugins.Hijack(window)` in your event-loop, before handling
events:

```diff
for evt := range w.Events() { // Gio main event loop
+ plugin.Install(w, evt)
window := &app.Window{} // Gio window

for {
+ evt := gioplugins.Hijack(window) // Gio main event loop

switch evt := evt.(type) {
// ...
Expand All @@ -40,19 +42,31 @@ for evt := range w.Events() { // Gio main event loop
```

Each plugin has its own README.md file, explaining how to use it. In general, you can simple
use `nameOfPlugin.SomeOp{}.Add(gtx.Ops)`, similar of how you use `clipboard.ReadOp{}.Add(gtx.Ops)`, native from Gio.
use `nameOfPlugin.SomeOp{}.Add(gtx.Ops)`, similar of how you use `pointer.PassOp{}.Add(gtx.Ops)`, native
from Gio. Beginning with Gio 0.6, it also introduces `Command`, which is executed using `gtx.Execute`, you can
also use Commands, if the plugin supports it, for instance `gioplugins.Execute(gtx, gioshare.TextCmd{Text: "Hello, World!"})`,
similar to what you are familiar with `gtx.Execute(clipboard.WriteCmd{Text: "Hello, World!"})`.

Once `plugin.Install` is set, you can use the plugins as simple `op` commands. If you are unsure if the plugin is
working, you can use the `pingpong` package, which will return on `PongEvent` to the given Tag:
Once `gioplugins.Event` is set, you can use the plugins as simple `op` operations or `cmd` commands. If you are unsure
if the plugin is working, you can use the `pingpong` package, which will return on `PongEvent` to the given Tag:

```go
pingpong.PingOp{Tag: &something}.Add(gtx.Ops)

gioplugins.Execute(gtx, pingpong.PingCmd{Tag: &something})
```

You can receive responses using the `Tag`, as Gio-core operations:
> Note: It's uses `gioplugins.Execute` and not `gtx.Execute`!

You can receive responses using the `Tag`, similar Gio-core operations:

```go
for _, evt := range gtx.Events(&something) {
for {
evt, ok := gioplugins.Event(pingpong.Filter{Tag: &something})
if !ok {
break
}

if evt, ok := evt.(pingpong.PongEvent); ok {
fmt.Println(evt.Pong)
}
Expand All @@ -65,27 +79,24 @@ Of course, `pingpong` has no use in real-world applications, but it can be used

**We have few plugins available:**

| Name | Description | OS |
|----------------|------------------|-----------------|
| **[PingPong](https://github.com/gioui-plugins/gio-plugins/tree/main/pingpong)** | Test if the plugin system is working. | _Android, iOS, macOS, Windows, WebAssembly, Linux, FreeBSD_ |
| **[Share](https://github.com/gioui-plugins/gio-plugins/tree/main/share)** | Share text/links using the native share dialog. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[WebViewer](https://github.com/gioui-plugins/gio-plugins/tree/main/webviewer)** | Display in-app webview using the native webview implementation on each platform. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Hyperlink](https://github.com/gioui-plugins/gio-plugins/tree/main/hyperlink)** | Open hyperlinks in the default browser. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Explorer](https://github.com/gioui-plugins/gio-plugins/tree/main/explorer)** | Opens the native file-dialog, to read/write files. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Safedata](https://github.com/gioui-plugins/gio-plugins/tree/main/safedata)** | Read/Write files into the secure storage of the device. | _Android, iOS, macOS, Windows, WebAssembly_ |
| Name | Description | OS |
|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------|-------------------------------------------------------------|
| **[PingPong](https://github.com/gioui-plugins/gio-plugins/tree/main/pingpong)** | Test if the plugin system is working. | _Android, iOS, macOS, Windows, WebAssembly, Linux, FreeBSD_ |
| **[Share](https://github.com/gioui-plugins/gio-plugins/tree/main/share)** | Share text/links using the native share dialog. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[WebViewer](https://github.com/gioui-plugins/gio-plugins/tree/main/webviewer)** | Display in-app webview using the native webview implementation on each platform. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Hyperlink](https://github.com/gioui-plugins/gio-plugins/tree/main/hyperlink)** | Open hyperlinks in the default browser. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Explorer](https://github.com/gioui-plugins/gio-plugins/tree/main/explorer)** | Opens the native file-dialog, to read/write files. | _Android, iOS, macOS, Windows, WebAssembly_ |
| **[Safedata](https://github.com/gioui-plugins/gio-plugins/tree/main/safedata)** | Read/Write files into the secure storage of the device. | _Android, iOS, macOS, Windows, WebAssembly_ |

**We have few plugins planned:**

Some plugins are planned, but not yet implemented, follow the development at https://github.com/orgs/gioui-plugins/projects/1. Also,
consider send some 👍 on issues which mentions features that you like.



If you want to help, please open an issue or a PR! If you want to suggest a plugin, please open an issue.

-----------



### Creating a new plugin

If you want to create a new plugin, you can check the `pingpog` package, which is the simplest plugin available.
Expand All @@ -111,6 +122,18 @@ the Windows and Android as high-priority, and the WebAssembly as medium-priority
Furthermore, we don't have any plans to support Linux and FreeBSD due to the low market-share and the lack of API
standards.

| Priority | OS | Arch |
|----------|-------------|--------------|
| High | Windows | AMD64 |
| High | Android | ARM64, ARMv7 |
| Medium | WebAssembly | WASMv1 |
| Low | MacOS | ARM64, AMD64 |
| Low | iOS | ARM64 |
| Ignored | FreeBSD | - |
| Ignored | Linux | - |

Currently, some package might not work on some platforms, and some features might not be available on some platforms.

### Security

This package heavily uses `unsafe`, and as it suggest: it can be unsafe to use. We are not responsible for any damage
Expand Down
8 changes: 8 additions & 0 deletions explorer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../makefile.mk

$(eval $(call generate_java,explorer))
$(eval $(call generate_java,file))

android: java_explorer java_file

gen: android
14 changes: 7 additions & 7 deletions explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ If you want to use it without plugin, read the Freestanding instructions. We pro

## Plugin:

To open an single file, you can use `explorer.OpenFileOp`.
To open an single file, you can use `explorer.OpenFileCmd`.

That will open native File Dialog/File Picker. Once the file is selected by the end-user,
one `explorer.OpenFileEvent` will be sent to the given `Tag`.

```go
gioexplorer.OpenFileOp{
gioplugins.Execute(gtx, gioexplorer.OpenFileCmd{
Tag: yourTag,
Mimetype: []mimetype.MimeType{
{Extension: "png", Type: "image", Subtype: "png"},
Expand All @@ -42,21 +42,21 @@ gioexplorer.OpenFileOp{
{Extension: "gif", Type: "image", Subtype: "gif"},
{Extension: "webp", Type: "image", Subtype: "webp"},
},
}.Add(gtx.Ops)
})
```

### Operations:

Operations must be added with `.Add(gtx.Ops)` method. The operation will be executed at the end of the frame.
Operations must be added with `gtx.Execute` method. The operation will be executed at the end of the frame.

- `gioexplorer.OpenFileOp`:
- `gioexplorer.OpenFileCmd`:
- Opens the native file dialog to open/import a single file.
- `gioexplorer.SaveFileOp`:
- `gioexplorer.SaveFileCmd`:
- Open the native file dialog to save/export a single file.

## Events:

Events are response sent using the `Tag` and should be handled with `gtx.Events()`.
Events are response sent using the `Tag` and should be handled with `gioplugins.Event()`.

- `gioexplorer.OpenFileEvent`:
- Sent to `Tag` when the user chooses the file to be read/open. That event contains one io.ReadCloser.
Expand Down
20 changes: 20 additions & 0 deletions explorer/demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include ../../makefile.mk

js:
$(GO) run $(GOGIO) -target js -o ./wasm .

android:
PATH=$(ANDROID_JAVA_ROOT) java -version
PATH=$(ANDROID_JAVA_ROOT):$(PATH) ANDROID_SDK_ROOT=$(ANDROID_SDK_ROOT) $(GO) run $(GOGIO) -target android -o ./android.apk .

ios:
$(GO) run $(GOGIO) -target ios -o ./ios.app .

windows:
$(GO) run $(GOGIO) -target windows -o ./windows.exe .

macos:
$(GO) run $(GOGIO) -target macos -arch arm64 -o ./macos_arm64.app .
$(GO) run $(GOGIO) -target macos -arch amd64 -o ./macos_intel.app .

all: js android ios windows macos
19 changes: 13 additions & 6 deletions explorer/demo/go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
module demo

go 1.19
go 1.22

replace gioui.org => ../../../gio

replace github.com/gioui-plugins/gio-plugins => ../../

require (
gioui.org v0.0.0-20230425023356-bba91263b077
gioui.org v0.6.1-0.20240607083507-1151eac07d84
github.com/gioui-plugins/gio-plugins v0.0.0-00010101000000-000000000000
golang.org/x/image v0.7.0
)

require (
gioui.org/cmd v0.0.0-20240602111522-ddde16a09e12 // indirect
gioui.org/cpu v0.0.0-20220412190645-f1e9e8c3b1f7 // indirect
gioui.org/shader v1.0.6 // indirect
gioui.org/shader v1.0.8 // indirect
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 // indirect
github.com/go-text/typesetting v0.0.0-20230413204129-b4f0492bf7ae // indirect
github.com/akavel/rsrc v0.10.1 // indirect
github.com/go-text/typesetting v0.1.1 // indirect
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
golang.org/x/exp/shiny v0.0.0-20220921164117-439092de6870 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
)
30 changes: 21 additions & 9 deletions explorer/demo/go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY=
gioui.org v0.0.0-20230425023356-bba91263b077 h1:BfZ3LodNX41vEUJI2dWHkFsZe+NVEHSTv8TceMyVe0M=
gioui.org v0.0.0-20230425023356-bba91263b077/go.mod h1:8CFQM/4LurRd9G3NUYdacFb9j2pK0LrAyVO2mAZo4mw=
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
gioui.org/cmd v0.0.0-20240602111522-ddde16a09e12 h1:AI02AXvn82PSxFwf6RFc6Xlvs4GstWB2qzMw4BTzzQk=
gioui.org/cmd v0.0.0-20240602111522-ddde16a09e12/go.mod h1:ZlKsrpku0BzRpWGTSsHBFbXRhubrGHzczyTuWMEJzFs=
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
gioui.org/cpu v0.0.0-20220412190645-f1e9e8c3b1f7 h1:tNJdnP5CgM39PRc+KWmBRRYX/zJ+rd5XaYxY5d5veqA=
gioui.org/cpu v0.0.0-20220412190645-f1e9e8c3b1f7/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
gioui.org/shader v1.0.6 h1:cvZmU+eODFR2545X+/8XucgZdTtEjR3QWW6W65b0q5Y=
gioui.org/shader v1.0.6/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr9PPB5aw8SjcOWWila7ZI=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
github.com/go-text/typesetting v0.0.0-20230413204129-b4f0492bf7ae h1:LCcaQgYrnS+sx9Tc3oGUvbRBRt+5oFnKWakaxeAvNVI=
github.com/go-text/typesetting v0.0.0-20230413204129-b4f0492bf7ae/go.mod h1:KmrpWuSMFcO2yjmyhGpnBGQHSKAoEgMTSSzvLDzCuEA=
github.com/go-text/typesetting-utils v0.0.0-20230412163830-89e4bcfa3ecc h1:9Kf84pnrmmjdRzZIkomfjowmGUhHs20jkrWYw/I6CYc=
github.com/akavel/rsrc v0.10.1 h1:hCCPImjmFKVNGpeLZyTDRHEFC283DzyTXTo0cO0Rq9o=
github.com/akavel/rsrc v0.10.1/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand All @@ -22,31 +26,39 @@ golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Loading