Skip to content

Commit

Permalink
internal/ui: fix Mullvad and self pages disappearing from the list wh…
Browse files Browse the repository at this point in the history
…en 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.
  • Loading branch information
DeedleFake authored May 5, 2024
1 parent 7742705 commit ee20cde
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
10 changes: 10 additions & 0 deletions dev.deedles.Trayscale.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
<content_rating type="oars-1.1" />

<releases>
<release version="v0.12.3" date="2024-05-04">
<description>
<ul>Fix self and Mullvad pages disappearing when re-opening the window.</ul>
</description>
</release>
<release version="v0.12.2" date="2024-05-03">
<description>
<ul>Nicer sorting and display of Mullvad nodes.</ul>
</description>
</release>
<release version="v0.12.1" date="2024-05-02">
<description>
<ul>Strip debugging symbols to reduce binary size.</ul>
Expand Down
11 changes: 5 additions & 6 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
}

Expand Down Expand Up @@ -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
})
Expand Down
5 changes: 3 additions & 2 deletions internal/ui/mullvadpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
25 changes: 9 additions & 16 deletions internal/ui/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions internal/ui/peerpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions internal/ui/selfpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
Expand Down

0 comments on commit ee20cde

Please sign in to comment.