Skip to content

Commit

Permalink
all: update to Go 1.23 and fix a few things (#148)
Browse files Browse the repository at this point in the history
* meta: update to Go 1.23

* internal/ui: add iterator for `gtk.ListModel`s

* internal/ui: remove some deprecated GTK stuff

* internal/ui: remove more deprecated stuff

* cmd/trayscale: regenerate `default.pgo`

* meta: add `v0.13.2` to metainfo
  • Loading branch information
DeedleFake authored Aug 14, 2024
1 parent 8280b64 commit d0eda8a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 58 deletions.
Binary file modified cmd/trayscale/default.pgo
Binary file not shown.
6 changes: 6 additions & 0 deletions dev.deedles.Trayscale.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<content_rating type="oars-1.1" />

<releases>
<release version="v0.13.2" date="2024-08-14">
<description>
<ul>Update to Go 1.23.</ul>
<ul>Replace some deprecated code with the new API.</ul>
</description>
</release>
<release version="v0.13.1" date="2024-08-12">
<description>
<ul>Restructured Mullvad list to categorize per-country.</ul>
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module deedles.dev/trayscale

go 1.22.5
go 1.23.0

require (
deedles.dev/mk v0.1.0
Expand All @@ -10,13 +10,13 @@ require (
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
golang.org/x/net v0.28.0
gotest.tools/v3 v3.5.1
honnef.co/go/tools v0.4.7
honnef.co/go/tools v0.5.0
tailscale.com v1.70.0
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
github.com/KarpelesLab/weak v0.1.1 // indirect
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
Expand All @@ -39,7 +39,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/miekg/dns v1.1.61 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
Expand All @@ -66,7 +66,7 @@ require (
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
k8s.io/client-go v0.30.3 // indirect
k8s.io/client-go v0.31.0 // indirect
nhooyr.io/websocket v1.8.17 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
software.sslmate.com/src/go-pkcs12 v0.4.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ filippo.io/mkcert v1.4.4 h1:8eVbbwfVlaqUM7OwuftKc2nuYOoTDQWqsoXmzoXZdbc=
filippo.io/mkcert v1.4.4/go.mod h1:VyvOchVuAye3BoUsPUOOofKygVwLV2KQMVFJNRq+1dA=
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/KarpelesLab/weak v0.1.1 h1:fNnlPo3aypS9tBzoEQluY13XyUfd/eWaSE/vMvo9s4g=
github.com/KarpelesLab/weak v0.1.1/go.mod h1:pzXsWs5f2bf+fpgHayTlBE1qJpO3MpJKo5sRaLu1XNw=
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
Expand Down Expand Up @@ -74,8 +74,8 @@ github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs=
github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ=
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
Expand Down Expand Up @@ -144,12 +144,12 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0=
honnef.co/go/tools v0.5.0 h1:29uoiIormS3Z6R+t56STz/oI4v+mB51TSmEOdJPgRnE=
honnef.co/go/tools v0.5.0/go.mod h1:e9irvo83WDG9/irijV44wr3tbhcFeRnfpVlRqVwpzMs=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (a *App) startTS(ctx context.Context) error {
Reject: "_Cancel",
}.Show(a, func(accept bool) {
if accept {
gtk.ShowURI(&a.win.Window, status.Status.AuthURL, gdk.CURRENT_TIME)
gtk.NewURILauncher(status.Status.AuthURL).Launch(ctx, &a.win.Window, nil)
}
})
return nil
Expand Down Expand Up @@ -315,7 +315,7 @@ func (a *App) onAppActivate(ctx context.Context) {
return false
})
a.poller.Poll() <- struct{}{}
a.win.Show()
a.win.SetVisible(true)
}

func (a *App) initTray(ctx context.Context) {
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/dialogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (d Confirmation) Show(a *App, res func(bool)) {
res(response == "accept")
})

dialog.Show()
dialog.SetVisible(true)
}

type Prompt struct {
Expand Down Expand Up @@ -67,7 +67,7 @@ func (d Prompt) Show(a *App, initialValue string, res func(response, val string)
res(def, input.Buffer().Text())
})

dialog.Show()
dialog.SetVisible(true)
}

type Info struct {
Expand All @@ -87,5 +87,5 @@ func (d Info) Show(a *App, closed func()) {
})
}

