Skip to content

Commit d0eda8a

Browse files
authored
all: update to Go 1.23 and fix a few things (#148)
* 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
1 parent 8280b64 commit d0eda8a

10 files changed

+75
-58
lines changed

cmd/trayscale/default.pgo

-112 Bytes
Binary file not shown.

dev.deedles.Trayscale.metainfo.xml

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
<content_rating type="oars-1.1" />
5555

5656
<releases>
57+
<release version="v0.13.2" date="2024-08-14">
58+
<description>
59+
<ul>Update to Go 1.23.</ul>
60+
<ul>Replace some deprecated code with the new API.</ul>
61+
</description>
62+
</release>
5763
<release version="v0.13.1" date="2024-08-12">
5864
<description>
5965
<ul>Restructured Mullvad list to categorize per-country.</ul>

go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module deedles.dev/trayscale
22

3-
go 1.22.5
3+
go 1.23.0
44

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

1717
require (
1818
filippo.io/edwards25519 v1.1.0 // indirect
19-
github.com/BurntSushi/toml v1.4.0 // indirect
19+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
2020
github.com/KarpelesLab/weak v0.1.1 // indirect
2121
github.com/akutz/memconn v0.1.0 // indirect
2222
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
@@ -39,7 +39,7 @@ require (
3939
github.com/mattn/go-isatty v0.0.20 // indirect
4040
github.com/mdlayher/netlink v1.7.2 // indirect
4141
github.com/mdlayher/socket v0.5.1 // indirect
42-
github.com/miekg/dns v1.1.61 // indirect
42+
github.com/miekg/dns v1.1.62 // indirect
4343
github.com/mitchellh/go-ps v1.0.0 // indirect
4444
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
4545
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
@@ -66,7 +66,7 @@ require (
6666
golang.org/x/time v0.6.0 // indirect
6767
golang.org/x/tools v0.24.0 // indirect
6868
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
69-
k8s.io/client-go v0.30.3 // indirect
69+
k8s.io/client-go v0.31.0 // indirect
7070
nhooyr.io/websocket v1.8.17 // indirect
7171
sigs.k8s.io/yaml v1.4.0 // indirect
7272
software.sslmate.com/src/go-pkcs12 v0.4.0 // indirect

go.sum

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ filippo.io/mkcert v1.4.4 h1:8eVbbwfVlaqUM7OwuftKc2nuYOoTDQWqsoXmzoXZdbc=
66
filippo.io/mkcert v1.4.4/go.mod h1:VyvOchVuAye3BoUsPUOOofKygVwLV2KQMVFJNRq+1dA=
77
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
88
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
9-
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
10-
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
9+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
10+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
1111
github.com/KarpelesLab/weak v0.1.1 h1:fNnlPo3aypS9tBzoEQluY13XyUfd/eWaSE/vMvo9s4g=
1212
github.com/KarpelesLab/weak v0.1.1/go.mod h1:pzXsWs5f2bf+fpgHayTlBE1qJpO3MpJKo5sRaLu1XNw=
1313
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
@@ -74,8 +74,8 @@ github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/
7474
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
7575
github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=
7676
github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ=
77-
github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs=
78-
github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ=
77+
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
78+
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
7979
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
8080
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
8181
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
@@ -144,12 +144,12 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
144144
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
145145
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
146146
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
147-
honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
148-
honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0=
147+
honnef.co/go/tools v0.5.0 h1:29uoiIormS3Z6R+t56STz/oI4v+mB51TSmEOdJPgRnE=
148+
honnef.co/go/tools v0.5.0/go.mod h1:e9irvo83WDG9/irijV44wr3tbhcFeRnfpVlRqVwpzMs=
149149
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
150150
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
151-
k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
152-
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
151+
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
152+
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
153153
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
154154
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
155155
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=

internal/ui/app.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (a *App) startTS(ctx context.Context) error {
225225
Reject: "_Cancel",
226226
}.Show(a, func(accept bool) {
227227
if accept {
228-
gtk.ShowURI(&a.win.Window, status.Status.AuthURL, gdk.CURRENT_TIME)
228+
gtk.NewURILauncher(status.Status.AuthURL).Launch(ctx, &a.win.Window, nil)
229229
}
230230
})
231231
return nil
@@ -315,7 +315,7 @@ func (a *App) onAppActivate(ctx context.Context) {
315315
return false
316316
})
317317
a.poller.Poll() <- struct{}{}
318-
a.win.Show()
318+
a.win.SetVisible(true)
319319
}
320320

321321
func (a *App) initTray(ctx context.Context) {

internal/ui/dialogs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (d Confirmation) Show(a *App, res func(bool)) {
2424
res(response == "accept")
2525
})
2626

27-
dialog.Show()
27+
dialog.SetVisible(true)
2828
}
2929

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

70-
dialog.Show()
70+
dialog.SetVisible(true)
7171
}
7272

7373
type Info struct {
@@ -87,5 +87,5 @@ func (d Info) Show(a *App, closed func()) {
8787
})
8888
}
8989

90-
dialog.Show()
90+
dialog.SetVisible(true)
9191
}

