From ee20cdee330144ad288b708f4dd96f5858524ff3 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Sat, 4 May 2024 22:09:13 -0400 Subject: [PATCH] internal/ui: fix Mullvad and self pages disappearing from the list when re-opening the window (#118) * internal/ui: remove `Page.Init()` * internal/ui: fix Mullvad and self pages disappearing after opening from the tray icon * meta: add v0.12.3 to metainfo And v0.12.2, as it was missing for some reason. Strange. --- dev.deedles.Trayscale.metainfo.xml | 10 ++++++++++ internal/ui/app.go | 11 +++++------ internal/ui/mullvadpage.go | 5 +++-- internal/ui/page.go | 25 +++++++++---------------- internal/ui/peerpage.go | 5 +++-- internal/ui/selfpage.go | 5 +++-- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/dev.deedles.Trayscale.metainfo.xml b/dev.deedles.Trayscale.metainfo.xml index af9fd66..7169e75 100644 --- a/dev.deedles.Trayscale.metainfo.xml +++ b/dev.deedles.Trayscale.metainfo.xml @@ -54,6 +54,16 @@ + + +
    Fix self and Mullvad pages disappearing when re-opening the window.
+
+
+ + +
    Nicer sorting and display of Mullvad nodes.
+
+
    Strip debugging symbols to reduce binary size.
diff --git a/internal/ui/app.go b/internal/ui/app.go index 4480e6d..f262b47 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -137,16 +137,14 @@ func (a *App) updatePeers(status tsutil.Status) { stack := a.win.PeersStack if a.selfPage == nil { - a.selfPage = &stackPage{page: NewSelfPage()} - a.selfPage.Init(a, status.Status.Self, status) + a.selfPage = newStackPage(a, NewSelfPage(a, status.Status.Self, status)) } a.selfPage.Update(a, status.Status.Self, status) switch { case tsutil.CanMullvad(status.Status.Self): if a.mullvadPage == nil { - a.mullvadPage = &stackPage{page: NewMullvadPage()} - a.mullvadPage.Init(a, nil, status) + a.mullvadPage = newStackPage(a, NewMullvadPage(a, status)) } a.mullvadPage.Update(a, nil, status) case a.mullvadPage != nil: @@ -171,8 +169,7 @@ func (a *App) updatePeers(status tsutil.Status) { page, ok := a.peerPages[p] if !ok { - page = &stackPage{page: NewPeerPage()} - page.Init(a, peerStatus, status) + page = newStackPage(a, NewPeerPage(a, peerStatus, status)) a.peerPages[p] = page } @@ -344,6 +341,8 @@ func (a *App) onAppActivate(ctx context.Context) { a.win.ConnectCloseRequest(func() bool { clear(a.peerPages) + a.mullvadPage = nil + a.selfPage = nil a.win = nil return false }) diff --git a/internal/ui/mullvadpage.go b/internal/ui/mullvadpage.go index 1fe6bc0..c7463a3 100644 --- a/internal/ui/mullvadpage.go +++ b/internal/ui/mullvadpage.go @@ -28,9 +28,10 @@ type MullvadPage struct { exitNodeRows rowManager[*ipnstate.PeerStatus] } -func NewMullvadPage() *MullvadPage { +func NewMullvadPage(a *App, status tsutil.Status) *MullvadPage { var page MullvadPage fillFromBuilder(&page, mullvadPageXML) + page.init(a, status) return &page } @@ -46,7 +47,7 @@ func (page *MullvadPage) Name() string { return page.name } -func (page *MullvadPage) Init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { +func (page *MullvadPage) init(a *App, status tsutil.Status) { page.name = "Mullvad Exit Nodes" page.exitNodeRows.Parent = page.ExitNodesGroup diff --git a/internal/ui/page.go b/internal/ui/page.go index 9ee9a74..6469260 100644 --- a/internal/ui/page.go +++ b/internal/ui/page.go @@ -18,14 +18,6 @@ type Page interface { // Name returns a displayable name for the page. Name() string - // Init performs first-time initialization of the page, i.e. setting - // values to their defaults and whatnot. It should not call Update - // unless doing so is idempotent, though even then it's better not - // to. - // - // TODO: Remove this and just do it in constructors instead. - Init(*App, *ipnstate.PeerStatus, tsutil.Status) - // Update performs an update of the UI to match new state. Update(*App, *ipnstate.PeerStatus, tsutil.Status) } @@ -35,14 +27,15 @@ type stackPage struct { stackPage *gtk.StackPage } -func (page *stackPage) Init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { - page.page.Init(a, peer, status) - - page.stackPage = a.win.PeersStack.AddTitled( - page.page.Root(), - page.page.ID(), - page.page.Name(), - ) +func newStackPage(a *App, page Page) *stackPage { + return &stackPage{ + page: page, + stackPage: a.win.PeersStack.AddTitled( + page.Root(), + page.ID(), + page.Name(), + ), + } } func (page *stackPage) Update(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { diff --git a/internal/ui/peerpage.go b/internal/ui/peerpage.go index 3d50ada..cde941c 100644 --- a/internal/ui/peerpage.go +++ b/internal/ui/peerpage.go @@ -75,9 +75,10 @@ type PeerPage struct { routeRows rowManager[enum[netip.Prefix]] } -func NewPeerPage() *PeerPage { +func NewPeerPage(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) *PeerPage { var page PeerPage fillFromBuilder(&page, peerPageXML) + page.init(a, peer, status) return &page } @@ -93,7 +94,7 @@ func (page *PeerPage) Name() string { return page.name } -func (page *PeerPage) Init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { +func (page *PeerPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { page.peer = peer actions := gio.NewSimpleActionGroup() diff --git a/internal/ui/selfpage.go b/internal/ui/selfpage.go index 8bd5221..7a8b3df 100644 --- a/internal/ui/selfpage.go +++ b/internal/ui/selfpage.go @@ -72,9 +72,10 @@ type SelfPage struct { fileRows rowManager[apitype.WaitingFile] } -func NewSelfPage() *SelfPage { +func NewSelfPage(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) *SelfPage { var page SelfPage fillFromBuilder(&page, selfPageXML) + page.init(a, peer, status) return &page } @@ -90,7 +91,7 @@ func (page *SelfPage) Name() string { return page.name } -func (page *SelfPage) Init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { +func (page *SelfPage) init(a *App, peer *ipnstate.PeerStatus, status tsutil.Status) { page.peer = peer actions := gio.NewSimpleActionGroup()