dialog.Show()
dialog.SetVisible(true)
}
23 changes: 12 additions & 11 deletions internal/ui/peerpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,21 @@ func (page *PeerPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat

sendFileAction := gio.NewSimpleAction("sendfile", nil)
sendFileAction.ConnectActivate(func(p *glib.Variant) {
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionOpen, "", "")
fc.SetModal(true)
fc.SetSelectMultiple(true)
fc.ConnectResponse(func(id int) {
switch gtk.ResponseType(id) {
case gtk.ResponseAccept:
files := fc.Files()
for i := uint(0); i < files.NItems(); i++ {
file := files.Item(i).Cast().(*gio.File)
go a.pushFile(context.TODO(), peer.ID, file)
dialog := gtk.NewFileDialog()
dialog.SetModal(true)
dialog.OpenMultiple(context.TODO(), &a.win.Window, func(res gio.AsyncResulter) {
files, err := dialog.OpenMultipleFinish(res)
if err != nil {
if !errHasCode(err, int(gtk.DialogErrorDismissed)) {
slog.Error("open files", "err", err)
}
return
}

for file := range listModelObjects(files) {
go a.pushFile(context.TODO(), peer.ID, file.Cast().(*gio.File))
}
})
fc.Show()
})
actions.AddAction(sendFileAction)

Expand Down
39 changes: 12 additions & 27 deletions internal/ui/selfpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,6 @@ func (page *SelfPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat
actions := gio.NewSimpleActionGroup()
page.InsertActionGroup("peer", actions)

sendFileAction := gio.NewSimpleAction("sendfile", nil)
sendFileAction.ConnectActivate(func(p *glib.Variant) {
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionOpen, "", "")
fc.SetModal(true)
fc.SetSelectMultiple(true)
fc.ConnectResponse(func(id int) {
switch gtk.ResponseType(id) {
case gtk.ResponseAccept:
files := fc.Files()
for i := uint(0); i < files.NItems(); i++ {
file := files.Item(i).Cast().(*gio.File)
go a.pushFile(context.TODO(), peer.ID, file)
}
}
})
fc.Show()
})
actions.AddAction(sendFileAction)

page.addrRows.Parent = page.IPGroup
page.addrRows.New = func(ip netip.Addr) row[netip.Addr] {
row := addrRow{
Expand Down Expand Up @@ -189,16 +170,20 @@ func (page *SelfPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat
row.s.SetHasFrame(false)
row.s.SetTooltipText("Save")
row.s.ConnectClicked(func() {
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionSave, "", "")
fc.SetModal(true)
fc.SetCurrentName(row.file.Name)
fc.ConnectResponse(func(id int) {
switch gtk.ResponseType(id) {
case gtk.ResponseAccept:
go a.saveFile(context.TODO(), row.file.Name, fc.File())
dialog := gtk.NewFileDialog()
dialog.SetModal(true)
dialog.SetInitialName(row.file.Name)
dialog.Save(context.TODO(), &a.win.Window, func(res gio.AsyncResulter) {
file, err := dialog.SaveFinish(res)
if err != nil {
if !errHasCode(err, int(gtk.DialogErrorDismissed)) {
slog.Error("save file", "err", err)
}
return
}

go a.saveFile(context.TODO(), row.file.Name, file)
})
fc.Show()
})

row.d.SetMarginTop(12)
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (a *App) showPreferences() {
a.settings.Bind("tray-icon", win.UseTrayIconRow.Object, "active", gio.SettingsBindDefault)
a.settings.Bind("polling-interval", win.PollingIntervalAdjustment.Object, "value", gio.SettingsBindDefault)
win.SetTransientFor(&a.win.Window)
win.Show()
win.SetVisible(true)

a.app.AddWindow(&win.Window.Window)
}
Expand All @@ -103,7 +103,7 @@ func (a *App) showAbout() {
dialog.SetVersion(v)
}
dialog.SetTransientFor(&a.win.Window)
dialog.Show()
dialog.SetVisible(true)

a.app.AddWindow(&dialog.Window.Window)
}
Expand Down
25 changes: 25 additions & 0 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package ui

import (
"errors"
"io"
"iter"
"reflect"
"strings"
"time"

"deedles.dev/trayscale"
"deedles.dev/trayscale/internal/tsutil"
"github.com/diamondburned/gotk4/pkg/core/gerror"
"github.com/diamondburned/gotk4/pkg/gio/v2"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"tailscale.com/ipn/ipnstate"
"tailscale.com/types/opt"
Expand Down Expand Up @@ -140,3 +145,23 @@ func fillFromBuilder(into any, xml ...string) {

fillObjects(into, builder)
}

func listModelObjects(list *gio.ListModel) iter.Seq[*glib.Object] {
return func(yield func(*glib.Object) bool) {
length := list.NItems()
for i := uint(0); i < length; i++ {
item := list.Item(i)
if !yield(item) {
return
}
}
}
}

func errHasCode(err error, code int) bool {
var gerr *gerror.GError
if !errors.As(err, &gerr) {
return false
}
return gerr.ErrorCode() == code
}

0 comments on commit d0eda8a

Please sign in to comment.