internal/ui/peerpage.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,21 @@ func (page *PeerPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat
101101

102102
sendFileAction := gio.NewSimpleAction("sendfile", nil)
103103
sendFileAction.ConnectActivate(func(p *glib.Variant) {
104-
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionOpen, "", "")
105-
fc.SetModal(true)
106-
fc.SetSelectMultiple(true)
107-
fc.ConnectResponse(func(id int) {
108-
switch gtk.ResponseType(id) {
109-
case gtk.ResponseAccept:
110-
files := fc.Files()
111-
for i := uint(0); i < files.NItems(); i++ {
112-
file := files.Item(i).Cast().(*gio.File)
113-
go a.pushFile(context.TODO(), peer.ID, file)
104+
dialog := gtk.NewFileDialog()
105+
dialog.SetModal(true)
106+
dialog.OpenMultiple(context.TODO(), &a.win.Window, func(res gio.AsyncResulter) {
107+
files, err := dialog.OpenMultipleFinish(res)
108+
if err != nil {
109+
if !errHasCode(err, int(gtk.DialogErrorDismissed)) {
110+
slog.Error("open files", "err", err)
114111
}
112+
return
113+
}
114+
115+
for file := range listModelObjects(files) {
116+
go a.pushFile(context.TODO(), peer.ID, file.Cast().(*gio.File))
115117
}
116118
})
117-
fc.Show()
118119
})
119120
actions.AddAction(sendFileAction)
120121

internal/ui/selfpage.go

+12-27
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,6 @@ func (page *SelfPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat
9494
actions := gio.NewSimpleActionGroup()
9595
page.InsertActionGroup("peer", actions)
9696

97-
sendFileAction := gio.NewSimpleAction("sendfile", nil)
98-
sendFileAction.ConnectActivate(func(p *glib.Variant) {
99-
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionOpen, "", "")
100-
fc.SetModal(true)
101-
fc.SetSelectMultiple(true)
102-
fc.ConnectResponse(func(id int) {
103-
switch gtk.ResponseType(id) {
104-
case gtk.ResponseAccept:
105-
files := fc.Files()
106-
for i := uint(0); i < files.NItems(); i++ {
107-
file := files.Item(i).Cast().(*gio.File)
108-
go a.pushFile(context.TODO(), peer.ID, file)
109-
}
110-
}
111-
})
112-
fc.Show()
113-
})
114-
actions.AddAction(sendFileAction)
115-
11697
page.addrRows.Parent = page.IPGroup
11798
page.addrRows.New = func(ip netip.Addr) row[netip.Addr] {
11899
row := addrRow{
@@ -189,16 +170,20 @@ func (page *SelfPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Stat
189170
row.s.SetHasFrame(false)
190171
row.s.SetTooltipText("Save")
191172
row.s.ConnectClicked(func() {
192-
fc := gtk.NewFileChooserNative("", &a.win.Window, gtk.FileChooserActionSave, "", "")
193-
fc.SetModal(true)
194-
fc.SetCurrentName(row.file.Name)
195-
fc.ConnectResponse(func(id int) {
196-
switch gtk.ResponseType(id) {
197-
case gtk.ResponseAccept:
198-
go a.saveFile(context.TODO(), row.file.Name, fc.File())
173+
dialog := gtk.NewFileDialog()
174+
dialog.SetModal(true)
175+
dialog.SetInitialName(row.file.Name)
176+
dialog.Save(context.TODO(), &a.win.Window, func(res gio.AsyncResulter) {
177+
file, err := dialog.SaveFinish(res)
178+
if err != nil {
179+
if !errHasCode(err, int(gtk.DialogErrorDismissed)) {
180+
slog.Error("save file", "err", err)
181+
}
182+
return
199183
}
184+
185+
go a.saveFile(context.TODO(), row.file.Name, file)
200186
})
201-
fc.Show()
202187
})
203188

204189
row.d.SetMarginTop(12)

internal/ui/settings.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (a *App) showPreferences() {
8383
a.settings.Bind("tray-icon", win.UseTrayIconRow.Object, "active", gio.SettingsBindDefault)
8484
a.settings.Bind("polling-interval", win.PollingIntervalAdjustment.Object, "value", gio.SettingsBindDefault)
8585
win.SetTransientFor(&a.win.Window)
86-
win.Show()
86+
win.SetVisible(true)
8787

8888
a.app.AddWindow(&win.Window.Window)
8989
}
@@ -103,7 +103,7 @@ func (a *App) showAbout() {
103103
dialog.SetVersion(v)
104104
}
105105
dialog.SetTransientFor(&a.win.Window)
106-
dialog.Show()
106+
dialog.SetVisible(true)
107107

108108
a.app.AddWindow(&dialog.Window.Window)
109109
}

internal/ui/ui.go

+25
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package ui
22

33
import (
4+
"errors"
45
"io"
6+
"iter"
57
"reflect"
68
"strings"
79
"time"
810

911
"deedles.dev/trayscale"
1012
"deedles.dev/trayscale/internal/tsutil"
13+
"github.com/diamondburned/gotk4/pkg/core/gerror"
14+
"github.com/diamondburned/gotk4/pkg/gio/v2"
15+
"github.com/diamondburned/gotk4/pkg/glib/v2"
1116
"github.com/diamondburned/gotk4/pkg/gtk/v4"
1217
"tailscale.com/ipn/ipnstate"
1318
"tailscale.com/types/opt"
@@ -140,3 +145,23 @@ func fillFromBuilder(into any, xml ...string) {
140145

141146
fillObjects(into, builder)
142147
}
148+
149+
func listModelObjects(list *gio.ListModel) iter.Seq[*glib.Object] {
150+
return func(yield func(*glib.Object) bool) {
151+
length := list.NItems()
152+
for i := uint(0); i < length; i++ {
153+
item := list.Item(i)
154+
if !yield(item) {
155+
return
156+
}
157+
}
158+
}
159+
}
160+
161+
func errHasCode(err error, code int) bool {
162+
var gerr *gerror.GError
163+
if !errors.As(err, &gerr) {
164+
return false
165+
}
166+
return gerr.ErrorCode() == code
167+
}

0 commit comments

Comments
 (0)